// Magnattractor
// Dave Bollinger, August 2006
// http://www.davebollinger.com
// for Processing 0109 Beta
/**
Press 'c' to toggle color/monochrome mode.
Click mouse to advance to next set of parameters.
*/
AttractorSystem attsys;
int nframes;
boolean bColorMode = true;
void setup() {
size(300,300,P3D);
framerate(30);
colorMode(HSB);
attsys = new AttractorSystem(10);
next();
}
void next() {
background(#ffffff);
attsys.create();
nframes = 0;
}
void draw() {
attsys.iterate(5,50,500);
if (++nframes > 1000)
next();
}
void keyPressed() {
if (key=='`') saveFrame("frame.tga");
if (key=='c') {
bColorMode = !bColorMode;
if (bColorMode) {
colorMode(HSB);
// let individual points set stroke color
} else {
colorMode(RGB);
// set global stroke color
stroke( color(0,0,0,8) );
}
}
}
void mousePressed() {
next();
}
/*
*
* AttractorSystem
* consists of an attractor and a control point
*
*/
class AttractorSystem {
Attractor at;
ControlPoint cp;
Extent ex;
AttractorSystem(int nm) {
at = new Attractor(nm);
cp = new ControlPoint();
ex = new Extent();
}
void create() {
do {
at.create();
estimate(10,10,100);
} while (!valid());
}
// determine approximate extent of system
void estimate(int ncp, int nprime, int niters) {
ex.untrack();
for (int i=0; i maxx) maxx = x;
if (y < miny) miny = y;
if (y > maxy) maxy = y;
*/
/* soft track: */
if (x < minx) minx += (x-minx) * trackrate;
if (x > maxx) maxx += (x-maxx) * trackrate;
if (y < miny) miny += (y-miny) * trackrate;
if (y > maxy) maxy += (y-maxy) * trackrate;
calc();
}
boolean valid() {
calc();
if ((minx <= -1E4) || (miny <= -1E4)) return false;
if ((maxx >= 1E4) || (maxy >= 1E4)) return false;
return true;
}
}