25. November 2010
Bewege die Maus über die Fläche um die Objekte zu vergrössern./* * PERMUTATION 1 - Mouse Interaction * by Joel Gähwiler */ //Settings int anzahl = 7; int rand = 50; //Holders float xStep; float yStep; //Permutaion Array int[] permutationsIndexList = {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}; //SetUp Cycle void setup() { //Set Size & Smooth size(600, 600); smooth(); //Calculte xStep xStep = (width - 2 * rand) / (float)(anzahl-1); yStep = (height - 2 * rand) / (float)(anzahl-1); //Set FrameRate frameRate(10); } //Draw Cycle void draw() { //Clear Screen background(255); //Start at Permutation Index Zero int permutationsIndex = 0; //Set MidPoint to FirstSquare translate(rand,rand); //Loop Rows for(int y=0; y<anzahl;y++) { //Get a new Cordinate System pushMatrix(); //Loop Columns for(int x=0; x<anzahl;x++) { //Get Type form Permutations Array int objType = permutationsIndexList[permutationsIndex]; //Set Default Object Scale float objScale = 1; //Get Object Position in Fields PVector posObject = new PVector(x, y, 0); //Get Mouse Position in Fields PVector posMouse = new PVector(map(mouseX, 0, width, 0, 6), map(mouseY, 0, height, 0, 6)); //Calculate Distance float distance = posObject.dist(posMouse); //Map Distance to Type objType = (int)map(distance, 0, sqrt(72), 0, 6); //Map Distance to Scale objScale = map(distance,0, sqrt(72), 1, 0); //Draw Object drawPermutationObj(objType,objScale); //Increment Permutation Index ++permutationsIndex; //Go to next Column translate(xStep,0.0f); } //Close Cordinate System popMatrix(); //Go To Next Row translate(0.0f,yStep); } } //Draw an Object void drawPermutationObj(int type,float objScale) { //Get New Cordinate Syste & Style pushMatrix(); pushStyle(); //Set Scale scale(objScale); //Hintergrundkreis noStroke(); fill(0); ellipse(0,0,75,75); //Draw Object depending on Type switch(type) { case 0: //Ring 1 fill(255); ellipse(6.6,-6.6,70,70); //Ring 2 fill(0); ellipse(6.6,-6.6,60,60); //Inner fill(255); ellipse(3.3,-3.3,35,35); break; case 1: //Ring 1 fill(255); ellipse(3.3,-3.3,65,65); //Ring 2 fill(0); ellipse(3.3,-3.3,55,55); //Inner fill(255); ellipse(0,0,32.5,32.5); break; case 2: //Ring 1 fill(255); ellipse(0,0,60,60); //Ring 2 fill(0); ellipse(0,0,50,50); //Inner fill(255); ellipse(-3.3,3.3,30,30); break; case 3: //Ring 1 fill(255); ellipse(-3.3,3.3,55,55); //Ring 2 fill(0); ellipse(-3.3,3.3,45,45); //Inner fill(255); ellipse(-6.6,6.6,27.5,27.5); break; case 4: //Ring 1 fill(255); ellipse(-6.6,6.6,50,50); //Ring 2 fill(0); ellipse(-6.6,6.6,40,40); //Inner fill(255); ellipse(-10,10,25,25); break; case 5: //Ring 1 fill(255); ellipse(-10,10,45,45); //Ring 2 fill(0); ellipse(-10,10,35,35); //Inner fill(255); ellipse(-13.3,13.3,22.5,22.5); break; case 6: //Ring 1 fill(255); ellipse(-13.3,13.3,40,40); //Ring 2 fill(0); ellipse(-13.3,13.3,30,30); //Inner fill(255); ellipse(-16.6,16.6,20,20); break; default: break; } //Close Cordinate System & Style popStyle(); popMatrix(); } //Check for Pressed Keys void keyPressed() { switch(key) { //On Space Save case ' ': save("permutation.jpg"); break; } }