import java.awt.*; public class NicePanels extends RandomPanels { float nowLH, nowLS, nowLB, nowRH, nowRS, nowRB; float lastLH, lastLS, lastLB, lastRH, lastRS, lastRB; public void init() { leftUpdateFrequency = 250; rightUpdateFrequency = 250; super.init(); lh = (leftGen.next() & 0xff)/ (float)255.0; ls = (leftGen.next() & 0xff) / (float)255.0; lb = (leftGen.next() & 0xff) / (float)255.0; rh = (rightGen.next() & 0xff)/ (float)255.0; rs = (rightGen.next() & 0xff) / (float)255.0; rb = (rightGen.next() & 0xff) / (float)255.0; } // doesn't call superclass method - cut and paste stuff. // every frame, check to see if we should rerandomize a side // move each side closer to the colour it wants to be public void doFrame() { redrawLeft = true; redrawRight = true; int leftPhase = frameNumber % leftUpdateFrequency; if (leftPhase == 0) updateLeft(); float t = (float)leftPhase / leftUpdateFrequency; // how far are we? // move closer to desired value lh = lastLH * (1-t) + nowLH * t; ls = lastLS * (1-t) + nowLS * t; lb = lastLB * (1-t) + nowLB * t; leftColor = Color.getHSBColor(lh, ls, lb); int rightPhase = frameNumber % rightUpdateFrequency; if (rightPhase == 0) updateRight(); t = (float)rightPhase / rightUpdateFrequency; // how far are we? // move closer to desired value rh = lastRH * (1-t) + nowRH * t; rs = lastRS * (1-t) + nowRS * t; rb = lastRB * (1-t) + nowRB * t; rightColor = Color.getHSBColor(rh, rs, rb); redrawImage(); } // this doesn't call superclass methods - cut and paste some code in // we avoid setting the colour directly here. // new colour is random hue, but saturation and brightness are set // near to what the other one is currently at (with some randomness) public void updateLeft() { redrawLeft = true; lastLH = lh; lastLS = ls; lastLB = lb; nowLH = (leftGen.next() & 0xff) / (float)255.0; nowLS = (leftGen.next() & 0xff) / (float)255.0; nowLB = (leftGen.next() & 0xff) / (float)255.0; nowLS = (5*rs + nowLS) / 6; nowLB = (5*rb + nowLB) / 6; leftNumber = (int)Math.round(nowLH * 255); if (leftNumber > 255) leftNumber = 255; } public void updateRight() { redrawRight = true; lastRH = rh; lastRS = rs; lastRB = rb; nowRH = (rightGen.next() & 0xff)/ (float)255.0; nowRS = (rightGen.next() & 0xff) / (float)255.0; nowRB = (rightGen.next() & 0xff) / (float)255.0; nowRS = (nowRS + 5*ls) / 6; nowRB = (nowRB + 5*lb) / 6; rightNumber = (int)Math.round(nowRH * 255); if (rightNumber > 255) rightNumber = 255; } }