diff --git a/Code/Snowflake.js b/Code/Snowflake.js new file mode 100644 index 0000000000000000000000000000000000000000..766a5471c32c807ed304974f0309517fda7e6355 --- /dev/null +++ b/Code/Snowflake.js @@ -0,0 +1,77 @@ +function getRandomSize(){ + +let r = pow(random(0, 1), 5); +return constrain(r * 36, 2, 36); + + +//let r = randomGaussian() * 2; +//return constrain(abs(r * r), 2 , 36); +//while (true){ + //let r1 = random(1); + //let r2 = random(1); + //if (r2 > r1) { + //return r1 * 36; + //} + //} +} + +class Snowflake { + + constructor() { + let x = random(width); + let y = random(-100, -10); + this.pos = createVector(x, y); + this.vel = createVector(0, 0); + this.acc = createVector(); + this.r = getRandomSize(); + } + +applyForce(force){ + //Parallax Effect hack + let f = force.copy(); + f.mult(this.r); + + + //let f = force.copy(); + //f.div(this.mass); + this.acc.add(f); +} + +randomize(){ + let x = random(width); + let y = random(-100, -10); + this.pos = createVector(x, y); + this.vel = createVector(0, 0); + this.acc = createVector(); + this.r = getRandomSize(); +} + + update() { + + this.vel.add(this.acc); + this.vel.limit(this.r * 0.2); + +if (this.vel.mag()<1) { + this.vel.normalize(); +} + +this.pos.add(this.vel); + this.acc.mult(1); + + if (this.pos.y > height + this.r) { + this.randomize(); + } + } + //this is a funtion that + render() { + stroke(255); + image(snowImage,this.pos.x,this.pos.y,this.r,this.r); + strokeWeight(this.r); + + } + +//offScreen(){ +// return(this.pos.y > height + this.i); +// + +}