xxxxxxxxxx
50
/**
** -------------------- Let it Snow! --------------------------
**
** 1. Make the snowflakes drift slowly downwards
**
** 2. Loop the snowflakes back to the top of the screen
**
** 3. Randomly change their size and speed each loop
**
** Extra:
**
** 4. Can you interact with the snowflakes?
**
** 5. Can you add a "shake" button to randomize the snowflakes?
**
**. 6. Can you add more snowflakes everytime the user clicks their mouse?
**
** ------------------------------------------------------------
*/
var snowflakes = [];
var numberOfSnowflakes = 50;
function setup() {
createCanvas(400, 400);
// Create snowflakes with random x, y, size and speed
for (var i = 0; i < numberOfSnowflakes; i++) {
snowflakes[i] = {
x: random(0, width),
y: random(0, height),
size: random(2, 8),
speed: random(0.25, 1.25),
};
}
}
function draw() {
background(220);
noStroke();
fill(255);
drawSnowflakes();
}
function drawSnowflakes() {
for (var i = 0; i < snowflakes.length; i++) {
circle(snowflakes[i].x, snowflakes[i].y, snowflakes[i].size);
}
}