/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://cst1101.sketchpad.cc/sp/pad/view/ro.qEP4znegYGv/rev.64
*
* authors:
* Kathia Garcia
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// press 'S' or 's' to stop snow
// mousepressed for black background
/* @pjs preload="/static/uploaded_resources/p.3301/snowyNight.jpg"; */
PImage snowyNight= loadImage("/static/uploaded_resources/p.3301/snowyNight.jpg");
Snow [] lot; // array called lot of "Snow"
void setup() {
lot = new Snow[300]; // makes space for 300
size(600, 600);
for (int i = 0; i < lot.length; i++) {
lot[i] = new Snow(color(255), random(0, width), i*2, i/150.0, 5);
}
}
void draw() {
image(snowyNight, 0, 0, 600, 600);
fill(255);
for (int i = 0; i < lot.length; i++) {
lot[i].display();
lot[i].snowing();
}
}
//------------------------- SNOW CLASS ----------------------------
class Snow {
color snowColor; // data
float snowX;
float snowY;
float snowSpeed;
int snowSize;
Snow(color snowColor_, float snowX_, float snowY_, float snowSpeed_, int snowSize_) { // constructor
snowColor = snowColor_;
snowX = snowX_;
snowY = snowY_;
snowSpeed = snowSpeed_;
snowSize = snowSize_;
}
void snowing() { // snow moving
snowY = snowY + snowSpeed;
if (snowY > height) {
snowY = 0;
}
if
(key == 'S' || key == 's' ) { //stops snowing
snowY = snowY - snowSpeed;
}
}
void display() { // defines the snow
if (mousePressed) {
background(0);
}
else {// shows
fill(snowColor);
stroke(255);
ellipse(snowX, snowY, snowSize, snowSize);
}
}
}