xxxxxxxxxx
58
const SNOWFLAKES_PER_LAYER = 200;
const MAX_SIZE = 5;
const GRAVITY = 0.55;
const LAYER_COUNT = 3;
const WIND_SPEED = 1;
const WIND_CHANGE = 0.0025;
const SNOWFLAKES = [];
let bg;
function preload() {
bg = loadImage("Images/bg.jpg");
}
function setup() {
createCanvas(600, 600);
noStroke();
for (let l = 0; l < LAYER_COUNT; l++) {
SNOWFLAKES.push([]);
for (let i = 0; i < SNOWFLAKES_PER_LAYER; i++) {
SNOWFLAKES[l].push({
x: random(width),
y: random(height),
mass: random(0.75, 1.25),
l: l + 0
});
}
}
}
function draw() {
background(bg);
// Iterate through each snowflake to draw and update them
for (let l = 0; l < SNOWFLAKES.length; l++) {
const LAYER = SNOWFLAKES[l];
for (let i = 0; i < LAYER.length; i++) {
const snowflake = LAYER[i];
circle(snowflake.x, snowflake.y, (snowflake.l * MAX_SIZE) / LAYER_COUNT);
updateSnowflake(snowflake);
}
}
}
function updateSnowflake(snowflake) {
const diameter = (snowflake.l * MAX_SIZE) / LAYER_COUNT;
if (snowflake.y > height + diameter) snowflake.y = -diameter;
else snowflake.y += GRAVITY * snowflake.l * snowflake.mass;
}