Speed parameters stipulated in class not being applied
- int savedTime;
- int totalTime = 60000;
- int passedTime;
- int num_drops1 = 4;
- int num_drops2 = 16;
- int num_drops3 = 32;
- int num_drops4 = 64;
- int num_drops5 = 128;
- int num_drops6 = 246;
- int num_drops7 = 400;
- void setup()
- {
- size(500, 500);
- smooth();
- noStroke();
- savedTime = millis();
- }
- void draw() {
- background(0);
- passedTime = millis() - savedTime;
- if (passedTime <= 7500) {
- rain1();
- }
- else if ((passedTime <= 15000) && (passedTime > 7500)) {
- rain2();
- }
- else if ((passedTime <= 22500) && (passedTime > 15000)) {
- rain3();
- }
- else if ((passedTime <= 30000) && (passedTime > 22500)) {
- rain4();
- }
- else if ((passedTime <= 37500) && (passedTime > 30000)) {
- rain5();
- }
- else if ((passedTime <= 45000) && (passedTime > 37500)) {
- rain6();
- }
- else if ((passedTime <= 60000) && (passedTime > 45000)) {
- rain1();
- }
- else {
- stop();
- savedTime = millis(); // Save the current time to restart the timer!
- }
- println (passedTime + " ") ;
- }
- ////////////////////////////////// RAIN FUNCTION //////////////////////////////////
- void rain1() {
- Drop[] myDrops = new Drop[num_drops1];
- for (int i = 0; i<num_drops1; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops1; i++)
- {
- myDrops[i].update();
- }
- }
- }
- void rain2() {
- Drop[] myDrops = new Drop[num_drops2];
- for (int i = 0; i<num_drops2; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops2; i++)
- {
- myDrops[i].update();
- }
- }
- }
- void rain3() {
- Drop[] myDrops = new Drop[num_drops3];
- for (int i = 0; i<num_drops3; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops3; i++)
- {
- myDrops[i].update();
- }
- }
- }
- void rain4() {
- Drop[] myDrops = new Drop[num_drops4];
- for (int i = 0; i<num_drops4; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops4; i++)
- {
- myDrops[i].update();
- }
- }
- }
- void rain5() {
- Drop[] myDrops = new Drop[num_drops5];
- for (int i = 0; i<num_drops5; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops5; i++)
- {
- myDrops[i].update();
- }
- }
- }
- void rain6() {
- Drop[] myDrops = new Drop[num_drops6];
- for (int i = 0; i<num_drops6; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops6; i++)
- {
- myDrops[i].update();
- }
- }
- }
- void rain7() {
- Drop[] myDrops = new Drop[num_drops7];
- for (int i = 0; i<num_drops7; i++)
- {
- myDrops[i] = new Drop();
- myDrops[i].posX = random(0, width);
- myDrops[i].posY = random(0, height);
- myDrops[i].speedX = random(0, 3);
- }
- if (passedTime < totalTime) {
- for (int i = 0; i<num_drops7; i++)
- {
- myDrops[i].update();
- }
- }
- }
- ////////////////////////////////// RAIN CLASS ///////////////////////////////////////
- class Drop
- {
- //properties
- int myDiameter = 4;
- float posX = 250;
- float posY = 250;
- float speedX = 0.1;
- float speedY = 0;
- float gravity = 0.05;
- //method
- void update()
- {
- //ellipse(posX, posY, myDiameter, myDiameter);
- fill(#62B7FF, 200);
- ellipse(posY, posX, myDiameter, myDiameter);
- posX += speedX + 0.01;
- speedX = speedX + gravity;
- if (posX > width)
- {
- posX = 0;
- speedX = speedX*-.10;
- }
- }
- }
- ////////////////////////////////// END RAIN CLASS ///////////////////////////////////