xxxxxxxxxx
43
// FS in DA: Variables and if-else
//
// Ewan Klein
// ewan@prewired.org
//
// This is helpful: https://p5js.org/reference/
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220, 180, 30);
noStroke();
// Set some names for colours
// We use 'let' to declare a new variable
let red = color(255, 0, 0);
let green = color(0, 255, 0);
let blue = color(0, 0, 255);
let orange = color(255, 102, 0);
let white = color(255, 255, 255);
// The colour of the rectangle changes
// while the mouse is being held down
// 'mouseIsPressed' is a variable with two possible values,
// true and false.
if (mouseIsPressed) {
fill(red);
} else {
fill(orange);
}
rect(152, 0, 60, 100);
// Set the fill color to green
fill(green);
ellipse(200, 240, 80, 80);
// Set the fill color to blue
fill(blue);
triangle(250, 250, 390, 250, 310, 80)
}