// Log Starburst // - Jim Bumgardner, Ryan Govostoes // using a formula from Bumgardner's "Pixel Magic" - 1992. // History // 2/19/06 jbum - added mousePressed behavior ( swaps between RGB, HSB) // - removed use of int() for dMult in mouseMoved, added constrain() // - changed && to || in table generation // - modified g channel to use time cycle for a little more color variation // - removed +90 in a couple spots - not really necessary // - changed direction of dtable float sineTable[]; float dTable[]; float aTable[]; // float p = 0; - jbum switched to time-based float dMult = 2; float aMult = 2; int cMode = RGB; void setup() { size(300, 300, P2D); colorMode(cMode, 2); // precalculate 1 period of the sine wave (360 degrees) sineTable = new float[360]; for (int i = 0; i < 360; i ++) sineTable[i] = sin(radians(i)); // precalculate polar coords dTable = new float[width * height]; aTable = new float[width * height]; float cx = width / 2; float cy = height / 2; int i = 0; for (int y = 0; y < height; y ++) { for (int x = 0; x < width; x ++) { if (x != cx || y != cy) { // jbum 2/19/04 - changed && to || dTable[i] = 359-posDegrees( 0.5 * log(sq(x - cx) + sq(y - cy)) ); // jbum - changed direction aTable[i] = posDegrees( atan2(y - cy, x - cx) ); // jbum removed + 90; } i ++; } } } void draw() { loadPixels(); // 2/19/06 jbum = switch to time based // p += 11.459156; // 2 * 0.1 * degrees(1) float tb = millis()*.2; float tg = tb*.25; for(int i = 0; i < (width * height); i ++) { float a = sineTable[(int)(aTable[i] * aMult) % 360]; float da = dTable[i] * dMult + aTable[i]; // jbum - removed + 90; float r = 1 + a * sineTable[(int)da % 360]; // float g = 2 - r; float g = 1 + a * sineTable[(int)(da + tg) % 360]; // jbum float b = 1 + a * sineTable[(int)(da + tb) % 360]; pixels[i] = color(r, g, b); } updatePixels(); fpscalc(); } void mouseMoved() { // jbum 2/19/06 changed to use constrain aMult = (int) constrain(mouseX * 32 / width, 1, 32); dMult = constrain(mouseY * 32 / width, .1, 32); // jbum 2/19/06 this does not need to be an integer } // jbum 2/19/06 added mousepressed behavior void mousePressed() { cMode = (cMode == RGB? HSB : RGB); colorMode(cMode, 2); } float fps; int fpsN; void fpscalc() { fps += framerate; fpsN ++; if((fpsN % 60) == 0) print((fps / fpsN) + " "); } float posDegrees(float rad) { float deg = degrees(rad) % 360; if(deg < 0) deg += 360; return deg; }