Ejemplo n.º 1
0
// Main draws geometry and returns the filename. This should only be
// used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	// Draw the droid
	Draw(gc, 297, 210)

	// Return the output filename
	return samples.Output("geometry", ext), nil
}
Ejemplo n.º 2
0
// Main draws "Hello World" and returns the filename. This should only be
// used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	// Draw hello world
	Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI()))

	// Return the output filename
	return samples.Output("helloworld", ext), nil
}
Ejemplo n.º 3
0
// Main draws a left hand and ear of a gopher. Afterwards it returns
// the filename. This should only be used 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
}
Ejemplo n.º 4
0
// Main draws a rotated face of the gopher. Afterwards it returns
// the filename. This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	gc.SetStrokeColor(image.Black)
	gc.SetFillColor(image.White)
	gc.Save()
	// Draw a (partial) gopher
	gc.Translate(-60, 65)
	gc.Rotate(-30 * (math.Pi / 180.0))
	Draw(gc, 48, 48, 240, 72)
	gc.Restore()

	// Return the output filename
	return samples.Output("gopher2", ext), nil
}
Ejemplo n.º 5
0
// Main draws the different line caps and joins.
// This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	// Draw the line
	const offset = 75.0
	x := 35.0
	caps := []draw2d.LineCap{draw2d.ButtCap, draw2d.SquareCap, draw2d.RoundCap}
	joins := []draw2d.LineJoin{draw2d.BevelJoin, draw2d.MiterJoin, draw2d.RoundJoin}
	for i := range caps {
		Draw(gc, caps[i], joins[i], x, 50, x, 160, offset)
		x += offset
	}

	// Return the output filename
	return samples.Output("linecapjoin", ext), nil
}
Ejemplo n.º 6
0
// Main draws the image frame and returns the filename.
// This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	// Margin between the image and the frame
	const margin = 30
	// Line width od the frame
	const lineWidth = 3

	// Gopher image
	gopher := samples.Resource("image", "gopher.png", ext)

	// Draw gopher
	err := Draw(gc, gopher, 297, 210, margin, lineWidth)

	// Return the output filename
	return samples.Output("frameimage", ext), err
}
Ejemplo n.º 7
0
// Main draws vertically spaced lines and returns the filename.
// This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	gc.SetFillRule(draw2d.FillRuleWinding)
	gc.Clear()
	// Draw the line
	for x := 5.0; x < 297; x += 10 {
		Draw(gc, x, 0, x, 210)
	}
	gc.ClearRect(100, 75, 197, 135)
	draw2dkit.Ellipse(gc, 148.5, 105, 35, 25)
	gc.SetFillColor(color.RGBA{0xff, 0xff, 0x44, 0xff})
	gc.FillStroke()

	// Return the output filename
	return samples.Output("line", ext), nil
}
Ejemplo n.º 8
0
// Main draws the tiger
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	gc.Save()

	// flip the image
	gc.Translate(0, 200)
	gc.Scale(0.35, -0.35)
	gc.Translate(70, -200)

	// Tiger postscript drawing
	tiger := samples.Resource("image", "tiger.ps", ext)

	// Draw tiger
	Draw(gc, tiger)
	gc.Restore()

	// Return the output filename
	return samples.Output("postscript", ext), nil
}