p5 is a simple package that provides primitives resembling the ones exposed by p5js.org

p5

GitHub release go.dev reference CI GoDoc License codecov

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

License

p5 is released under the BSD-3 license.

Documentation

Documentation for p5 is served by GoDev.

Contributing

Guidelines for contributing to go-p5 the same than for the Go project.

Installation

This project relies on Gio for the graphics parts. As Gio uses system libraries to display graphics, you need to install those for your system/OS for p5 to work properly. See Gio/install for details.

Example

package main

import (
	"image/color"
	"math"

	"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.StrokeWidth(2)
	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)

	p5.Stroke(color.Black)
	p5.StrokeWidth(5)
	p5.Arc(300, 100, 80, 20, 0, 1.5*math.Pi)
}

img-hello

Comments
  • Implement keyboard API

    Implement keyboard API

    Base API

    Functions:

    • p5.KeyIsDown(code string) bool - checks if given key is already pressed

    Variables:

    • p5.KeyIsPressed bool - whether any key is pressed now
    • p5.Key string - name of last pressed/typed key

    Callbacks

    Callbacks can be set with following functions:

    • p5.SetKeyPressedCallback(f KeyEventFunc)
    • p5.SetKeyTypedCallback(f KeyEventFunc)
    • p5.SetKeyReleasedCallback(f KeyEventFunc)

    Caveats:

    • There is no way to detect lower case characters, so we always use upper case. Bear that in mind, especially when working with KeyTyped event.

    @sbinet I am not sure if the code is safe, so please take a look. I used your examples key-snake and key-pressed from https://github.com/go-p5/p5/pull/52. Feel free to suggest changes, this is just proposal :grinning:

  • Bezier curve

    Bezier curve

    updated #6

    This PR adds the cubic Bézier curve to the api.

    I added a dedicated test case and a dedicated golden file since I believe it will make maintenance easier as the api grows.

  • Tests are fragile due to image comparison

    Tests are fragile due to image comparison

    I am trying to run locally the test suite but it fails due to existing delta of 0.05

    === RUN TestAPIShapes api_test.go:61: testdata/api_shapes.png: images compare different --- FAIL: TestAPIShapes (0.08s)

    Increasing delta to 0.06 make test green.

    Is there any other more robust way to implement tests avoiding image comparison completely? Is there a way to compare the state that produces the images instead of the images themselves?

  • Questions About specific stuff

    Questions About specific stuff

    I tried run p5 while doing other stuff like this:

    image basically, in this situation the p5 window doesnt run, there's a way to run it, while listening to connections?

    I tried running it in concurrency mode: image but didnt worked.

    The Second question is: How to Run it on browser using gorilla?

  • gio: sw renderer hiccups

    gio: sw renderer hiccups

    with Gio>=v0.0.0-20210729070555-8cec7e04eb71 there appears to be a slight graphical hiccups when comparing an image produced with or w/o the libGL s/w renderer (the GitHubActions CI test on Linux falls back on using libGL s/w renderer.)

    • image with GPU backend: api_shapes_curve_golden

    • image with s/w renderer: curve-swcompute

    see:

    • https://github.com/go-p5/p5/commit/82e90d6
  • p5: implement FrameRate()

    p5: implement FrameRate()

    https://p5js.org/reference/#/p5/frameRate

    Currently the is no way to override the default ticker, so there is no way to change the frame rate.

    One solution would be to reset the ticker using https://golang.org/pkg/time/#Ticker.Reset whenever there is an update to Proc.ctl.FrameRate().

  • p5: retain state from draw-to-draw

    p5: retain state from draw-to-draw

    in Processing and in p5js, the state of the display is retained from iteration to iteration.

    right now, in p5, we don't (so, for example, in the mouse-pressed example, the circle around the mouse follows the mouse but doesn't leave a trail of circles across its path, as the p5js example does.)

    that's actually a feature of Gio.

    to "simulate" the same behaviour, we could have an image.Image field that is drawn to at the end of each draw cycle. at cycle+1, we draw that last image.Image before invoking the user's draw function.

  • p5: rework event-loop drawing

    p5: rework event-loop drawing

    right now, p5 relies on Gio to get its re-draw events, together with a little ticker goroutine (that ticks at the requested frequency, requesting Gio for redrawing the canvas).

    it's a bit brittle because it's intertwined with other Gio events that will re-draw the canvas (such as a resize of the window), which will confuse users' draw methods (e.g.: the current solar-system draw methods expects a fixed frequency and computes delta-t (and thus positions, speeds and accelerations) from that frequency).

    we'd need to somehow separate or distinguish the 2 sets of events. (probably by only re-drawing when the ticker goroutine marked some Proc state as "dirty"?)

