public class Window { public Window(float _size[], float _pos[], boolean _yrot, color _color) { set(_size, _pos, _yrot, _color); } public void set(float _size[], float _pos[], boolean _yrot, color _color) { size = new float[2]; pos = new float[3]; System.arraycopy(_size, 0, size, 0, 2); System.arraycopy(_pos, 0, pos, 0, 3); yrot = _yrot; col = _color; acol = col; g= new Glow[3]; for(int i=0; i <3; ++i) g[i]=new Glow(); } public void set_color(color _color) { col = _color; //if(!gstarted) acol = col; } public boolean draw() { fill(acol); if(yrot) { vertex(pos[0], pos[1], pos[2]); vertex(pos[0], pos[1] + size[0], pos[2]); vertex(pos[0], pos[1] + size[0], pos[2] + size[1]); vertex(pos[0], pos[1], pos[2] + size[1]); } else { vertex(pos[0], pos[1], pos[2]); vertex(pos[0] + size[0], pos[1], pos[2]); vertex(pos[0] + size[0], pos[1], pos[2] + size[1]); vertex(pos[0], pos[1], pos[2] + size[1]); } return true; } public void glow(color col, float intensity, float t, float t100, int i) { g[i%3].start(col, intensity, t, t100); } public void stopglow(int i) { g[i%3].stop(); } public void updglow(boolean pause) { color cb = 0; color c[] = new color[3]; for(int i=0; i<3; ++i) { c[i] = g[i].update(pause); } if(alpha(c[0]) > 0 && alpha(c[0]) > 0) cb = blendColor(c[0],c[1],BLEND); else if(alpha(c[0]) == 0) cb = c[1]; else if(alpha(c[1]) == 0) cb = c[0]; if (alpha(c[2]) > 0) cb = blendColor(c[2],cb,BLEND); acol = blendColor(col, cb, BLEND); acol = color(red(acol), green(acol), blue(acol), 255); //acol = color(red(col)*(1.0-p)+red(gcol)*p,green(col)*(1.0-p)+green(gcol)*p,blue(col)*(1.0-p)+blue(gcol)*p); //acol = blendColor(color(red(col),green(col), blue(col), (1.0-p)*255), color(red(gcol),green(gcol), blue(gcol), (p)*255), BLEND); //acol = color(red(acol), green(acol), blue(acol), 255); } private float size[]; private float pos[]; private boolean yrot; private color col; private color acol; private Glow g[]; class Glow { Glow() { gstarted = false; } public void start(color col, float intensity, float t, float t100) { if(gstarted) return; gstarted = true; gstartt = frameCount; gt = int(frameRate * t + .5); gendt = frameCount + gt; gcol = col; gint = intensity; gt100 = int(t100 * frameRate + 0.5); if(2*gt100 > gt) gt100 = gt/2; if(gint > 1.0) gint = 1.0; } public void stop() { gstarted = false; } public color update(boolean pause) { if(pause) { gendt++; gstartt++; return lcol; } if(!gstarted) { lcol = 0; return 0; } if(frameCount > gendt) { gstarted = false; lcol = 0; return 0; } int dt = frameCount - gstartt; if(dt < gt100 || dt > gt - gt100) { float p; if(dt < gt100) { p = float(dt) / float(gt100) * gint; } else { p = float(dt - gt + gt100) / float(gt100) * gint; p = gint - p; } lcol = color(red(gcol),green(gcol), blue(gcol), (p)*255); return lcol; } lcol = color(red(gcol),green(gcol), blue(gcol), gint*255); return lcol; } private boolean gstarted; private int gstartt; private int gendt; private int gt; private int gt100; private color gcol, lcol; private float gint; } }