gg/examples/lines.go

32 lines
552 B
Go
Raw Permalink Normal View History

2016-02-19 04:21:29 +01:00
package main
import (
"math/rand"
2016-02-19 15:43:37 +01:00
"github.com/fogleman/gg"
2016-02-19 04:21:29 +01:00
)
func main() {
const W = 1024
const H = 1024
2016-02-19 15:43:37 +01:00
dc := gg.NewContext(W, H)
2016-02-19 17:07:25 +01:00
dc.SetRGB(0, 0, 0)
dc.Clear()
2016-02-19 04:21:29 +01:00
for i := 0; i < 1000; i++ {
x1 := rand.Float64() * W
y1 := rand.Float64() * H
x2 := rand.Float64() * W
y2 := rand.Float64() * H
r := rand.Float64()
g := rand.Float64()
b := rand.Float64()
a := rand.Float64()*0.5 + 0.5
w := rand.Float64()*4 + 1
2016-02-19 17:07:25 +01:00
dc.SetRGBA(r, g, b, a)
2016-02-19 04:21:29 +01:00
dc.SetLineWidth(w)
dc.DrawLine(x1, y1, x2, y2)
2016-02-19 17:07:25 +01:00
dc.Stroke()
2016-02-19 04:21:29 +01:00
}
2016-02-19 19:54:55 +01:00
dc.SavePNG("out.png")
2016-02-19 04:21:29 +01:00
}