12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- int rate = 7;
- int tickMS = rate;
- int previous_stars = 0;
- int time_stars = 0;
-
- int rate2 = 1800;
- int tickMS2 = rate;
- int previous_stars2 = 0;
- int time_stars2 = 0;
-
- int starRadius = 20;
- Star stars[] = new Star[1000];
- Star stars2[] = new Star[1000];
-
- void paintStars() {
- int current = millis();
- int elapsed = current - previous_stars;
- previous_stars = current;
- time_stars += elapsed;
- while(time_stars >= tickMS){
- time_stars -= tickMS;
- stars[(int)random(stars.length)].go();
- tickMS = int(random(rate/100,2*rate-(rate/100)));
- }
-
- if (stars.length > 0) {
- for (int i = stars.length-1; i > 0; i--) {
- if(stars[i].alive){
- stars[i].display();
- }
- }
- }
- }
-
- void paintStars2() {
- int current = millis();
- int elapsed = current - previous_stars2;
- previous_stars2 = current;
- time_stars2 += elapsed;
- while(time_stars2 >= tickMS2){
- time_stars2 -= tickMS2;
- stars2[(int)random(stars.length)].go();
- tickMS2 = int(random(rate2/100,2*rate2-(rate/100)));
- }
-
- if (stars2.length > 0) {
- for (int i = stars2.length-1; i > 0; i--) {
- if(stars2[i].alive){
- stars2[i].display();
- }
- }
- }
- }
-
-
-
- class Star {
- int x, y, init;
- int radius, bjitter, b;
- int lifetime = 3600;
- boolean alive;
- PGraphics pg;
- Star(PGraphics pg_) {
- pg = pg_;
- }
- void go(){
- alive = true;
- x = (int)random(0,270);
- y = (int)random(0,270);
- init = millis();
- b = 255;
- bjitter = (int)random(-50, 50);
- radius = starRadius;
- }
- void display() {
- b -= 10;
- pg.fill(255, b);
- pg.ellipse(x, y, radius, radius);
- radius -= .5;
-
- if (init + lifetime < millis()) {
- alive = false;
- }
- }
- }
|