xxxxxxxxxx
51
/*
Objectives:
- Learn Conditional statements
- Introduce the idea of probability
*/
let space = 20;
let x = 0;
let y = 0;
function setup() {
createCanvas(400, 400);
background(255);
}
function draw() {
// The function random(), returns a value
// between 0 and 1
let randy = random();
// This is the equivalent of flipping a coin. There is
// 50% chance it will be greater than 0.5 and 50% it
// will be less than 0.5
if (randy > 0.5) {
// Make sure you understand these algorithms to create
// a / and a \. Practice using graph paper
line(x, y, x + space, y + space);
} else {
line(x, y + space, x + space, y);
}
// This conditional decides when to draw on a row
// or change to the next row
if (x > width) {
x = 0;
y = y + space;
} else {
x += space;
}
}
/*
CHALLENGES
1. Add more shapes, circles, triangles, rectangles and arcs.
2. Add colour to the shapes.
3. Change the size and colour with your space,x and y variables.
4. Make sure that the program stops drawing when the canvas is full.
5. Have the drawing, loop to the top once it reaches the bottom of the canvas, drawing on top of the existing image
*/