23. Dezember 2010
Here is the final result of the Animated Permutation. The program uses the song Straight Heat by Edit (http://www.youtube.com/watch?v=1fcQNCY60vo) which is embedded into the program with the MINIM library. There are a nr. of things you can do with the program. You can Change the direction of shapes with the mouse as well as an override that moves that same shape with the keyboard from left to right (keys "k" & "l"). A inverse function with the keys "1". And a shape gets resized with the "m" and "n" keys. Here is the code and some pictures./* //SIMPLE PERMUTATION //TESTING MOUSE MOVEMENT */ //Initializing Variables int numberPerRow = 7; int rand = 50; float xStep; float yStep; int currentVariation = 2; boolean keyPressed = false; String currentKey; float diameter; float rotation; int fill; float x; float y; float makelarger=0; float zoomsize = 6.3; // Minim Audio import ddf.minim.*; // Minim Audio Buffer Level - Used to evaluate how loud the song is plazing. Returns value between 0-1 import ddf.minim.signals.*; Minim minim; AudioPlayer player; AudioInput input; // The PermutaionsList displays the shapes in the matrix that you see below. Each nr. corresponds to a certain shape. Nr.s correspond to the case 0: nr seen below. // Make Larger is a great value to play with and in some ways erases alot of the other forms depending on which circle gets blown up. int[] permutationsList = { 0, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 5, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 2, 5, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 0 }; void setup() { size(600, 600); // Defines the size of the window smooth(); xStep = (width - 2 * rand) / (float)(numberPerRow-1); yStep = (height - 2 * rand) / (float)(numberPerRow-1); // Start Audio via Minim minim = new Minim(this); player = minim.loadFile("straightheat.mp3"); input = minim.getLineIn(); player.loop(); player.play(); } void draw() { background(255); //background(player.right.level() * 255); scale(zoomsize); int permutationsIndex = 0; pushMatrix(); translate(rand,rand); for(int y=0; y<numberPerRow;y++) { pushMatrix(); for(int x=0; x<numberPerRow;x++) { drawPermutationObj(permutationsList[permutationsIndex], radians(MousePosition(xStep*x, yStep*y)), player.left.level(), makelarger); //drawPermutationObj(permutationsList[permutationsIndex], radians(player.right.level()), player.left.level(), makelarger); ++permutationsIndex; translate(xStep,0.0f); } popMatrix(); translate(0.0f,yStep); } popMatrix(); } /* // Mouse Position */ float MousePosition(float _x, float _y) { float MousePoint = 0; if (keyPressed){ if (currentKey == "k") { MousePoint = 315; } else if (currentKey == "l") { MousePoint = 45; } } else { MousePoint = degrees(atan2(mouseY - _y, mouseX - _x)); // The following if statement is used to make sure that there is no negative value on the mouse position. If the mouse position returned is negative // the statement adds a nr to make the value positive again. if (MousePoint < 0) { if(MousePoint >= -90) { MousePoint = (MousePoint+90); //MousePoint = (MousePoint+120); } else { MousePoint = (MousePoint+450); //MousePoint = (MousePoint+480); } } else { MousePoint = (MousePoint+90); //MousePoint = (MousePoint+120); } } return MousePoint; } void keyReleased() { keyPressed = false; } void keyPressed() { switch(key) { /*case '1': currentVariation = 1; break; */ case '1': if (currentVariation == 1) { currentVariation = 2; } else { currentVariation = 1; } break; case 'm': makelarger += 10; break; case 'n': makelarger -= 10; break; case '0': zoomsize = 6.3; break; case '9': zoomsize = 3; break; case '8': zoomsize = 2; break; case '7': zoomsize = 1; break; case 'k': keyPressed = true; // Radian Position currentKey = "k"; break; case 'l': keyPressed = true; // Radian Position currentKey = "l"; break; } } void drawPermutationObj(int type, float transformation, float levels, float makelarger) { pushMatrix(); rotate(transformation); pushStyle(); switch(type) { case 0: //Program an explode type value that makes the ellipses dissapear off the grid. make one value control that. Try to assign to a knob. if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; case 1: if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; case 2: if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; case 3: if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; case 4: if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; case 5: if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; case 6: if (currentVariation == 1) { stroke(0); fill(0); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(0); ellipse(0,0,45,45); stroke(255); fill(0); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(255); ellipse(0,-10,40,40); stroke(0); fill(0); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } else if (currentVariation == 2) { stroke(0); fill(255); ellipse(0,0,75,75); stroke(255); fill(255*levels); ellipse(0,-10,55,55); stroke(0); fill(255); ellipse(0,0,45,45); stroke(255); fill(255); ellipse(0,0,46+makelarger,46+makelarger); stroke(0); fill(0); ellipse(0,-10,40,40); stroke(0); fill(255); ellipse(0,-10,25,25); stroke(255); fill(255*levels); ellipse(0,15,15,15); } break; default: break; } popStyle(); popMatrix(); }