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.4: Permutation mit Maus

8. Dezember 2010

Aufgabe: Durch Bewegen der Maus sollte sich die Permutation verändern. Mithilfe der reference habe ich einen Farbwechsel mit "mouseMoved" erstellt, dementsprechend gross ist die Freude:
int     anzahl = 7;
int     rand = 50;
int     value = 0;

float   f = 0;
float   xStep;
float   yStep;
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++)
        {
          f += 0.1;
          drawPermutationObj(permutationsIndexList[permutationsIndex],f);
          print(str(permutationsIndexList[permutationsIndex]) + "\t");

          ++permutationsIndex;

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

}

float rot=0;

void drawPermutationObj(int type, float c)
{
  pushStyle();
  switch(type)
  {
  case 0: 
    rot +=0;
    pushMatrix();
    rotate(radians(-c));
  
    stroke(0);
    //fill(0);
    fill(value);
    ellipse(0,0,75,75);
    //fill(value);
    fill(255);
    ellipse(2,0,55,55);
    noFill();
    strokeWeight(6);
    ellipse(-9,0,45,45);
    fill(0);
    ellipse(-15,0,23,23);
    
    popMatrix();
    break;

  case 1:
      rot +=0;
      pushMatrix();
      rotate(radians(-c));
      
    stroke(0);
    //fill(0);
    fill(value);
    ellipse(0,0,75,75);
    //fill(255);
    fill(value);
    ellipse(2,0,57,57);
    noFill();
    strokeWeight(6);
    ellipse(-9.2,0,43,43);
    fill(0);
    ellipse(-15,-1,23,23);
    fill(0);
    ellipse(-14.5,-1.6,21,21);
    
    popMatrix();
    break;

  case 2: 
    rot +=0;
    pushMatrix();
    rotate(radians(-c));
    
    stroke(0);
    fill(0);
    ellipse(0,0,75,75);
    fill(value);
    //fill(255);
    ellipse(0,0,59,59);
    noFill();
    strokeWeight(5);
    ellipse(-9.4,-2,40,40);
    fill(0);
    ellipse(-14.5,-3.2,19,19);
    
    popMatrix();
    break;

  case 3:
  
  rot +=0;
      pushMatrix();
      rotate(radians(-c));
    stroke(0);
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    ellipse(0,0,61,61);
    noFill();
    fill(value);
    strokeWeight(5);
    ellipse(-9.6,-3,38,38);
    fill(0);
    ellipse(-13.5,-4.8,17,17);
    
    popMatrix();
    break;  

  case 4:
    rot +=0;
    pushMatrix();
    rotate(radians(-c));
    
    stroke(0);
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    ellipse(0,0,66,66);
    noFill();
    strokeWeight(5);
    ellipse(-9.7,-4,35,35);
    //fill(0);
    fill(value);
    ellipse(-13,-6.4,15,15);
    
    popMatrix();
    break;

  case 5:
  rot +=0;
      pushMatrix();
      rotate(radians(-c));
  
    stroke(0);
    fill(0);
    ellipse(0,0,75,75);
    fill(255);
    ellipse(0,0,68,68);
    //noFill();
    fill(value);
    //strokeWeight(5);
    fill(value);
    ellipse(-9.9,-6,33,33);
    fill(0);
    fill(value);
    ellipse(-12.5,-8,13,13);
    
    popMatrix();
    break;

  case 6:
  
  rot +=0;
      pushMatrix();
      rotate(radians(-c));
    fill(value);
    stroke(0);
    fill(0);
    fill(value);
    ellipse(0,0,75,75);
    fill(255);
    fill(value);
    ellipse(0,0,70,70);
    noFill();
    //strokeWeight(4);
    fill(value);
    ellipse(-10,-7,30,30);
    fill(0);
    fill(value);
    ellipse(-12,-10,10,10);
    
    popMatrix();
    break;

  default:
    break;
  }
  popStyle();
}

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

void mouseMoved() {
  value = value + 2;
  if (value > 255) {
    value = 0;
  }
}