Example #1
0
func android(gc draw2d.GraphicContext, x, y float64) {
	gc.SetLineCap(draw2d.RoundCap)
	gc.SetLineWidth(5)
	gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 360*(math.Pi/180)) // head
	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()
	draw2d.Circle(gc, x+60, y+45, 5) // left eye
	gc.FillStroke()
	draw2d.Circle(gc, x+100, y+45, 5) // right eye
	gc.FillStroke()
	draw2d.RoundRect(gc, x+30, y+75, x+30+100, y+75+90, 10, 10) // body
	gc.FillStroke()
	draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80)
	gc.FillStroke()
	draw2d.RoundRect(gc, x+5, y+80, x+5+20, y+80+70, 10, 10) // left arm
	gc.FillStroke()
	draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) // right arm
	gc.FillStroke()
	draw2d.RoundRect(gc, x+50, y+150, x+50+20, y+150+50, 10, 10) // left leg
	gc.FillStroke()
	draw2d.RoundRect(gc, x+90, y+150, x+90+20, y+150+50, 10, 10) // right leg
	gc.FillStroke()
}
Example #2
0
func TestFillString() {
	draw2d.SetFontFolder("../resource/font/")
	i, gc := initGc(100, 100)
	draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
	gc.FillStroke()
	gc.SetFontSize(18)
	gc.MoveTo(10, 52)
	gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
	width := gc.FillString("cou")
	gc.RMoveTo(width+1, 0)
	gc.FillString("cou")
	saveToPngFile("TestFillString", i)
}
Example #3
0
func main() {
	i := image.NewRGBA(image.Rect(0, 0, 600, 600))
	gc := draw2d.NewGraphicContext(i)
	xc, yc := 100.0, 100.0
	radiusX, radiusY := 100.0, 100.0
	startAngle := 45.0 * (math.Pi / 180.0) /* angles are specified */
	angle := 360 * (math.Pi / 180.0)       /* in radians           */
	gc.SetLineWidth(10)
	gc.SetLineCap(draw2d.ButtCap)
	gc.SetStrokeColor(image.Black)
	gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle)
	gc.Stroke()
	// fill a circle
	gc.SetLineWidth(6)

	//	gc.MoveTo(xc, yc)
	//gc.LineTo(xc+math.Cos(startAngle)*radiusX, yc+math.Sin(startAngle)*radiusY)
	//	gc.MoveTo(xc, yc)
	//gc.LineTo(xc-radiusX, yc)
	gc.Stroke()

	gc.ArcTo(xc, yc, 10.0, 10.0, 0, 2*math.Pi)
	gc.Fill()
	saveToPngFile("TestDrawArc.png", i)

	gc.MoveTo(10.0, 10.0)
	gc.LineTo(100.0, 10.0)
	gc.Stroke()
	saveToPngFile("TestPath.png", i)
	draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
	gc.SetStrokeColor(image.Black)
	gc.FillStroke()
	gc.SetFontSize(18)
	gc.MoveTo(10, 52)
	gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
	width := gc.FillString("cou")
	fmt.Printf("width: %f\n", width)
	gc.RMoveTo(width+1, 0)
	gc.FillString("cou")
	saveToPngFile("TestFillString.png", i)
	width = gc.FillString("1234124512512512")

	fmt.Printf("width: %f\n", width)
	saveToPngFile("TestFillString.png", i)
}
Example #4
0
func TestFillString() {
	draw2d.SetFontFolder("../resource/font/")
	i, gc := initGc(100, 100)
	draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
	gc.FillStroke()
	gc.SetFillColor(image.Black)
	gc.SetFontSize(18)
	gc.Translate(6, 52)
	gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
	width := gc.FillString("cou")
	gc.Translate(width+1, 0)
	left, top, right, bottom := gc.GetStringBounds("cou")
	gc.SetStrokeColor(color.NRGBA{255, 0x33, 0x33, 0x80})
	draw2d.Rect(gc, left, top, right, bottom)
	gc.SetLineWidth(3.0)
	gc.Stroke()
	gc.SetStrokeColor(image.Black)
	gc.SetLineWidth(1.0)
	gc.StrokeString("cou")
	saveToPngFile("TestFillString", i)
}
Example #5
0
func gordon(gc draw2d.GraphicContext, x, y, w, h float64) {
	h23 := (h * 2) / 3

	blf := color.RGBA{0, 0, 0, 0xff}
	wf := color.RGBA{0xff, 0xff, 0xff, 0xff}
	nf := color.RGBA{0x8B, 0x45, 0x13, 0xff}
	brf := color.RGBA{0x8B, 0x45, 0x13, 0x99}
	brb := color.RGBA{0x8B, 0x45, 0x13, 0xBB}

	gc.MoveTo(x, y+h)
	gc.CubicCurveTo(x, y+h, x+w/2, y-h, x+w, y+h)
	gc.Close()
	gc.SetFillColor(brb)
	gc.Fill()
	draw2d.RoundRect(gc, x, y+h, x+w, y+h+h, 10, 10)
	gc.Fill()
	draw2d.Circle(gc, x, y+h, w/12) // left ear
	gc.SetFillColor(brf)
	gc.Fill()
	draw2d.Circle(gc, x, y+h, w/12-10)
	gc.SetFillColor(nf)
	gc.Fill()

	draw2d.Circle(gc, x+w, y+h, w/12) // right ear
	gc.SetFillColor(brf)
	gc.Fill()
	draw2d.Circle(gc, x+w, y+h, w/12-10)
	gc.SetFillColor(nf)
	gc.Fill()

	draw2d.Circle(gc, x+w/3, y+h23, w/9) // left eye
	gc.SetFillColor(wf)
	gc.Fill()
	draw2d.Circle(gc, x+w/3+10, y+h23, w/10-10)
	gc.SetFillColor(blf)
	gc.Fill()
	draw2d.Circle(gc, x+w/3+15, y+h23, 5)
	gc.SetFillColor(wf)
	gc.Fill()

	draw2d.Circle(gc, x+w-w/3, y+h23, w/9) // right eye
	gc.Fill()
	draw2d.Circle(gc, x+w-w/3+10, y+h23, w/10-10)
	gc.SetFillColor(blf)
	gc.Fill()
	draw2d.Circle(gc, x+w-(w/3)+15, y+h23, 5)
	gc.SetFillColor(wf)
	gc.Fill()

	gc.SetFillColor(wf)
	draw2d.RoundRect(gc, x+w/2-w/8, y+h+30, x+w/2-w/8+w/8, y+h+30+w/6, 5, 5) // left tooth
	gc.Fill()
	draw2d.RoundRect(gc, x+w/2, y+h+30, x+w/2+w/8, y+h+30+w/6, 5, 5) // right tooth
	gc.Fill()

	draw2d.Ellipse(gc, x+(w/2), y+h+30, w/6, w/12) // snout
	gc.SetFillColor(nf)
	gc.Fill()
	draw2d.Ellipse(gc, x+(w/2), y+h+10, w/10, w/12) // nose
	gc.SetFillColor(blf)
	gc.Fill()

}
// Defines the visualization of the figure according to position (0, 0).
func (this *RoundRectangle) Visualize() {
	graphicContext := GetTheImageGraphicContext()
	draw2d.RoundRect(graphicContext, 0, 0, this.Width, this.Height, this.Radius, this.Radius)
}