From 215984bf961298716f78c5c557e3d0eaff5476eb Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sat, 20 Feb 2016 15:42:59 -0500 Subject: [PATCH] sine --- examples/sine.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/sine.go diff --git a/examples/sine.go b/examples/sine.go new file mode 100644 index 0000000..679da06 --- /dev/null +++ b/examples/sine.go @@ -0,0 +1,29 @@ +package main + +import ( + "math" + + "github.com/fogleman/gg" +) + +func main() { + const W = 1200 + const H = 60 + dc := gg.NewContext(W, H) + // dc.SetHexColor("#FFFFFF") + // dc.Clear() + dc.ScaleAbout(0.95, 0.75, W/2, H/2) + for i := 0; i < W; i++ { + a := float64(i) * 2 * math.Pi / W * 8 + x := float64(i) + y := (math.Sin(a) + 1) / 2 * H + dc.LineTo(x, y) + } + dc.ClosePath() + dc.SetHexColor("#3E606F") + dc.FillPreserve() + dc.SetHexColor("#19344180") + dc.SetLineWidth(8) + dc.Stroke() + dc.SavePNG("out.png") +}