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

1. Dezember 2010

For our 10 assignment we had to create our permutations in Processing. This was a fun assignment to tackle mostly because It would allow total control of all the forms that are built to make our permutations and shapes. After altering the single forms I encountered my first problem with the masking of the objects. Because one gets larger it was interfering with the other shapes as seen in the following picture; I could scale the object, but instead wanted to mask it so that no matter what changes occured. Processing would only display a certain height and width. When working with the rotation It was apparent the the float rotation was applied to all the rows. Which was my first problem. Here is what that looked like when the rotate (rotation); was applied to Case 0; Once I had the rotation implemented to rotate the forms in a fixed increment the problem of masking became apparent again. The scales of the forms interfered with each other as seen below; Here is the code thus far;
int     anzahl = 7;
int     rand = 50;
float   xStep;
float   yStep;
float   rotation = radians (45);
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};

void setup()
{
  size(600, 600);
  smooth();

  xStep = (width - 2 * rand) / (float)(anzahl-1);
  yStep = (height - 2 * rand) / (float)(anzahl-1);

  noLoop();
}

void draw()
{
  background(255);

  int     permutationsIndex = 0;

  pushMatrix();
    translate(rand,rand);
    for(int y=0; y<anzahl;y++)
    {
      pushMatrix();
        for(int x=0; x<anzahl;x++)
        {
          drawPermutationObj(permutationsIndexList[permutationsIndex], rotation);
          print(str(permutationsIndexList[permutationsIndex]) + "\t");

          ++permutationsIndex;

          translate(xStep,0.0f);
        }
        println();
      popMatrix();
      translate(0.0f,yStep);
    }
  popMatrix();

}

void drawPermutationObj(int type, float rotation) //implemented float rotation to have the forms turn slightly
{
  pushStyle();
  noStroke();
  switch(type)
  {
  case 0:
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    triangle (0,-37,32,18,-32,18);
    fill(0);
    ellipse(0,0,32,32);
    fill(255);
    triangle (0,-15,14,9,-14,9);
    break;

  case 1:
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    pushMatrix();
      
      scale(1.2);
      rotate(rotation);
      //rotate(radians(15));
      triangle (0,-37,32,18,-32,18);
      
    popMatrix();
    
    fill(0);
    
    pushMatrix();
    
    scale(1.2);
    ellipse(0,0,32,32);
    fill(255);
    
    popMatrix();
    
    pushMatrix();
      
      scale(1.2);
      rotate(-rotation);
      //rotate(radians(-15));
      triangle (0,-15,14,9,-14,9);
    
    popMatrix();
    
    break;

  case 2:

    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    pushMatrix();
      
      scale(1.4);
      rotate(rotation);
      //rotate(radians(30));
      triangle (0,-37,32,18,-32,18);
      
    popMatrix();
    
    fill(0);
    
    pushMatrix();
    
    scale(1.4);
    ellipse(0,0,32,32);
    fill(255);
    
    popMatrix();
    
    pushMatrix();
      
      scale(1.4);
      rotate(-rotation);
      //rotate(radians(-30));
      triangle (0,-15,14,9,-14,9);
    
    popMatrix();
    
    break;

  case 3:
    
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    pushMatrix();
      
      scale(1.6);
      rotate(rotation);
      //rotate(radians(45));
      triangle (0,-37,32,18,-32,18);
      
    popMatrix();
    
    fill(0);
    
    pushMatrix();
    
    scale(1.6);
    ellipse(0,0,32,32);
    fill(255);
    
    popMatrix();
    
    pushMatrix();
      
      scale(1.6);
            rotate(-rotation);
            //rotate(radians(-45));
      triangle (0,-15,14,9,-14,9);
    
    popMatrix();
    
    break;

  case 4:
    
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    pushMatrix();
      
      scale(1.8);
      rotate(rotation);
      //rotate(radians(50));
      triangle (0,-37,32,18,-32,18);
      
    popMatrix();
    
    fill(0);
    
    pushMatrix();
    
    scale(1.8);
    ellipse(0,0,32,32);
    fill(255);
    
    popMatrix();
    
    pushMatrix();
      
      scale(1.8);
      rotate(-rotation);
      //rotate(radians(-50));
      triangle (0,-15,14,9,-14,9);
    
    popMatrix();
    
    break;

  case 5:
  
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    pushMatrix();
      
      scale(2);
            rotate(rotation);
            //rotate(radians(65));
      triangle (0,-37,32,18,-32,18);
      
    popMatrix();
    
    fill(0);
    
    pushMatrix();
    
    scale(2);
    ellipse(0,0,32,32);
    fill(255);
    
    popMatrix();
    
    pushMatrix();
      
      scale(2);
            rotate(-rotation);
            //rotate(radians(-65));
      triangle (0,-15,14,9,-14,9);
    
    popMatrix();
    
    break;
  case 6:

   fill(0);
    ellipse(0,0,75,75);
    fill(255);
    pushMatrix();
      
      scale(2.2);
            rotate(rotation);
            //rotate(radians(80));
      triangle (0,-37,32,18,-32,18);
      
    popMatrix();
    
    fill(0);
    
    pushMatrix();
    
    scale(2.2);
    ellipse(0,0,32,32);
    fill(255);
    
    popMatrix();
    
    pushMatrix();
      
      scale(2.2);
            rotate(-rotation);
            //rotate(radians(-80));
      triangle (0,-15,14,9,-14,9);
    
    popMatrix();
    
    break;

  default:
    break;
  }
  popStyle();
}

void keyPressed()
{
  switch(key)
  {
  case ' ':
    save("permutation.jpg");
    break;
  }
}