69 lines
1.2 KiB
Go
69 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"git.jcg.re/jcgruenhage/pixclient"
|
|
"math/rand"
|
|
"net"
|
|
)
|
|
|
|
func main() {
|
|
x, y := 1920, 1200
|
|
client := pixclient.Init(net.IPv4(94, 45, 231, 39), 1234)
|
|
currentX := rand.Intn(x)
|
|
currentY := rand.Intn(y)
|
|
r, g, b := byte(255), byte(0), byte(0)
|
|
counter := 0
|
|
for true {
|
|
direction := rand.Intn(4)
|
|
for ((currentX == x-1) && (direction == 1)) || ((currentX == 0) && (direction == 3)) || ((currentY == y-1) && (direction == 2)) || ((currentY == 0) && (direction == 0)) {
|
|
direction = rand.Intn(4)
|
|
}
|
|
if direction == 0 {
|
|
currentY--
|
|
} else if direction == 1 {
|
|
currentX++
|
|
} else if direction == 2 {
|
|
currentY++
|
|
} else if direction == 3 {
|
|
currentX--
|
|
} else {
|
|
panic("Illegal Direction!")
|
|
}
|
|
if counter%50 == 0 {
|
|
iterateColor(&r, &g, &b)
|
|
}
|
|
client.WritePixel(currentX, currentY, r, g, b, 255)
|
|
counter++
|
|
}
|
|
}
|
|
func iterateColor(r, g, b *byte) {
|
|
if *r == 255 {
|
|
if *b != 0 {
|
|
*b--
|
|
} else if *g != 255 {
|
|
*g++
|
|
} else {
|
|
*r--
|
|
}
|
|
} else if *g == 255 {
|
|
if *r != 0 {
|
|
*r--
|
|
} else if *b != 255 {
|
|
*b++
|
|
} else {
|
|
*g--
|
|
}
|
|
} else if *b == 255 {
|
|
if *g != 0 {
|
|
*g--
|
|
} else if *r != 255 {
|
|
*r++
|
|
} else {
|
|
*b--
|
|
|
|
}
|
|
} else {
|
|
panic("Illegal state")
|
|
}
|
|
}
|