// SteelWool01
// David Bollinger
// http://www.davebollinger.com
// for Processing 0109 Beta
/**
Click to advance to next pattern.
*/
FixedPointBuffer buf;
Attractor attractor;
ParticleTrail [] trails;
int currentseed = 0;
int nframes;
int ntrails = 3;
int partiespertrail = 100;
int itersperframe = 10;
int framestillnext = 500;
void setup() {
size(480,480,P3D);
buf = new FixedPointBuffer(width,height);
attractor = new Attractor();
trails = new ParticleTrail[ntrails];
for (int i=0; i framestillnext)
next();
}
void next() {
randomSeed(currentseed++);
attractor.make();
for (int i=0; i=wid-1.0) || (y>=hei-1.0)) return;
// integral coordinates
int ix1 = (int)(x);
int iy1 = (int)(y);
int ix2 = ix1 + 1;
int iy2 = iy1 + 1;
// fractional coordinates
float fractx = x - (float)(ix1);
float fracty = y - (float)(iy1);
// reciprocal of fractional coordinates
float recipx = 1.0 - fractx;
float recipy = 1.0 - fracty;
// preconvert color values to floats
float fr = (float)(curred);
float fg = (float)(curgrn);
float fb = (float)(curblu);
// plot it
float ratio;
int idx, c;
// upper-left
ratio = recipx * recipy * curalf;
idx = iy1 * width + ix1;
c = (int)((ratio*fr) + redbuf[idx]); if (c>maxrgb) c=maxrgb; redbuf[idx] = c;
c = (int)((ratio*fg) + grnbuf[idx]); if (c>maxrgb) c=maxrgb; grnbuf[idx] = c;
c = (int)((ratio*fb) + blubuf[idx]); if (c>maxrgb) c=maxrgb; blubuf[idx] = c;
// upper-right
ratio = fractx * recipy * curalf;
idx = iy1 * width + ix2;
c = (int)((ratio*fr) + redbuf[idx]); if (c>maxrgb) c=maxrgb; redbuf[idx] = c;
c = (int)((ratio*fg) + grnbuf[idx]); if (c>maxrgb) c=maxrgb; grnbuf[idx] = c;
c = (int)((ratio*fb) + blubuf[idx]); if (c>maxrgb) c=maxrgb; blubuf[idx] = c;
// lower-left
ratio = recipx * fracty * curalf;
idx = iy2 * width + ix1;
c = (int)((ratio*fr) + redbuf[idx]); if (c>maxrgb) c=maxrgb; redbuf[idx] = c;
c = (int)((ratio*fg) + grnbuf[idx]); if (c>maxrgb) c=maxrgb; grnbuf[idx] = c;
c = (int)((ratio*fb) + blubuf[idx]); if (c>maxrgb) c=maxrgb; blubuf[idx] = c;
// lower-right
ratio = fractx * fracty * curalf;
idx = iy2 * width + ix2;
c = (int)((ratio*fr) + redbuf[idx]); if (c>maxrgb) c=maxrgb; redbuf[idx] = c;
c = (int)((ratio*fg) + grnbuf[idx]); if (c>maxrgb) c=maxrgb; grnbuf[idx] = c;
c = (int)((ratio*fb) + blubuf[idx]); if (c>maxrgb) c=maxrgb; blubuf[idx] = c;
}
// render converts 8.shift format back down to 8 bit rgb
void render() {
for (int idx=area-1; idx>=0; idx--) {
pixels[idx] = 0xFF000000 |
(redbuf[idx] & 0xFF0000) |
((grnbuf[idx] & 0xFF0000) >> 8) |
((blubuf[idx] & 0xFF0000) >> 16);
}
updatePixels();
}
}