xxxxxxxxxx
47
// This sketch uses the random() function to make a random pumpkin patch!
function setup() {
createCanvas(400, 400);
// Slow down the frame rate a little so we can see our pumpkins better.
// Deleting this line will make our sketch faster.
frameRate(5);
background(0, 32, 0);
}
function draw() {
// Give our pumpkin a random location and size.
const pumpkinCenterX = random(0, width);
const pumpkinCenterY = random(0, height);
const pumpkinWidth = random(100, 300);
const pumpkinHeight = random(50, 200);
// Give our pumpkin a random color. Try changing these numbers!
const pumpkinRed = random(100, 255);
const pumpkinGreen = random(0, 150);
const pumpkinBlue = random(0, 100);
// We don't redraw the background, so all our old pumpkins stick around!
// stem
stroke(0, 160, 0);
strokeWeight(20);
line(pumpkinCenterX,
pumpkinCenterY - pumpkinHeight * .5,
pumpkinCenterX - pumpkinWidth * .25,
pumpkinCenterY - pumpkinHeight * .75);
// Set the color of the pumpkin.
fill(pumpkinRed, pumpkinGreen, pumpkinBlue);
// This line makes the outline a little darker than the fill.
stroke(pumpkinRed * .5, pumpkinGreen * .5, pumpkinBlue * .5);
strokeWeight(3);
// pumpkin
ellipse(pumpkinCenterX, pumpkinCenterY, pumpkinWidth, pumpkinHeight);
ellipse(pumpkinCenterX, pumpkinCenterY, pumpkinWidth * .75, pumpkinHeight);
ellipse(pumpkinCenterX, pumpkinCenterY, pumpkinWidth * .5, pumpkinHeight);
ellipse(pumpkinCenterX, pumpkinCenterY, pumpkinWidth * .25, pumpkinHeight);
}