xxxxxxxxxx
37
function setup() {
createCanvas(400, 400);
frameRate(1);
}
function draw() {
background(220);
// Create flower object.
let myFlower = createFlower();
// Use flower object properties to draw flower as an ellipse.
fill(myFlower.color);
ellipse(myFlower.x, myFlower.y, myFlower.size);
}
function createFlower() {
// Define a flower object.
// Set the x to be a random location on the left half of the screen.
// Set the y to be a random location on the bottom half of the screen.
// Set the size to be a random value from tiny (5) to big (100).
// Set the color to shades of blue.
let flower = {
x: random(20, 200),
y: random(200, 380),
size: random(5, 100),
lifespan: random(255, 300),
color: color(0, 0, random(255))
};
// Return flower object.
return flower;
}