xxxxxxxxxx
39
/*
author: Weidi
......
this is a demo to show what is random function
......
random (min , max);
Return a random floating-point number between min number with max number you set.
.......
random(max); ----- this equals to random(0, max);
this function will return a random float num between 0 and maximum
if you min number is 0, then you can write just with maximum number for your range - random(max)
*/
function setup() {
createCanvas(400, 400);
//change the framerate to 5 frames per second
frameRate(5);
}
function draw() {
background(220);
//a white circle pop up in random position of canvas
fill('white');
noStroke();
circle(random(width),random(height),50);
//a red rectangle in random size with different width and height both from 20 to 90 pixels
fill('red');
rectMode(CENTER);
rect(width/2,height/2-40,random(20,90),random(20,90));
//a random color square below the red one
fill(random(255),random(100,200),random(80,100));
rect(width/2,height/2+40,80,80);
}