xxxxxxxxxx
37
// each sketch gets set up like an object/class
let sketch1 = function(k){
// all p5 functions need to be prefixed with initial letter
k.setup = function() {
k.createCanvas(400, 400);
k.fill(255,255,0);
}
k.draw = function() {
//grey background
k.background(220);
k.ellipse(k.mouseX,k.mouseY,50,50);
}
}
// each sketch needs a new variable name and initial letter
let sketch2 = function(p){
p.setup = function() {
p.createCanvas(400, 400);
p.fill(0,255,255);
}
p.draw = function() {
// red background
p.background(220,0,0);
p.ellipse(p.mouseX,p.mouseY,50,50);
}
}
// each sketch created in global scope by using new p5();
let myp5_1 = new p5(sketch1);
let myp5_2 = new p5(sketch2);