// import processing.opengl.*; // library for easy manipulation of cameras // The Obsessive Camera Direction // by Kristian Linn Damkjer // !! you need to download it to run this code !! // find link at http://www.processing.org/reference/libraries/index.html import damkjer.ocd.*; // create camera from OCD library Camera camera1; // max nodes, 25*25 for example int nodeAmount = 625; // nodes array: x,y,z,force float[][] nodes = new float[int(nodeAmount)][4]; // rotationZ float[] rotationY = new float[int(nodeAmount)]; // rotationZ Target float[] rotationTargetY = new float[int(nodeAmount)]; // counter for timing int timingCounter = 0; int timingCounterSpeed = 1; float rotationCounter = 0.0; // String displayAnimation = "noise"; // image loading setup PImage a; PImage b; int imageSize = 25; int[][] aPixels; int currentImage = 1; int maxImage = 20; String animation = "count"; int frameRate = 1; // perlin noise setup int noiseDepth = 1; // setup *********************************************************************************** void setup() { size(800, 600, P3D); colorMode(HSB, 100); framerate(25); generateNodes(); // smooth(); // little buggy camera constructor from OCD library camera1 = new Camera(this, 10.0, -60.0, 0.0, 78.0, 20.0, 60.0, 0.0, 1.0, 0.0, radians(PI/7), (width/height), 1.0, 1000.0); camera1.zoom(radians(130) / 2.0); b = loadImage("background.jpg"); } // main method *********************************************************************************** void draw() { background(30,50,0); // background(b); camera1.feed(); //lights(); drawNodes(); iterateRotation(); keyboardListener(); cameraNavigation(); // timing timingCounter += 1; if (timingCounter>timingCounterSpeed){ timingCounter = 0; if (displayAnimation == "images"){ loadMyImage(); displayMyImage(); } else if (displayAnimation == "noise"){ displayPerlinNoise(); } } } // generate data *********************************************************************************** void generateNodes() { float x = 0; float y = 0; float z = 0; int j=0; for (int i=0; i24) { j = 0; x = 0; z += 6; } float humanizer = (random(10)-5)/20; x += 6+humanizer; z += humanizer; nodes[i][0] = x; nodes[i][1] = y; nodes[i][2] = z; // and force nodes[i][3] = 0; rotationY[i] = radians(random(360)); rotationTargetY[i] = radians(random(360)); } } // Calculate forces ********************************************************************************************* void iterateRotation(){ for(int i=0; i 9){ zeros = "00"; } if (currentImage > 99){ zeros = "0"; } a = loadImage(animation+zeros+currentImage+".gif"); for(int i=0; i maxImage){ currentImage = 1; if (animation == "count"){ animation = "ripple"; } else if (animation == "ripple"){ animation = "rotation"; } else if (animation == "rotation"){ animation = "hand"; frameRate = 5; maxImage = 128; } else if (animation == "hand"){ animation = "count"; frameRate = 1; maxImage = 20; } } } void displayMyImage(){ float rr, gg, bb, tt; for(int i=0; i0){ nodes[(i*imageSize)+j+fix][3] = tt-50; } } } } // perlin noise void displayPerlinNoise(){ float noiseScale=0.03; noiseDepth += 1; for(int i=0; i0){ nodes[(i*imageSize)+j][3] = noise(i*noiseScale, j*noiseScale, noiseDepth*noiseScale*2)*3000; } } } } // keyboardListener *************************************************************************************************************** void keyboardListener(){ if(keyPressed) { if(key == 'r' || key == 'R') { randomForces(); } if(key == 's' || key == 'S') { resetForces(); } if(key == 'p' || key == 'P') { patternForces(); } if(key == 'i' || key == 'I') { loadMyImage(); displayMyImage(); } // looping content switches if(key == 'a' || key == 'A') { displayAnimation = "images"; timingCounterSpeed = 5; } if(key == 'n' || key == 'N') { displayAnimation = "noise"; timingCounterSpeed = 1; } } } // 3d navigation *************************************************************************************************************** void cameraNavigation() { if (!mousePressed){ // } else if (mouseButton == LEFT) { camera1.circle(radians(mouseX - pmouseX) / -2.0); camera1.arc(radians(mouseY - pmouseY) / -2.0); } else if (mouseButton == RIGHT) { camera1.zoom(radians(mouseY - pmouseY) / 2.0); } else if (mouseButton == CENTER) { camera1.look(radians(mouseX - pmouseX) / 6.0, radians(mouseY - pmouseY) / 2.0); } }