Related tags
Package shapes provides an algebra for handling shapes

About Package shapes provides the algebra and machinery for dealing with the metainformation of shapes of a tensor. Why a shape package? The shape pac

Jan 14, 2022
The android-go project provides a platform for writing native Android apps in Go programming language.
The android-go project provides a platform for writing native Android apps in Go programming language.

android-go The android-go project aims to provide a platform (namely an SDK) for writing native Android apps in Go programming language. All things he

Jan 5, 2023
Provides a method to create thumbnails from provided images.

Thumbnail Generation Package for Go This package provides method to create thumbnails from provided images. Installation Use to go command: $ go get g

Aug 31, 2022
Open-in-linear - A tool provides a shortcut to opening a linear issue in the desktop app or browser

This tool provides a shortcut to opening a linear issue in the desktop app or browser.

Jan 25, 2022
Imaging is a simple image processing package for Go
Imaging is a simple image processing package for Go

Imaging Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.). All the image process

Dec 30, 2022
magicimage is a simple image validation & save with rich feature package for net/http

Installation go get github.com/IndominusByte/magicimage Usage examples A few usage examples can be found below. See the documentation for the full lis

Feb 5, 2022
A (very) simple graph package that utilizes the Generics features in Go 1.18

A (very) simple graph package that utilizes the Generics features in Go 1.18

May 11, 2022
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get github.com/wroge/wgs84 Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Nov 25, 2022
Go package for fast high-level image processing powered by libvips C library

bimg Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API. bimg was designed to be

Jan 2, 2023
Go bindings for GStreamer (retired: currently I don't use/develop this package)

Retired. I don't use/develop this package anymore. Go bindings for GStreamer at a very early stage of maturity. This package is based on GLib bindings

Nov 10, 2022
Go package for decoding and encoding TARGA image format

tga tga is a Go package for decoding and encoding TARGA image format. It supports RLE and raw TARGA images with 8/15/16/24/32 bits per pixel, monochro

Sep 26, 2022
Go package for computer vision using OpenCV 4 and beyond.
Go package for computer vision using OpenCV 4 and beyond.

GoCV The GoCV package provides Go language bindings for the OpenCV 4 computer vision library. The GoCV package supports the latest releases of Go and

Jan 1, 2023
Go Perceptual image hashing package

goimagehash Inspired by imagehash A image hashing library written in Go. ImageHash supports: Average hashing Difference hashing Perception hashing Wav

Jan 3, 2023
generativeart is a Go package to generate many kinds of generative art.
generativeart is a Go package to generate many kinds of generative art.

generativeart is a Go package to generate many kinds of generative art. The goal is to collect some excellent generative art (implemented in R or Processing), and rewrite them in Go again

Dec 29, 2022
golang package to find the K most dominant/prominent colors in an image
golang package to find the K most dominant/prominent colors in an image

prominentcolor Find the K most dominant colors in an image The Kmeans function returns the K most dominant colors in the image, ordered in the order o

Nov 7, 2022
Go package captcha implements generation and verification of image and audio CAPTCHAs.
Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dec 30, 2022
openGL Have Fun - A Go package that makes life with OpenGL enjoyable.

glhf openGL Have Fun - A Go package that makes life with OpenGL enjoyable. go get github.com/faiface/glhf Main features Garbage collected OpenGL obje

Jan 1, 2023
Procedural texture generation package.
Procedural texture generation package.

Texture Generation A package for the procedural generation of textures. Based on the ideas contained in the Bryce 3D deep texture editor. More example

Sep 8, 2022
asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

asciigrid asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID. Install go

Jul 3, 2022