Vibrating rectangles: Difference between revisions

→‎{{header|Go}}: Added code to create GIF file directly from the program.
(Added Go)
(→‎{{header|Go}}: Added code to create GIF file directly from the program.)
Line 45:
 
=={{header|Go}}==
This uses Go's 'image' packages in its standard library to create an animated GIF. The file itself can be created from the terminal as follows:
 
<pre>
$ go build vibrating.go
$ ./vibrating > vibrating.gif
</pre>
When played this is somewhat similar to the Python entry except that it uses a 7 (rather than 6) color palette and repeats indefinitely.
 
Line 63 ⟶ 60:
"image/color"
"image/gif"
"log"
"os"
)
Line 131 ⟶ 129:
}
}
file, err := os.Create("vibrating.gif")
gif.EncodeAll(os.Stdout, &anim)
if err != nil {
log.Fatal(err)
}
defer file.Close()
if err2 := gif.EncodeAll(os.Stdoutfile, &anim); err != nil {
log.Fatal(err2)
}
}</lang>
 
9,476

edits