summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/main.go b/main.go
index 45362f8..7e652eb 100644
--- a/main.go
+++ b/main.go
@@ -1,9 +1,11 @@
package main
import (
- "fmt"
+ "image"
"image/color"
+ "image/gif"
"io"
+ "math"
"math/rand/v2"
"os"
)
@@ -13,6 +15,11 @@ var palette = []color.Color{
color.Black,
}
+const (
+ whiteIndex = iota
+ blackIndex
+)
+
func main() {
lissajous(os.Stdout)
}
@@ -29,8 +36,23 @@ func lissajous(out io.Writer) {
// Note that this generates the exact same random number per
// run of the program.
freq := rand.Float64() * 3.0
+ anim := gif.GIF{LoopCount: nframes}
+ phase := 0.0
+
+ for range nframes {
+ rect := image.Rect(0, 0, 2*size+1, 2*size+1)
+ img := image.NewPaletted(rect, palette)
- for range 10 {
- fmt.Printf("random number: %.2f\n", freq)
+ for t := 0.0; t < cycles*2*math.Pi; t += res {
+ x := math.Sin(t)
+ y := math.Sin(t*freq + phase)
+ img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blackIndex)
+ }
+
+ phase += 0.1
+ anim.Delay = append(anim.Delay, delay)
+ anim.Image = append(anim.Image, img)
}
+
+ gif.EncodeAll(out, &anim)
}