Skip to content

Instantly share code, notes, and snippets.

@jamesfe
Created July 14, 2016 21:22
Show Gist options
  • Select an option

  • Save jamesfe/d43c479a7af8b5127eb7d752c946db5d to your computer and use it in GitHub Desktop.

Select an option

Save jamesfe/d43c479a7af8b5127eb7d752c946db5d to your computer and use it in GitHub Desktop.
Draw a random path on a canvas.
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