update example

This commit is contained in:
Michael Fogleman 2016-02-21 17:29:11 -05:00
parent 9c129741d4
commit 509f79dbd2

View File

@ -14,12 +14,31 @@ func point() (x, y float64) {
return random(), random() return random(), random()
} }
func drawCurve(dc *gg.Context) {
dc.SetRGBA(0, 0, 0, 0.1)
dc.FillPreserve()
dc.SetRGB(0, 0, 0)
dc.SetLineWidth(12)
dc.Stroke()
}
func drawPoints(dc *gg.Context) {
dc.SetRGBA(1, 0, 0, 0.5)
dc.SetLineWidth(2)
dc.Stroke()
}
func randomQuadratic(dc *gg.Context) { func randomQuadratic(dc *gg.Context) {
x0, y0 := point() x0, y0 := point()
x1, y1 := point() x1, y1 := point()
x2, y2 := point() x2, y2 := point()
dc.MoveTo(x0, y0) dc.MoveTo(x0, y0)
dc.QuadraticTo(x1, y1, x2, y2) dc.QuadraticTo(x1, y1, x2, y2)
drawCurve(dc)
dc.MoveTo(x0, y0)
dc.LineTo(x1, y1)
dc.LineTo(x2, y2)
drawPoints(dc)
} }
func randomCubic(dc *gg.Context) { func randomCubic(dc *gg.Context) {
@ -29,6 +48,12 @@ func randomCubic(dc *gg.Context) {
x3, y3 := point() x3, y3 := point()
dc.MoveTo(x0, y0) dc.MoveTo(x0, y0)
dc.CubicTo(x1, y1, x2, y2, x3, y3) dc.CubicTo(x1, y1, x2, y2, x3, y3)
drawCurve(dc)
dc.MoveTo(x0, y0)
dc.LineTo(x1, y1)
dc.LineTo(x2, y2)
dc.LineTo(x3, y3)
drawPoints(dc)
} }
func main() { func main() {
@ -47,15 +72,13 @@ func main() {
dc.Push() dc.Push()
dc.Translate(x, y) dc.Translate(x, y)
dc.Scale(S/2, S/2) dc.Scale(S/2, S/2)
randomCubic(dc) if j%2 == 0 {
// randomQuadratic(dc) randomCubic(dc)
} else {
randomQuadratic(dc)
}
dc.Pop() dc.Pop()
} }
} }
dc.SetRGBA(0, 0, 0, 0.1)
dc.FillPreserve()
dc.SetRGB(0, 0, 0)
dc.SetLineWidth(16)
dc.StrokePreserve()
dc.SavePNG("out.png") dc.SavePNG("out.png")
} }