Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Lektion_10_AnimatedPermutations

8. Dezember 2010

Because my last permutation was not up to standards I have to wait till friday until I can show Mr. Späth a few new permutations. Those will then be used to make this animated permutations. So instead I created a simple permutation with crosses because I havent worked with them before. The hard part about this permutation was to define a mouse position that worked. Especially making sure that the negative x and y values where changed to a value that the program could work with. Defining the degrees is something I am still having problems with. As I want the pointer to follow the mouse. The easy way to solve that would be to draw the arrow at another point. But I would rather solve it by changing the degree value.

/*
//SIMPLE PERMUTATION
//TESTING MOUSE MOVEMENT
*/

//Initializing Variables

int     numberPerRow = 7;
int     rand = 50;
float   xStep;
float   yStep;

// 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.

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);
}


/*
// Mouse Position
 */
float MousePosition(float _x, float _y) {
  float 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 draw()
{
  background(255);

  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 + 35, yStep*y + 35)));
          ++permutationsIndex;
          translate(xStep,0.0f);
        }
      popMatrix();
      translate(0.0f,yStep);
    }
  popMatrix();
}

void drawPermutationObj(int type, float transformation)
{
  pushMatrix();
  rotate(transformation);
  pushStyle();
  switch(type)
  {
  case 0:
    

      stroke(0);
      fill(0);
      ellipse(0,0,75,75);


      stroke(0);
      fill(255);
      ellipse(0,0,62,62);

      stroke(0);
      fill(0);
      beginShape();
      vertex(25,0);
      vertex(20,-10);
      vertex(20,-5);
      vertex(10,-5);
      vertex(10,5);
      vertex(20,5);
      vertex(20,10);
      endShape(CLOSE);
      //endShape();
    
  break;

  case 1:
   

      stroke(0);
      fill(0);
      ellipse(0,0,75,75);


      stroke(0);
      fill(255);
      ellipse(0,0,62,62);


      stroke(0);
      fill(0);
      beginShape();
      vertex(25,0);
      vertex(20,-10);
      vertex(20,-5);
      vertex(8,-5);
      vertex(8,5);
      vertex(20,5);
      vertex(20,10);
      endShape(CLOSE);


      
    
  break;

  case 2:
    

      stroke(0);
      fill(0);
      ellipse(0,0,75,75);


      stroke(0);
      fill(255);
      ellipse(0,0,62,62);


      stroke(0);
      fill(0);
      beginShape();
      vertex(25,0);
      vertex(20,-10);
      vertex(20,-5);
      vertex(6,-5);
      vertex(6,5);
      vertex(20,5);
      vertex(20,10);
      endShape(CLOSE);


    
  break;

  case 3:
    

      stroke(0);
      fill(0);
      ellipse(0,0,75,75);


      stroke(0);
      fill(255);
      ellipse(0,0,62,62);


      stroke(0);
      fill(0);
      beginShape();
      vertex(25,0);
      vertex(20,-10);
      vertex(20,-5);
      vertex(4,-5);
      vertex(4,5);
      vertex(20,5);
      vertex(20,10);
      endShape(CLOSE);


   
  break;  

  case 4:
   

        stroke(0);
        fill(0);
        ellipse(0,0,75,75);


        stroke(0);
        fill(255);
        ellipse(0,0,62,62);


        stroke(0);
      fill(0);
      beginShape();
      vertex(25,0);
      vertex(20,-10);
      vertex(20,-5);
      vertex(2,-5);
      vertex(2,5);
      vertex(20,5);
      vertex(20,10);
      endShape(CLOSE);


     
  break;

  case 5:
    

        stroke(0);
        fill(0);
        ellipse(0,0,75,75);


        stroke(0);
        fill(255);
        ellipse(0,0,62,62);


        stroke(0);
        fill(0);
        beginShape();
        vertex(25,0);
        vertex(20,-10);
        vertex(20,-5);
        vertex(0,-5);
        vertex(0,5);
        vertex(20,5);
        vertex(20,10);
        endShape(CLOSE);


     
  break;

  case 6:
    

      stroke(0);
      fill(0);
      ellipse(0,0,75,75);


      stroke(0);
      fill(255);
      ellipse(0,0,62,62);


      stroke(0);
      fill(0);
      beginShape();
      vertex(25,0);
      vertex(20,-10);
      vertex(20,-5);
      vertex(-2,-5);
      vertex(-2,5);
      vertex(20,5);
      vertex(20,10);
      endShape(CLOSE);


    
  break;

  default:
  break;
  }
  popStyle();
  popMatrix();
}