From 401ff36d5a8227a0fed47adb4f1ca4cca31c30f9 Mon Sep 17 00:00:00 2001 From: Stani Date: Fri, 10 Jul 2015 02:13:43 +0200 Subject: [PATCH] add sample: gopher --- samples/gopher/gopher.go | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 samples/gopher/gopher.go diff --git a/samples/gopher/gopher.go b/samples/gopher/gopher.go new file mode 100644 index 0000000..dbd488d --- /dev/null +++ b/samples/gopher/gopher.go @@ -0,0 +1,63 @@ +// Copyright 2010 The draw2d Authors. All rights reserved. +// created: 21/11/2010 by Laurent Le Goff + +// Package gopher draws a gopher avatar based on a svg of: +// https://github.com/golang-samples/gopher-vector/ +package gopher + +import ( + "image/color" + + "github.com/llgcode/draw2d" + "github.com/llgcode/draw2d/samples" +) + +// Main draws a left hand and ear of a gopher. Afterwards it returns +// the filename. This should only be during testing. +func Main(gc draw2d.GraphicContext, ext string) (string, error) { + gc.Save() + gc.Scale(0.5, 0.5) + // Draw a (partial) gopher + Draw(gc) + gc.Restore() + + // Return the output filename + return samples.Output("gopher", ext), nil +} + +// Draw a left hand and ear of a gopher using a gc thanks to +// https://github.com/golang-samples/gopher-vector/ +func Draw(gc draw2d.GraphicContext) { + // Initialize Stroke Attribute + gc.SetLineWidth(3) + gc.SetLineCap(draw2d.RoundCap) + gc.SetStrokeColor(color.Black) + + // Left hand + // + gc.SetFillColor(color.RGBA{0xF6, 0xD2, 0xA2, 0xff}) + gc.MoveTo(10.634, 300.493) + gc.RCubicCurveTo(0.764, 15.751, 16.499, 8.463, 23.626, 3.539) + gc.RCubicCurveTo(6.765, -4.675, 8.743, -0.789, 9.337, -10.015) + gc.RCubicCurveTo(0.389, -6.064, 1.088, -12.128, 0.744, -18.216) + gc.RCubicCurveTo(-10.23, -0.927, -21.357, 1.509, -29.744, 7.602) + gc.CubicCurveTo(10.277, 286.542, 2.177, 296.561, 10.634, 300.493) + gc.FillStroke() + + // + gc.MoveTo(10.634, 300.493) + gc.RCubicCurveTo(2.29, -0.852, 4.717, -1.457, 6.271, -3.528) + gc.Stroke() + + // Left Ear + // + gc.MoveTo(46.997, 112.853) + gc.CubicCurveTo(-13.3, 95.897, 31.536, 19.189, 79.956, 50.74) + gc.LineTo(46.997, 112.853) + gc.Close() + gc.Stroke() +}