//import processing.opengl.*; // // viewport float eyeX = 7; float eyeY = 40; float eyeZ = 33.0; float eyeTargetX = 75.0; float eyeTargetY = 75.0; float eyeTargetZ = 10.0; float eyeDragX; float eyeDragY; float eyeDragZ; float eyeDragRotation; float eyeRotation; int mouseDragX; int mouseDragY; int cycle = 10; boolean dragFlag = false; // max nodes, 25*25 for example int nodeAmount = 624; // nodes array: x,y,z,force float[][] nodes = new float[nodeAmount][4]; // nodesFixed array: x,y,z float[][] nodesFixed = new float[nodeAmount][3]; // nodesTarget array: xtaret,ytarget,ztarget float[][] nodesTarget = new float[nodeAmount][3]; // connections array: node1, node2, orginaldistance float[][] connections = new float[nodeAmount*5][4]; // force memory float[] oldForce = new float[int(nodeAmount)]; // rotation float[] rotationZ = new float[int(nodeAmount)]; // rotation Target float[] rotationTargetZ = new float[int(nodeAmount)]; // casey image example PImage a; int imageSize = 25; int[][] aPixels; int currentImage = 0; int maxImage = 5; void setup() { size(800, 600, P3D); colorMode(HSB, 100); framerate(30); //eyeRotation = PI/3; //eyeX = sin(eyeRotation)*100; //eyeY = cos(eyeRotation)*100; generateNodes(); generateConnections(); //noFill(); perspective(30, float(width)/float(height), 1, 500); setCamera(); } void draw() { background(0,0,0); // if(keyPressed) { if(key == 'r' || key == 'R') { randomForces(); } if(key == 's' || key == 'S') { resetForces(); } if(key == 'c' || key == 'C') { cycleForces(); } if(key == 'p' || key == 'P') { patternForces(); } if(key == 'i' || key == 'I') { loadMyImage(); displayMyImage(); } if((keyCode == UP) || (keyCode == DOWN) || (keyCode == LEFT) || (keyCode == RIGHT)){ moveCamTarget(); } // store until next for (int i=0; i144) && (x%2==0) ) { x = 3; y += sqrt(27)+(random(10)-5)/5; } else if (x>147){ x = 0; y += sqrt(27)+(random(10)-5)/5; } if (false && (y > 20) && ((z/sqrt(27))%2==0) ){ y = -73; z -= sqrt(27); } if (false && (y > 20) && ((z/sqrt(27))%2!=0) ){ y = -70; z -= sqrt(27); } //z = 0; nodes[i][0] = x; nodes[i][1] = y; nodes[i][2] = z; // and force nodes[i][3] = 0; //nodes[i][3] = random(200)-100; // store initial position nodesFixed[i][0] = x; nodesFixed[i][1] = y; nodesFixed[i][2] = z; // store targets nodesTarget[i][0] = x; nodesTarget[i][1] = y; nodesTarget[i][2] = z; } } // data for all connected nodes, with their original distance stored void generateConnections() { int connectionCounter = 0; for (int nodei=0; nodei= nodeAmount-10){ cycle = 10; } } void patternForces(){ float offset = random(20)+1; for (int i=0; i maxImage){ currentImage = 0; } } void displayMyImage(){ float rr, gg, bb, tt; for(int i=0; i0){ nodes[(i*imageSize)+j+fix][3] = tt-50; } } } } // Calculate forces ********************************************************************************************* // iterate a to b with speed void iterate(int a, int b, float speed) { nodesTarget[a][0] -= (nodesTarget[a][0]-nodesTarget[b][0])/speed; nodesTarget[a][1] -= (nodesTarget[a][1]-nodesTarget[b][1])/speed; nodesTarget[a][2] -= (nodesTarget[a][2]-nodesTarget[b][2])/speed; } // iterate a to its origin with speed void stayFixed(int a, float speed) { float offset; offset = ((nodesTarget[a][0]-nodesFixed[a][0])+(nodesTarget[a][1]-nodesFixed[a][1]))/2; nodesTarget[a][0] -= (nodesTarget[a][0]-nodesFixed[a][0])/speed; nodesTarget[a][1] -= (nodesTarget[a][1]-nodesFixed[a][1])/speed; nodesTarget[a][2] -= (nodesTarget[a][2]-(nodesFixed[a][2]-offset))/speed; } // iterate a target values with speed void applyPositions(int a, float speed) { nodes[a][0] -= (nodes[a][0]-nodesTarget[a][0])/speed; nodes[a][1] -= (nodes[a][1]-nodesTarget[a][1])/speed; nodes[a][2] -= (nodes[a][2]-nodesTarget[a][2])/speed; } void followFriend(int a, int b, float defaultDistance, float speed) { defaultDistance = defaultDistance-(nodes[a][3]+nodes[b][3])/2; if (dist(nodes[a][0], nodes[a][1],nodes[a][2],nodes[b][0],nodes[b][1],nodes[b][2])>defaultDistance) { iterate(a, b, speed); iterate(b, a, speed); } } void calcForces(){ for (int j=0; j