Skip to content

Instantly share code, notes, and snippets.

@s-estay
Last active September 4, 2019 19:01
Show Gist options
  • Save s-estay/84fc840aa98f7dea1b85153f5f81e524 to your computer and use it in GitHub Desktop.
Save s-estay/84fc840aa98f7dea1b85153f5f81e524 to your computer and use it in GitHub Desktop.
P5js map random example
//instance mode
//map and random functions
var sketch = function(p){
var bcol = 0;
//objects
//in c++ this would be a struct
var spot = {
x : 100,
y : 50
};
var col = {
r : 255,
g : 0,
b : 0
};
p.setup = function(){
p.createCanvas(640, 100);
}
p.draw = function(){
p.background(0);
col.r = p.random(100, 255);
col.b = p.random(100, 255);
spot.x = p.random(0, p.width);
spot.y = p.random(0, p.height);
p.noStroke();
p.fill(col.r, col.g, col.b);
p.ellipse(spot.x, spot.y, 20, 20);
}
}
var myp5 = new p5(sketch, 'script-map-random');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment