// ArcNegative draws an arc with a negative angle (anti clockwise). func ArcNegative(gc draw2d.GraphicContext, xc, yc, width, height float64) { xc += width / 2 yc += height / 2 radiusX, radiusY := width/2, height/2 startAngle := 45.0 * (math.Pi / 180.0) /* angles are specified */ angle := -225 * (math.Pi / 180.0) /* clockwise in radians */ gc.SetLineWidth(width / 10) gc.SetLineCap(draw2d.ButtCap) gc.SetStrokeColor(image.Black) gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle) gc.Stroke() // fill a circle gc.SetStrokeColor(color.NRGBA{255, 0x33, 0x33, 0x80}) gc.SetFillColor(color.NRGBA{255, 0x33, 0x33, 0x80}) gc.SetLineWidth(width / 20) gc.MoveTo(xc+math.Cos(startAngle)*radiusX, yc+math.Sin(startAngle)*radiusY) gc.LineTo(xc, yc) gc.LineTo(xc-radiusX, yc) gc.Stroke() gc.ArcTo(xc, yc, width/10.0, height/10.0, 0, 2*math.Pi) gc.Fill() }
// PathTransform scales a path differently in horizontal and vertical direction. func PathTransform(gc draw2d.GraphicContext, x, y, width, height float64) { gc.Save() gc.SetLineWidth(width / 10) gc.Translate(x+width/2, y+height/2) gc.Scale(1, 4) gc.ArcTo(0, 0, width/8, height/8, 0, math.Pi*2) gc.Close() gc.Stroke() gc.Restore() }
// Draw the droid on a certain position. func Draw(gc draw2d.GraphicContext, x, y float64) { // 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}) // set line properties gc.SetLineCap(draw2d.RoundCap) gc.SetLineWidth(5) // head 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() // left eye draw2dkit.Circle(gc, x+60, y+45, 5) gc.FillStroke() // right eye draw2dkit.Circle(gc, x+100, y+45, 5) gc.FillStroke() // body draw2dkit.RoundedRectangle(gc, x+30, y+75, x+30+100, y+75+90, 10, 10) gc.FillStroke() draw2dkit.Rectangle(gc, x+30, y+75, x+30+100, y+75+80) gc.FillStroke() // left arm draw2dkit.RoundedRectangle(gc, x+5, y+80, x+5+20, y+80+70, 10, 10) gc.FillStroke() // right arm draw2dkit.RoundedRectangle(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) gc.FillStroke() // left leg draw2dkit.RoundedRectangle(gc, x+50, y+150, x+50+20, y+150+50, 10, 10) gc.FillStroke() // right leg draw2dkit.RoundedRectangle(gc, x+90, y+150, x+90+20, y+150+50, 10, 10) gc.FillStroke() }
// Arc draws a link between two points func Arc(gc draw2d.GraphicContext, x, y1, y2 float64) { // Center yc := (y1 + y2) / 2 // x radius xRadius := y2 - y1 // y radius yRadius := y2 - yc // Start at -45 degrees startAngle := -math.Pi / 2 // 180 degrees = half a circle angle := math.Pi gc.ArcTo(x, yc, xRadius, yRadius, startAngle, angle) gc.Stroke() gc.Fill() }