samples

package
v0.0.0-...-cea70a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2017 License: BSD-2-Clause Imports: 1 Imported by: 0

README

draw2d samples

Various samples for using draw2d

Using the image backend

The following Go code draws the android sample on a png image:

import (
	"image"

	"github.com/llgcode/draw2d"
	"github.com/llgcode/draw2d/samples/android"
)

function main(){}
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)
	// Draw Android logo
	fn, err := android.Main(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", fn, err)
		return
	}
	// Save to png
	err = draw2d.SaveToPngFile(fn, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", fn, err)
	}
}

Using the pdf backend

The following Go code draws the android sample on a pdf document:

import (
	"image"

	"github.com/llgcode/draw2d/draw2dpdf"
	"github.com/llgcode/draw2d/samples/android"
)

function main(){}
	// Initialize the graphic context on a pdf document
	dest := draw2dpdf.NewPdf("L", "mm", "A4")
	gc := draw2dpdf.NewGraphicContext(dest)
	// Draw Android logo
	fn, err := android.Main(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", fn, err)
		return
	}
	// Save to pdf
	err = draw2dpdf.SaveToPdfFile(fn, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", fn, err)
	}
}

Testing

These samples are run as tests from the root package folder draw2d by:

go test ./...

Or if you want to run with test coverage:

go test -cover ./... | grep -v "no test"

The following files are responsible to run the image tests:

draw2d/test_test.go
draw2d/samples_test.go

The following files are responsible to run the pdf tests:

draw2d/pdf/test_test.go
draw2dpdf/samples_test.go

Documentation

Overview

Package samples provides examples which can be used with different backends. They are also used for testing and coverage of the draw2d package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Output

func Output(name, ext string) string

Output returns the output filename for testing.

func Resource

func Resource(folder, filename, ext string) string

Resource returns a resource filename for testing.

Types

This section is empty.

Directories

Path Synopsis
Package android draws an android avatar.
Package android draws an android avatar.
Package frameimage centers a png image and rotates it.
Package frameimage centers a png image and rotates it.
Package geometry draws some geometric tests.
Package geometry draws some geometric tests.
Package gopher draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
Package gopher draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
Package gopher2 draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
Package gopher2 draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
Package helloworld displays multiple "Hello World" (one rotated) in a rounded rectangle.
Package helloworld displays multiple "Hello World" (one rotated) in a rounded rectangle.
Open an OpenGl window and display a rectangle using a OpenGl GraphicContext
Open an OpenGl window and display a rectangle using a OpenGl GraphicContext
Package line draws vertically spaced lines.
Package line draws vertically spaced lines.
Package linecapjoin demonstrates the different line caps and joins.
Package linecapjoin demonstrates the different line caps and joins.
Package postscript reads the tiger.ps file and draws it to a backend.
Package postscript reads the tiger.ps file and draws it to a backend.
Open a OpenGL window and display a tiger interpreting a postscript file
Open a OpenGL window and display a tiger interpreting a postscript file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL