xxxxxxxxxx
44
let snow = [];
let gravity;
let zOff = 0;
let textures = [];
function getRandomSnowflake(){
return random(textures);
}
function preload(){
for(let i = 0; i <= 50; i++){
textures.push(getSnowflake());
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
gravity = createVector(0,0.3);
for(let i = 0; i < 1000; i++){
snow.push(new Snowflake());
}
}
function draw() {
background(0);
zOff += 0.05;
for(let flake of snow){
let xOff = flake.pos.x / width;
let yOff = flake.pos.y / height;
let wAngle = noise(xOff,yOff,zOff) * TWO_PI
let wind = p5.Vector.fromAngle(wAngle);
wind.mult(0.1);
flake.applyForce(gravity);
flake.applyForce(wind);
flake.update();
flake.draw();
}
}