p5-sketch
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

How to use it

Since every class we create in our project needs to be able to use p5 functions, this package solves the problem by exposing the sketch object. So we can import it into any class and use p5 functions as needed.

main.js

import p from 'p5-sketch'
import MyExternalObject from './my-external-object'

let obj

p.setup = () => {
  p.createCanvas(600, 600)
  obj = new MyExternalObject()
}

p.draw = () => {
  p.background('PapayaWhip')
}

my-external-object.js

import p from 'p5-sketch'

export default class MyExternalObject {
  constructor() {
    this.x = 300
    this.y = 300
  }

  draw() {
    p.noStroke()
    p.fill('blue')
    p.circle(this.x, this.y, 100)
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i p5-sketch

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

1.15 kB

Total Files

4

Last publish

Collaborators

  • jersonlatorre