p5

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: BSD-3-Clause Imports: 21 Imported by: 10

README

p5

GitHub release go.dev reference CI GoDoc License

p5 is a simple package that provides primitives resembling the ones exposed by the p5/processing library.

Example

package main

import (
	"image/color"

	"github.com/go-p5/p5"
)

func main() {
	p5.Run(setup, draw)
}

func setup() {
	p5.Canvas(400, 400)
	p5.Background(color.Gray{Y: 220})
}

func draw() {
	p5.Fill(color.RGBA{R: 255, A: 208})
	p5.Ellipse(50, 50, 80, 80)

	p5.Fill(color.RGBA{B: 255, A: 208})
	p5.Quad(50, 50, 80, 50, 80, 120, 60, 120)

	p5.Fill(color.RGBA{G: 255, A: 208})
	p5.Rect(200, 200, 50, 100)

	p5.Fill(color.RGBA{G: 255, A: 208})
	p5.Triangle(100, 100, 120, 120, 80, 120)

	p5.TextSize(24)
	p5.Text("Hello, World!", 10, 300)
}

img-hello

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Arc(x, y, w, h float64, beg, end float64)

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

func Background(c color.Color)

Background defines the background color for the painting area. The default color is transparent.

func Canvas

func Canvas(w, h int)

Canvas defines the dimensions of the painting area, in pixels.

func Circle

func Circle(x, y, d float64)

Circle draws a circle at (x,y) with a diameter d.

func Ellipse

func Ellipse(x, y, w, h float64)

Ellipse draws an ellipse at (x,y) with the provided width and height.

func Fill

func Fill(c color.Color)

Fill sets the color used to fill shapes.

func Line

func Line(x1, y1, x2, y2 float64)

Line draws a line between (x1,y1) and (x2,y2).

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 Square

func Square(x, y, s float64)

Square draws a square at (x,y) with size s.

func Stroke

func Stroke(c color.Color)

Stroke sets the color of the strokes.

func StrokeWidth added in v0.2.0

func StrokeWidth(v float64)

StrokeWidth sets the size of the strokes.

func Text

func Text(txt string, x, y float64)

Text draws txt on the screen at (x,y).

func TextSize

func TextSize(size float64)

TextSize sets the text size.

func Triangle

func Triangle(x1, y1, x2, y2, x3, y3 float64)

Triangle draws a triangle, connecting the 3 points (x1,y1), (x2,y2) and (x3,y3) together.

Types

type Buttons

type Buttons uint8

Buttons is a set of mouse buttons.

const (
	ButtonLeft Buttons = 1 << iota
	ButtonRight
	ButtonMiddle
)

func (Buttons) Contain

func (b Buttons) Contain(buttons Buttons) bool

Contain reports whether the set b contains all of the buttons.

type Func

type Func func()

Func is the type of functions users provide to p5.

type Proc

type Proc struct {
	Setup Func
	Draw  Func
	Mouse Func
	// contains filtered or unexported fields
}

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

func (p *Proc) Arc(x, y, w, h float64, beg, end float64)

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

func (p *Proc) Background(c color.Color)

Background defines the background color for the painting area. The default color is transparent.

func (*Proc) Canvas added in v0.2.0

func (p *Proc) Canvas(w, h int)

Canvas defines the dimensions of the painting area, in pixels.

func (*Proc) Circle

func (p *Proc) Circle(x, y, d float64)

Circle draws a circle at (x,y) with a diameter d.

func (*Proc) Ellipse

func (p *Proc) Ellipse(x, y, w, h float64)

Ellipse draws an ellipse at (x,y) with the provided width and height.

func (*Proc) Fill added in v0.2.0

func (p *Proc) Fill(c color.Color)

Fill sets the color used to fill shapes.

func (*Proc) Line

func (p *Proc) Line(x1, y1, x2, y2 float64)

Line draws a line between (x1,y1) and (x2,y2).

func (*Proc) Quad

func (p *Proc) 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 (*Proc) Rect

func (p *Proc) Rect(x, y, w, h float64)

Rect draws a rectangle at (x,y) with width w and height h.

func (*Proc) Run

func (p *Proc) Run()

func (*Proc) Square

func (p *Proc) Square(x, y, s float64)

Square draws a square at (x,y) with size s.

func (*Proc) Stroke added in v0.2.0

func (p *Proc) Stroke(c color.Color)

Stroke sets the color of the strokes.

func (*Proc) StrokeWidth added in v0.2.0

func (p *Proc) StrokeWidth(v float64)

StrokeWidth sets the size of the strokes.

func (*Proc) Text

func (p *Proc) Text(txt string, x, y float64)

Text draws txt on the screen at (x,y).

func (*Proc) TextSize

func (p *Proc) TextSize(size float64)

TextSize sets the text size.

func (*Proc) Triangle

func (p *Proc) Triangle(x1, y1, x2, y2, x3, y3 float64)

Triangle draws a triangle, connecting the 3 points (x1,y1), (x2,y2) and (x3,y3) together.

Directories

Path Synopsis
cmd
example

Jump to

Keyboard shortcuts

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