Documentation ¶
Overview ¶
Package p5 provides types and functions to draw geometrical shapes on a canvas, interact with the mouse and keyboard, with the aim to learn programming with a graphics aid.
p5 is inspired by Processing and its p5js port:
A very simple p5 program could look like:
func main() { p5.Run(setup, draw) } func setup() { p5.Canvas(200, 200) p5.Background(color.Black) } func draw() { p5.Fill(color.White) p5.Square(10, 10, 50, 50) }
p5 actually provides two set of APIs:
- one closely following the p5js API, with global functions and hidden state,
- another one based on the p5.Proc type that encapsulates state.
Index ¶
- Variables
- func Arc(x, y, w, h float64, beg, end float64)
- func Background(c color.Color)
- func Canvas(w, h int)
- func Circle(x, y, d float64)
- func Ellipse(x, y, w, h float64)
- func Fill(c color.Color)
- func Line(x1, y1, x2, y2 float64)
- func Quad(x1, y1, x2, y2, x3, y3, x4, y4 float64)
- func Rect(x, y, w, h float64)
- func Run(setup, draw Func)
- func Screenshot(fname string)
- func Square(x, y, s float64)
- func Stroke(c color.Color)
- func StrokeWidth(v float64)
- func Text(txt string, x, y float64)
- func TextSize(size float64)
- func Triangle(x1, y1, x2, y2, x3, y3 float64)
- type Buttons
- type Func
- type Proc
- func (p *Proc) Arc(x, y, w, h float64, beg, end float64)
- func (p *Proc) Background(c color.Color)
- func (p *Proc) Canvas(w, h int)
- func (p *Proc) Circle(x, y, d float64)
- func (p *Proc) Ellipse(x, y, w, h float64)
- func (p *Proc) Fill(c color.Color)
- func (p *Proc) Line(x1, y1, x2, y2 float64)
- func (p *Proc) Quad(x1, y1, x2, y2, x3, y3, x4, y4 float64)
- func (p *Proc) Rect(x, y, w, h float64)
- func (p *Proc) Run()
- func (p *Proc) Screenshot(fname string) error
- func (p *Proc) Square(x, y, s float64)
- func (p *Proc) Stroke(c color.Color)
- func (p *Proc) StrokeWidth(v float64)
- func (p *Proc) Text(txt string, x, y float64)
- func (p *Proc) TextSize(size float64)
- func (p *Proc) Triangle(x1, y1, x2, y2, x3, y3 float64)
Constants ¶
This section is empty.
Variables ¶
var Event struct { Mouse struct { Pressed bool PrevPosition struct { X float64 Y float64 } Position struct { X float64 Y float64 } Buttons Buttons } }
Event is the current event pushed from the system.
Functions ¶
func Arc ¶
Arc draws an ellipsoidal arc centered at (x,y), with the provided width and height, and a path from the beg to end radians. Positive angles denote a counter-clockwise path.
func Background ¶
Background defines the background color for the painting area. The default color is transparent.
func Ellipse ¶
func Ellipse(x, y, w, h float64)
Ellipse draws an ellipse at (x,y) with the provided width and height.
func Quad ¶
func Quad(x1, y1, x2, y2, x3, y3, x4, y4 float64)
Quad draws a quadrilateral, connecting the 4 points (x1,y1), (x2,y2), (x3,y3) and (x4,y4) together.
func Rect ¶
func Rect(x, y, w, h float64)
Rect draws a rectangle at (x,y) with width w and height h.
func Run ¶
func Run(setup, draw Func)
Run executes the user functions setup and draw. Run never exits.
func Screenshot ¶ added in v0.3.0
func Screenshot(fname string)
Screenshot saves the current canvas to the provided file. Supported file formats are: PNG, JPEG and GIF.
func StrokeWidth ¶ added in v0.2.0
func StrokeWidth(v float64)
StrokeWidth sets the size of the strokes.
Types ¶
type Proc ¶
Proc is a p5 processor.
Proc runs the bound Setup function once before the event loop. Proc then runs the bound Draw function once per event loop iteration.
func (*Proc) Arc ¶ added in v0.2.0
Arc draws an ellipsoidal arc centered at (x,y), with the provided width and height, and a path from the beg to end radians. Positive angles denote a counter-clockwise path.
func (*Proc) Background ¶ added in v0.2.0
Background defines the background color for the painting area. The default color is transparent.
func (*Proc) Canvas ¶ added in v0.2.0
Canvas defines the dimensions of the painting area, in pixels.
func (*Proc) Quad ¶
Quad draws a quadrilateral, connecting the 4 points (x1,y1), (x2,y2), (x3,y3) and (x4,y4) together.
func (*Proc) Screenshot ¶ added in v0.3.0
Screenshot saves the current canvas to the provided file. Supported file formats are: PNG, JPEG and GIF.
func (*Proc) StrokeWidth ¶ added in v0.2.0
StrokeWidth sets the size of the strokes.