Created
July 14, 2016 21:22
-
-
Save jamesfe/d43c479a7af8b5127eb7d752c946db5d to your computer and use it in GitHub Desktop.
Draw a random path on a canvas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "math/rand" | |
| "os" | |
| "time" | |
| "github.com/ajstarks/svgo" | |
| ) | |
| func init() { | |
| currentTime := time.Now() | |
| rand.Seed(int64(currentTime.Second())) | |
| } | |
| func main() { | |
| width := 500 | |
| height := 500 | |
| outfile, err := os.Create("outfile.svg") | |
| if err != nil { | |
| panic(err) | |
| } | |
| canvas := svg.New(outfile) | |
| canvas.Start(width, height) | |
| size := 4 | |
| xCoord, yCoord := width/2, height/2 | |
| for i := 0; i < 2000; i++ { | |
| xDelta := (rand.Intn(3) - 1) * size | |
| yDelta := (rand.Intn(3) - 1) * size | |
| xCoord += xDelta | |
| yCoord += yDelta | |
| canvas.Rect(xCoord, yCoord, size, size) | |
| } | |
| canvas.End() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment