p5-global2instance
Convert p5js code/snippet from global to instance mode
Install
npm install p5-global2instance
Usage
There are 2 away to use this script.
CLI
p5-global2instance sourceCode.js
This will produce file sourceCode.p5.js
.
For more details use --help
node test.js --help Usage: test [options] [file] Options: -o, --output [file] Save output file to [file] -p, --print Print result to stdout -h, --help output usage information
Import as module
Take this example code
const p5Convert = const sourceCode = `var current;var previous; function setup () { createCanvas(720, 400);}; function draw () { background(0);};` let output = console
It will output
; { var current; var previous; sketch { sketch; }; sketch { sketchbackground0; };}
Options
You can also pass esprima and escodegen options.