Last active
September 4, 2019 19:01
-
-
Save s-estay/84fc840aa98f7dea1b85153f5f81e524 to your computer and use it in GitHub Desktop.
P5js map random example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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