// CatMouse
// Dave Bollinger, Feb 2006
// http://www.davebollinger.com
// (updated for Processing 0123 Beta, Dec 2006)
/**
CatMouse
an experiment in topological biology
Click and drag to rotate
Press 'a' to toggle auto-rotate
*/
int N = 30; // mesh resolution (# rows/cols to subdivide texture into)
float [][] bris; // precalculated brightness from texture image at mesh resolution
float M = N / 2.0f; // half of N
float SCALE = 200.0 / N; // overall scaling of coordinates to fit display
float origin = (-M + 0.5) * SCALE; // the upper-left coord of scaled mesh
float zFactor = 1.000001f; // z-scaling factor
float zFactorDelta = 2.0f; // change in z-scaling factor per frame
float zFactorMin = -200.0; // min value for z-scaling factor
float zFactorMax = 200.0; // max value for z-scaling factor
float ctrx, ctry; // screen center
PImage tex; // texture image
PImage bmp; // bump image
float du, dv; // texture coordinate deltas
Rotor rotx, roty; // rotation
boolean autoRotate = false;
void setup() {
size(300, 300, P3D);
noStroke();
tex = loadImage("fasa100.jpg");
bmp = loadImage("heights.jpg");
du = float(tex.width-1) / float(N);
dv = float(tex.height-1) / float(N);
bris = new float[N+1][N+1];
int x, y;
float u,v;
for (y=0, v=0.0f; y<=N; y++, v+=dv)
for (x=0, u=0.0f; x<=N; x++, u+=du)
bris[y][x] = brightness(bmp.get(int(u),int(v))) / 255.0f - 0.5f;
ctrx = width / 2.0f;
ctry = height / 2.0f;
rotx = new Rotor(0.3, 0.1);
roty = new Rotor(0.0, 0.1);
}
void keyPressed() {
if (key=='a') autoRotate = !autoRotate;
}
void draw() {
if (mousePressed) {
rotx.impulse((pmouseY-mouseY)*0.001);
roty.impulse((mouseX-pmouseX)*0.001);
}
if (autoRotate) {
rotx.impulse(0.001);
roty.impulse(0.001);
}
rotx.update();
roty.update();
background(0);
translate(ctrx, ctry, 0);
directionalLight(255, 255, 255, 0.5, 0.5, -0.5);
directionalLight(255, 255, 255, 0.5, 0.5, -0.5);
rotateX(rotx.pos);
rotateY(roty.pos);
drawMesh();
zFactor += zFactorDelta;
if ((zFactor < zFactorMin) || (zFactor > zFactorMax)) {
zFactor -= zFactorDelta;
zFactorDelta = -zFactorDelta;
}
}
void drawMesh() {
int x, y;
float tx,ty,u,v;
for (y=0, ty=origin, v=0.0f; y