Skip to content

Instantly share code, notes, and snippets.

@s-estay
Last active March 20, 2018 10:20
Show Gist options
  • Save s-estay/cb20211fe3f89dd290bf0e118b8960b8 to your computer and use it in GitHub Desktop.
Save s-estay/cb20211fe3f89dd290bf0e118b8960b8 to your computer and use it in GitHub Desktop.
Create script using instance mode.
//instance mode
//template for creating a p5 sketch (kind of)
var sketch = function(p){
//RGB rainbow colors
p.rainbowR = [248, 255, 255, 254, 208, 105, 18, 68, 59];
p.rainbowG = [12, 51, 102, 174, 195, 208, 189, 68, 12];
p.rainbowB = [18, 17, 68, 45, 16, 37, 185, 221, 189];
var i;
var t = p.rainbowR.length;
p.setup = function(){
p.createCanvas(640, 100);
i = 0;
}
p.draw = function(){
//background
p.background(255);
//borders
p.fill(255);
p.stroke(0);
p.rect(0, 0, 639, 99);
//ellipse click
p.stroke(255);
p.fill(p.rainbowR[i], p.rainbowG[i], p.rainbowB[i]);
p.ellipse(p.mouseX, p.mouseY, 50, 50);
//ellipse static
p.stroke(255);
p.fill(0, 100);
p.ellipse(320, 50, 50, 50);
}
p.mousePressed = function(){
if(i < t - 1){
i += 1;
}
else{
i = 0;
}
}
}
//after we have created the template
//we can create new p5 objects
var myp5_1 = new p5(sketch, 'script-holder-1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment