2015-06-26 23:13:20 +00:00
|
|
|
// Copyright 2010 The draw2d Authors. All rights reserved.
|
2015-06-27 15:19:08 +00:00
|
|
|
// created: 21/11/2010 by Laurent Le Goff, Stani Michiels
|
2015-06-26 23:13:20 +00:00
|
|
|
|
|
|
|
// Draw an android avatar to android.png
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/stanim/draw2d"
|
|
|
|
"github.com/stanim/draw2d/pdf2d"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Initialize the graphic context on a pdf document
|
2015-06-27 16:24:16 +00:00
|
|
|
dest := pdf2d.NewPdf("P", "mm", "A4")
|
|
|
|
gc := pdf2d.NewGraphicContext(dest)
|
2015-06-26 23:13:20 +00:00
|
|
|
|
|
|
|
// set the fill and stroke color of the droid
|
|
|
|
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
|
|
|
|
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
|
|
|
|
|
|
|
|
// Draw the droid
|
|
|
|
DrawDroid(gc, 10, 10)
|
|
|
|
|
2015-06-27 14:34:30 +00:00
|
|
|
// Save to pdf
|
2015-06-27 16:24:16 +00:00
|
|
|
pdf2d.SaveToPdfFile("android.pdf", dest)
|
2015-06-26 23:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func DrawDroid(gc draw2d.GraphicContext, x, y float64) {
|
|
|
|
gc.SetLineCap(draw2d.RoundCap)
|
|
|
|
gc.SetLineWidth(5)
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// head
|
2015-06-26 23:13:20 +00:00
|
|
|
gc.MoveTo(x+30, y+70)
|
|
|
|
gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 180*(math.Pi/180))
|
|
|
|
gc.Close()
|
|
|
|
gc.FillStroke()
|
|
|
|
gc.MoveTo(x+60, y+25)
|
|
|
|
gc.LineTo(x+50, y+10)
|
|
|
|
gc.MoveTo(x+100, y+25)
|
|
|
|
gc.LineTo(x+110, y+10)
|
|
|
|
gc.Stroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// left eye
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.Circle(gc, x+60, y+45, 5)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// right eye
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.Circle(gc, x+100, y+45, 5)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// body
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.RoundRect(gc, x+30, y+75, x+30+100, y+75+90, 10, 10)
|
|
|
|
gc.FillStroke()
|
|
|
|
draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// left arm
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.RoundRect(gc, x+5, y+80, x+5+20, y+80+70, 10, 10)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// right arm
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// left leg
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.RoundRect(gc, x+50, y+150, x+50+20, y+150+50, 10, 10)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
2015-06-27 16:24:16 +00:00
|
|
|
// right leg
|
2015-06-26 23:13:20 +00:00
|
|
|
draw2d.RoundRect(gc, x+90, y+150, x+90+20, y+150+50, 10, 10)
|
|
|
|
gc.FillStroke()
|
|
|
|
}
|