From 509f79dbd2718cbb55d68d33dc18c2e63eb6eb25 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sun, 21 Feb 2016 17:29:11 -0500 Subject: [PATCH] update example --- examples/beziers.go | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/examples/beziers.go b/examples/beziers.go index 93b68b2..e4cfa8d 100644 --- a/examples/beziers.go +++ b/examples/beziers.go @@ -14,12 +14,31 @@ func point() (x, y float64) { 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) { x0, y0 := point() x1, y1 := point() x2, y2 := point() dc.MoveTo(x0, y0) 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) { @@ -29,6 +48,12 @@ func randomCubic(dc *gg.Context) { x3, y3 := point() dc.MoveTo(x0, y0) 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() { @@ -47,15 +72,13 @@ func main() { dc.Push() dc.Translate(x, y) dc.Scale(S/2, S/2) - randomCubic(dc) - // randomQuadratic(dc) + if j%2 == 0 { + randomCubic(dc) + } else { + randomQuadratic(dc) + } 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") }