class Fire { float x, y; float vx, vy; /*Flake(float xpos, float ypos, float velx, float vely, int ittl, int ir, int ig, int ib) { r = ir; g = ig; b = ib; x = xpos; y = ypos; vx = velx; vy = vely; ttl = ittl; }*/ } class Firework { float x, y; int r, g, b; int ttl; Fire[] children; } class FireworksShow { int w, h; Firework[] works; int newest; FireworksShow(int wi, int hi) { w = wi; h = hi; works = new Firework[10]; newest = 0; } void Draw(float xpos, float ypos, int s) { int rand = int(random(w*s)); if (works[newest] == null) { if (rand % 50 == 0) { Firework r = new Firework(); r.x = rand; r.y = h*s; r.ttl = int(random(20,50)); r.children = null; r.r = int(100 + random(0,150)); r.g = int(100 + random(0,150)); r.b = int(100 + random(0,150)); works[newest] = r; newest = (newest + 1) % works.length; println("created new"); } } for (int i = 0; i < works.length; i++) { rand = int(random(w)); if (works[i] != null) { //println("in"); stroke(works[i].r, works[i].g, works[i].b); fill(works[i].r, works[i].g, works[i].b); if (works[i].children != null) { works[i].ttl--; for (int j = 0; j < works[i].children.length; j++) { if (works[i].children[j].x < 3*s) continue; if (works[i].children[j].x > (w-3)*s) continue; if (works[i].children[j].y > (h - 5)*s) continue; works[i].children[j].x += works[i].children[j].vx; works[i].children[j].y += works[i].children[j].vy; works[i].children[j].vy += .01; if (works[i].children[j].y < 3*s) continue; rect(xpos + works[i].children[j].x, ypos + works[i].children[j].y, s, s); // println("e"); } if (works[i].ttl < 0) works[i] = null; } else { works[i].y -= 3; works[i].ttl--; if (works[i].ttl < 0) { works[i].children = new Fire[30]; float ang = 0; works[i].ttl = 200; for (int j = 0; j < works[i].children.length; j++) { ang = 360.0 * j / float(works[i].children.length); works[i].children[j] = new Fire(); works[i].children[j].x = works[i].x; works[i].children[j].y = works[i].y; works[i].children[j].vx = cos(ang); works[i].children[j].vy = sin(ang); } } rect(xpos + works[i].x, ypos + works[i].y, s, s); // println("a"); } //println( (xpos + works[i].x) + ", " + (ypos + works[i].y) ); } } /* for (int i = 0; i < flakes.length; i++) { rand = int(random(w)); if (flakes[i] != null) { if (random(1) > .5) { flakes[i].y += rand % 2; flakes[i].vx += (rand % 3) - 1; if (flakes[i].vx > 5) flakes[i].vx = 5; if (flakes[i].vx < -5) flakes[i].vx = -5; flakes[i].x += flakes[i].vx * .2; if (flakes[i].x < 3*s) flakes[i].x = 3*s; if (flakes[i].x > (w-3)*s) flakes[i].x = (w-3)*s; } PImage type = types[flakes[i].t]; image(type, xpos + flakes[i].x, ypos + flakes[i].y, type.width*s, type.height*s); if (flakes[i].y > (h - 10 + flakes[i].depth)*s) { //bg.beginDraw(); //bg.image(type, flakes[i].x/s, flakes[i].y/s); //bg.endDraw(); flakes[i] = null; } } }*/ } }