cmd/smiley/main.go

package main

import (
	"flag"
	"fmt"
	"net"
	"strconv"
	"time"
)

func main() {
	resolution := flag.Int("res", 200, "Port step size (lower = higher resolution)")
	duration := flag.Duration("dur", 10*time.Second, "Total run time")
	ip := flag.String("ip", "127.0.0.1", "Address to send packets to")
	flag.Parse()

	start := time.Now()

	for time.Since(start) < *duration {
		elapsed := time.Since(start).Seconds()

		for port := 1; port <= 65535; port += *resolution {
			if isSmiley(port, elapsed) {
				addr := net.JoinHostPort(*ip, strconv.Itoa(port))

				conn, err := net.Dial("udp", addr)
				if err == nil {
					// Send minimal payload
					conn.Write([]byte{0x00})
					conn.Close()
				}
				fmt.Println("Sent Packet to port", port, addr)
			}
		}

		// Controls horizontal spacing (time axis density)
		time.Sleep(100 * time.Millisecond)
	}
}

// Determines whether a packet should be sent at (time, port)
func isSmiley(port int, t float64) bool {
	thickness := 400    // line thickness for drawing
	timeScale := 2500.0 // scale time axis to match port axis for circles

	// Both eyes at same vertical height (port), separated horizontally (time)
	eyePort := 50000
	eyeRadius := 2000.0

	// Left eye (at time = 3)
	leftEyeTime := 3.0
	dt := (t - leftEyeTime) * timeScale
	dp := float64(port - eyePort)
	if dt*dt+dp*dp < eyeRadius*eyeRadius {
		return true
	}

	// Right eye (at time = 7)
	rightEyeTime := 7.0
	dt = (t - rightEyeTime) * timeScale
	dp = float64(port - eyePort)
	if dt*dt+dp*dp < eyeRadius*eyeRadius {
		return true
	}

	// Mouth (curved smile line below eyes)
	mouthTimeStart := 2.5
	mouthTimeEnd := 7.5

	if t >= mouthTimeStart && t <= mouthTimeEnd {
		mouthCenterTime := 5.0    // center of face
		mouthLowestPort := 30000  // bottom of smile curve (at center)
		mouthHighestPort := 38000 // top of smile curve (at edges)

		// Smile shape: U curve (low in middle, high at edges)
		halfWidth := (mouthTimeEnd - mouthTimeStart) / 2 // 2.5
		dt := t - mouthCenterTime
		a := float64(mouthHighestPort-mouthLowestPort) / (halfWidth * halfWidth)
		curvePort := int(a*dt*dt) + mouthLowestPort

		// Only draw if port is ON the curve line (not inside)
		if port > curvePort-thickness && port < curvePort+thickness {
			return true
		}
	}

	return false
}