README

pinhole

GoDoc

3D Wireframe Drawing Library for Go

Javascript Version
Demo

earthshapes spiralgopher

Why does this exist?

I needed a CPU based 3D rendering library with a very simple API for visualizing data structures. No bells or whistles, just clean lines and solid colors.

Getting Started

Installing

To start using pinhole, install Go and run go get:

$ go get -u github.com/tidwall/pinhole

This will retrieve the library.

Using

The coordinate space has a locked origin of 0,0,0 with the min/max boundaries of -1,-1,-1 to +1,+1,+1. The Z coordinate extends from -1 (nearest) to +1 (farthest).

There are four types of shapes; line, cube, circle, and dot. These can be transformed with the Scale, Rotate, and Translate functions. Multiple shapes can be transformed by nesting in a Begin/End block.

A simple cube:

p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.SavePNG("cube.png", 500, 500, nil)

Rotate the cube:

p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.Rotate(math.Pi/3, math.Pi/6, 0)
p.SavePNG("cube.png", 500, 500, nil)

Add, rotate, and transform a circle:

p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.Rotate(math.Pi/3, math.Pi/6, 0)

p.Begin()
p.DrawCircle(0, 0, 0, 0.2)
p.Rotate(0, math.Pi/2, 0)
p.Translate(-0.6, -0.4, 0)
p.Colorize(color.RGBA{255, 0, 0, 255})
p.End()

p.SavePNG("cube.png", 500, 500, nil)

Contact

Josh Baker @tidwall

License

pinhole source code is available under the ISC License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultImageOptions = &ImageOptions{
	BGColor:   color.White,
	LineWidth: 1,
	Scale:     1,
}

Functions

This section is empty.

Types

type ImageOptions

type ImageOptions struct {
	BGColor   color.Color
	LineWidth float64
	Scale     float64
}

type Pinhole

type Pinhole struct {
	// contains filtered or unexported fields
}

func New

func New() *Pinhole

func (*Pinhole) Begin

func (p *Pinhole) Begin()

func (*Pinhole) Center

func (p *Pinhole) Center()

func (*Pinhole) Colorize

func (p *Pinhole) Colorize(color color.Color)

func (*Pinhole) DrawCircle

func (p *Pinhole) DrawCircle(x, y, z float64, radius float64)

func (*Pinhole) DrawCube

func (p *Pinhole) DrawCube(minx, miny, minz, maxx, maxy, maxz float64)

func (*Pinhole) DrawDot

func (p *Pinhole) DrawDot(x, y, z float64, radius float64)

func (*Pinhole) DrawLine

func (p *Pinhole) DrawLine(x1, y1, z1, x2, y2, z2 float64)

func (*Pinhole) DrawRect

func (p *Pinhole) DrawRect(minx, miny, maxx, maxy, z float64)

func (*Pinhole) DrawString

func (p *Pinhole) DrawString(x, y, z float64, s string)

func (*Pinhole) End

func (p *Pinhole) End()

func (*Pinhole) Image

func (p *Pinhole) Image(width, height int, opts *ImageOptions) *image.RGBA

func (*Pinhole) LoadObj

func (p *Pinhole) LoadObj(r io.Reader) error

func (*Pinhole) Rotate

func (p *Pinhole) Rotate(x, y, z float64)

func (*Pinhole) SavePNG

func (p *Pinhole) SavePNG(path string, width, height int, opts *ImageOptions) error

func (*Pinhole) Scale

func (p *Pinhole) Scale(x, y, z float64)

func (*Pinhole) Translate

func (p *Pinhole) Translate(x, y, z float64)

Source Files

Directories

Path Synopsis