From da3d0863b9e39fb1e8c612dfcf072537fa85032e Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Fri, 23 Feb 2018 09:52:38 -0500 Subject: [PATCH] add crisp lines example --- examples/crisp.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/crisp.go diff --git a/examples/crisp.go b/examples/crisp.go new file mode 100644 index 0000000..2ac058e --- /dev/null +++ b/examples/crisp.go @@ -0,0 +1,44 @@ +package main + +import ( + "github.com/fogleman/gg" +) + +func main() { + const W = 1000 + const H = 1000 + const Minor = 10 + const Major = 100 + + dc := gg.NewContext(W, H) + dc.SetRGB(1, 1, 1) + dc.Clear() + + // minor grid + for x := Minor; x < W; x += Minor { + fx := float64(x) + 0.5 + dc.DrawLine(fx, 0, fx, H) + } + for y := Minor; y < H; y += Minor { + fy := float64(y) + 0.5 + dc.DrawLine(0, fy, W, fy) + } + dc.SetLineWidth(1) + dc.SetRGBA(0, 0, 0, 0.25) + dc.Stroke() + + // major grid + for x := Major; x < W; x += Major { + fx := float64(x) + 0.5 + dc.DrawLine(fx, 0, fx, H) + } + for y := Major; y < H; y += Major { + fy := float64(y) + 0.5 + dc.DrawLine(0, fy, W, fy) + } + dc.SetLineWidth(1) + dc.SetRGBA(0, 0, 0, 0.5) + dc.Stroke() + + dc.SavePNG("out.png") +}