Advertisement
Guest User

Untitled

a guest
Mar 12th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.87 KB | None | 0 0
  1. package main
  2.  
  3. var palette = []color.Color{color.Black, color.RGBA{0, 255, 0, 255}}
  4.  
  5. const (
  6.     whiteIndex = iota
  7.     blackIndex
  8. )
  9.  
  10. func lissajous(out io.Writer) {
  11.     const (
  12.         cycles  = 5
  13.         res     = 0.001
  14.         size    = 100
  15.         nframes = 64
  16.         delay   = 8
  17.     )
  18.  
  19.     rand.Seed(time.Now().UTC().UnixNano())
  20.     freq := rand.Float64() * 3.0
  21.     anim := gif.GIF{LoopCount: nframes}
  22.  
  23.     phase := 0.0
  24.     for i := 0; i < nframes; i++ {
  25.         rect := image.Rect(0, 0, 2*size+1, 2*size+1)
  26.         img := image.NewPaletted(rect, palette)
  27.         for t := 0.0; t < cycles*2*math.Pi; t += res {
  28.             x := math.Sin(t)
  29.             y := math.Sin(t*freq + phase)
  30.  
  31.             img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5),
  32.                 blackIndex)
  33.         }
  34.         phase += 0.1
  35.         anim.Delay = append(anim.Delay, delay)
  36.         anim.Image = append(anim.Image, img)
  37.     }
  38.  
  39.     gif.EncodeAll(out, &anim)
  40. }
  41.  
  42. func main_1() {
  43.     lissajous(os.Stdout)
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement