Esempio n. 1
0
// 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
	// <path fill-rule="evenodd" clip-rule="evenodd" fill="#F6D2A2" stroke="#000000" stroke-width="3" stroke-linecap="round" d="
	// M10.634,300.493c0.764,15.751,16.499,8.463,23.626,3.539c6.765-4.675,8.743-0.789,9.337-10.015
	// c0.389-6.064,1.088-12.128,0.744-18.216c-10.23-0.927-21.357,1.509-29.744,7.602C10.277,286.542,2.177,296.561,10.634,300.493"/>
	gc.SetFillColor(color.RGBA{0xF6, 0xD2, 0xA2, 0xff})
	gc.MoveTo(10.634, 300.493)
	rCubicCurveTo(gc, 0.764, 15.751, 16.499, 8.463, 23.626, 3.539)
	rCubicCurveTo(gc, 6.765, -4.675, 8.743, -0.789, 9.337, -10.015)
	rCubicCurveTo(gc, 0.389, -6.064, 1.088, -12.128, 0.744, -18.216)
	rCubicCurveTo(gc, -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()

	// <path fill-rule="evenodd" clip-rule="evenodd" fill="#C6B198" stroke="#000000" stroke-width="3" stroke-linecap="round" d="
	// M10.634,300.493c2.29-0.852,4.717-1.457,6.271-3.528"/>
	gc.MoveTo(10.634, 300.493)
	rCubicCurveTo(gc, 2.29, -0.852, 4.717, -1.457, 6.271, -3.528)
	gc.Stroke()

	// Left Ear
	// <path fill-rule="evenodd" clip-rule="evenodd" fill="#6AD7E5" stroke="#000000" stroke-width="3" stroke-linecap="round" d="
	// M46.997,112.853C-13.3,95.897,31.536,19.189,79.956,50.74L46.997,112.853z"/>
	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()
}
Esempio n. 2
0
// Dash draws a line with a dash pattern
func Dash(gc draw2d.GraphicContext, x, y, width, height float64) {
	sx, sy := width/162, height/205
	gc.SetStrokeColor(image.Black)
	gc.SetLineDash([]float64{height / 10, height / 50, height / 50, height / 50}, -50.0)
	gc.SetLineCap(draw2d.ButtCap)
	gc.SetLineJoin(draw2d.RoundJoin)
	gc.SetLineWidth(height / 50)

	gc.MoveTo(x+sx*60.0, y)
	gc.LineTo(x+sx*60.0, y)
	gc.LineTo(x+sx*162, y+sy*205)
	rLineTo(gc, sx*-102.4, 0)
	gc.CubicCurveTo(x+sx*-17, y+sy*205, x+sx*-17, y+sy*103, x+sx*60.0, y+sy*103.0)
	gc.Stroke()
	gc.SetLineDash(nil, 0.0)
}
Esempio n. 3
0
// FillStroke first fills and afterwards strokes a path.
func FillStroke(gc draw2d.GraphicContext, x, y, width, height float64) {
	sx, sy := width/210, height/215
	gc.MoveTo(x+sx*113.0, y)
	gc.LineTo(x+sx*215.0, y+sy*215)
	rLineTo(gc, sx*-100, 0)
	gc.CubicCurveTo(x+sx*35, y+sy*215, x+sx*35, y+sy*113, x+sx*113.0, y+sy*113)
	gc.Close()

	gc.MoveTo(x+sx*50.0, y)
	rLineTo(gc, sx*51.2, sy*51.2)
	rLineTo(gc, sx*-51.2, sy*51.2)
	rLineTo(gc, sx*-51.2, sy*-51.2)
	gc.Close()

	gc.SetLineWidth(width / 20.0)
	gc.SetFillColor(color.NRGBA{0, 0, 0xFF, 0xFF})
	gc.SetStrokeColor(image.Black)
	gc.FillStroke()
}
Esempio n. 4
0
// CubicCurve draws a cubic curve with its control points.
func CubicCurve(gc draw2d.GraphicContext, x, y, width, height float64) {
	sx, sy := width/162, height/205
	x0, y0 := x, y+sy*100.0
	x1, y1 := x+sx*75, y+sy*205
	x2, y2 := x+sx*125, y
	x3, y3 := x+sx*205, y+sy*100

	gc.SetStrokeColor(image.Black)
	gc.SetFillColor(color.NRGBA{0xAA, 0xAA, 0xAA, 0xFF})
	gc.SetLineWidth(width / 10)
	gc.MoveTo(x0, y0)
	gc.CubicCurveTo(x1, y1, x2, y2, x3, y3)
	gc.Stroke()

	gc.SetStrokeColor(color.NRGBA{0xFF, 0x33, 0x33, 0x88})

	gc.SetLineWidth(width / 20)
	// draw segment of curve
	gc.MoveTo(x0, y0)
	gc.LineTo(x1, y1)
	gc.LineTo(x2, y2)
	gc.LineTo(x3, y3)
	gc.Stroke()
}
Esempio n. 5
0
// Draw a gopher head (not rotated)
func Draw(gc draw2d.GraphicContext, x, y, w, h float64) {
	h23 := (h * 2) / 3

	blf := color.RGBA{0, 0, 0, 0xff}          // black
	wf := color.RGBA{0xff, 0xff, 0xff, 0xff}  // white
	nf := color.RGBA{0x8B, 0x45, 0x13, 0xff}  // brown opaque
	brf := color.RGBA{0x8B, 0x45, 0x13, 0x99} // brown transparant
	brb := color.RGBA{0x8B, 0x45, 0x13, 0xBB} // brown transparant

	// round head top
	gc.MoveTo(x, y+h*1.002)
	gc.CubicCurveTo(x+w/4, y-h/3, x+3*w/4, y-h/3, x+w, y+h*1.002)
	gc.Close()
	gc.SetFillColor(brb)
	gc.Fill()

	// rectangle head bottom
	draw2dkit.RoundedRectangle(gc, x, y+h, x+w, y+h+h, h/5, h/5)
	gc.Fill()

	// left ear outside
	draw2dkit.Circle(gc, x, y+h, w/12)
	gc.SetFillColor(brf)
	gc.Fill()

	// left ear inside
	draw2dkit.Circle(gc, x, y+h, 0.5*w/12)
	gc.SetFillColor(nf)
	gc.Fill()

	// right ear outside
	draw2dkit.Circle(gc, x+w, y+h, w/12)
	gc.SetFillColor(brf)
	gc.Fill()

	// right ear inside
	draw2dkit.Circle(gc, x+w, y+h, 0.5*w/12)
	gc.SetFillColor(nf)
	gc.Fill()

	// left eye outside white
	draw2dkit.Circle(gc, x+w/3, y+h23, w/9)
	gc.SetFillColor(wf)
	gc.Fill()

	// left eye black
	draw2dkit.Circle(gc, x+w/3+w/24, y+h23, 0.5*w/9)
	gc.SetFillColor(blf)
	gc.Fill()

	// left eye inside white
	draw2dkit.Circle(gc, x+w/3+w/24+w/48, y+h23, 0.2*w/9)
	gc.SetFillColor(wf)
	gc.Fill()

	// right eye outside white
	draw2dkit.Circle(gc, x+w-w/3, y+h23, w/9)
	gc.Fill()

	// right eye black
	draw2dkit.Circle(gc, x+w-w/3+w/24, y+h23, 0.5*w/9)
	gc.SetFillColor(blf)
	gc.Fill()

	// right eye inside white
	draw2dkit.Circle(gc, x+w-(w/3)+w/24+w/48, y+h23, 0.2*w/9)
	gc.SetFillColor(wf)
	gc.Fill()

	// left tooth
	gc.SetFillColor(wf)
	draw2dkit.RoundedRectangle(gc, x+w/2-w/8, y+h+h/2.5, x+w/2-w/8+w/8, y+h+h/2.5+w/6, w/10, w/10)
	gc.Fill()

	// right tooth
	draw2dkit.RoundedRectangle(gc, x+w/2, y+h+h/2.5, x+w/2+w/8, y+h+h/2.5+w/6, w/10, w/10)
	gc.Fill()

	// snout
	draw2dkit.Ellipse(gc, x+(w/2), y+h+h/2.5, w/6, w/12)
	gc.SetFillColor(nf)
	gc.Fill()

	// nose
	draw2dkit.Ellipse(gc, x+(w/2), y+h+h/7, w/10, w/12)
	gc.SetFillColor(blf)
	gc.Fill()
}
Esempio n. 6
0
// CurveRectangle draws a rectangle with bezier curves (not rounded rectangle).
func CurveRectangle(gc draw2d.GraphicContext, x0, y0,
	rectWidth, rectHeight float64, stroke, fill color.Color) {
	radius := (rectWidth + rectHeight) / 4

	x1 := x0 + rectWidth
	y1 := y0 + rectHeight
	if rectWidth/2 < radius {
		if rectHeight/2 < radius {
			gc.MoveTo(x0, (y0+y1)/2)
			gc.CubicCurveTo(x0, y0, x0, y0, (x0+x1)/2, y0)
			gc.CubicCurveTo(x1, y0, x1, y0, x1, (y0+y1)/2)
			gc.CubicCurveTo(x1, y1, x1, y1, (x1+x0)/2, y1)
			gc.CubicCurveTo(x0, y1, x0, y1, x0, (y0+y1)/2)
		} else {
			gc.MoveTo(x0, y0+radius)
			gc.CubicCurveTo(x0, y0, x0, y0, (x0+x1)/2, y0)
			gc.CubicCurveTo(x1, y0, x1, y0, x1, y0+radius)
			gc.LineTo(x1, y1-radius)
			gc.CubicCurveTo(x1, y1, x1, y1, (x1+x0)/2, y1)
			gc.CubicCurveTo(x0, y1, x0, y1, x0, y1-radius)
		}
	} else {
		if rectHeight/2 < radius {
			gc.MoveTo(x0, (y0+y1)/2)
			gc.CubicCurveTo(x0, y0, x0, y0, x0+radius, y0)
			gc.LineTo(x1-radius, y0)
			gc.CubicCurveTo(x1, y0, x1, y0, x1, (y0+y1)/2)
			gc.CubicCurveTo(x1, y1, x1, y1, x1-radius, y1)
			gc.LineTo(x0+radius, y1)
			gc.CubicCurveTo(x0, y1, x0, y1, x0, (y0+y1)/2)
		} else {
			gc.MoveTo(x0, y0+radius)
			gc.CubicCurveTo(x0, y0, x0, y0, x0+radius, y0)
			gc.LineTo(x1-radius, y0)
			gc.CubicCurveTo(x1, y0, x1, y0, x1, y0+radius)
			gc.LineTo(x1, y1-radius)
			gc.CubicCurveTo(x1, y1, x1, y1, x1-radius, y1)
			gc.LineTo(x0+radius, y1)
			gc.CubicCurveTo(x0, y1, x0, y1, x0, y1-radius)
		}
	}
	gc.Close()
	gc.SetStrokeColor(stroke)
	gc.SetFillColor(fill)
	gc.SetLineWidth(10.0)
	gc.FillStroke()
}