diff options
| author | Brandon C. Irizarry <brandon.irizarry@gmail.com> | 2026-03-05 21:05:21 -0500 |
|---|---|---|
| committer | Brandon C. Irizarry <brandon.irizarry@gmail.com> | 2026-03-05 21:05:21 -0500 |
| commit | a613d1ba9f2897cf98de424d27d1a1355558b337 (patch) | |
| tree | 5fb0f94935ac9c285efe89159a2b255be2d5a300 | |
| parent | 93b1f39d8e33893f1519caec2809ad368fa31978 (diff) | |
feat: create a gif
| -rw-r--r-- | main.go | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -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) } |
