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.

GDB Aufgabe 04 – Permutationen

10. November 2011

Bei dieser Aufgabe mussten wir die Transformationen in einem Raster anordnen und Verschiebungen vornehmen. Ich habe hier Funktionen für Screenshots, das Verändern des Abstands und für das Wechseln der verschiedenen Permutationen eingebaut. Am Zeichen habe ich geändert, dass es jetzt eine dicke schwarze Outline hat.
void keyPressed()
{
  switch(key)
  {
  case 'a':
    permutationNumber++;
    if(permutationNumber > 5) {   // If permutationNumber is bigger than 5
    permutationNumber = 1;        //...set it back to 1
    }
    println("Next permutation");
    redraw();
    break;
   case 's':
    saveFrame("screenshot-####.png");      // Speichern eines Screenshots auf Druck von S
    println("Saved screenshot-##.png");
    redraw();
    break;
   case 'd':
    rand+=20;
    if(rand > 330) {   // If rand ist bigger than 330
    rand = 70;        //...set it back to 70
    }
    println("Decreased distance between signs");
    redraw();
    break;
    case 'w':
    println("The W");
    redraw();
    break;
  }
}
   
int     anzahl = 7;
int     rand = 70;
float   xStep;
float   yStep;

// Defines the y-positions of the different rows of transformation.
// the bigger the difference, the further these are apart on the screen.

int yPosTrans1 = 0;
int yPosTrans2 = 0;
int yPosTrans3 = 0;

// defines the x-positions for each transformation step (taken over from older code...)

int xPosStep1 = 0;
int xPosStep2 = 0;
int xPosStep3 = 0;
int xPosStep4 = 0;
int xPosStep5 = 0;
int xPosStep6 = 0;
int xPosStep7 = 0;

int formSize = 90; // all forms have a common size

int permutation1  = 1;
int permutation2  = 2;
int permutation3  = 3;
int permutation4  = 4;
int permutation5  = 5;

int permutationNumber = permutation1;

int[]   permutationsIndexList1 = {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};

// each row is reversing its order
int[]   permutationsIndexList2 = {0, 1, 2, 3, 4, 5, 6,
                                 6, 5, 4, 3, 2, 1, 0,
                                 0, 1, 2, 3, 4, 5, 6,
                                 6, 5, 4, 3, 2, 1, 0,
                                 0, 1, 2, 3, 4, 5, 6,
                                 6, 5, 4, 3, 2, 1, 0,
                                 0, 1, 2, 3, 4, 5, 6,};

// spiral pattern, starting in the middle going right
int[]   permutationsIndexList3 = {1, 0, 6, 5, 4, 3, 2,
                                 2, 2, 1, 0, 6, 5, 1,
                                 3, 3, 4, 3, 2, 4, 0,
                                 4, 4, 5, 0, 1, 3, 6,
                                 5, 5, 6, 0, 1, 2, 5,
                                 6, 6, 0, 1, 2, 3, 4,
                                 0, 1, 2, 3, 4, 5, 6};

//// diagonal pattern, "falling apart" towards the corners
int[]   permutationsIndexList4 = {6, 5, 4, 3, 2, 1, 0,
                                 5, 4, 3, 2, 1, 0, 1,
                                 4, 3, 2, 1, 0, 1, 2,
                                 3, 2, 1, 0, 1, 2, 3,
                                 2, 1, 0, 1, 2, 3, 4,
                                 1, 0, 1, 2, 3, 4, 5,
                                 0, 1, 2, 3, 4, 5, 6};

int[]   permutationsIndexList5 = {0, 1, 2, 3, 4, 5, 6,
                                 1, 2, 3, 4, 5, 6, 0,
                                 2, 3, 4, 5, 6, 0, 1,
                                 3, 4, 5, 6, 0, 1, 2,
                                 4, 5, 6, 0, 1, 2, 3,
                                 5, 6, 0, 1, 2, 3, 4,
                                 6, 0, 1, 2, 3, 4, 5};

void setup()
{

  size(670, 670);
  smooth();

  rectMode(CENTER);
  ellipseMode(CENTER);
  frameRate(15);
  noLoop();
}

void draw()
{

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

  int     permutationsIndex = 0;

  pushMatrix();
    translate(rand,rand);
    for(int y=0; y<anzahl;y++)
    {
      pushMatrix();
        for(int x=0; x<anzahl;x++)
        {

          if((permutationNumber) == 1){
          drawPermutationObj(permutationsIndexList1[permutationsIndex]);
          ++permutationsIndex;
          }

          if((permutationNumber) == 2){
          drawPermutationObj(permutationsIndexList2[permutationsIndex]);
          ++permutationsIndex;
          }

          if((permutationNumber) == 3){
          drawPermutationObj(permutationsIndexList3[permutationsIndex]);
          ++permutationsIndex;
          }

          if((permutationNumber) == 4){
          drawPermutationObj(permutationsIndexList4[permutationsIndex]);
          ++permutationsIndex;
          }

          if((permutationNumber) == 5){
          drawPermutationObj(permutationsIndexList5[permutationsIndex]);
          ++permutationsIndex;
          }

          translate(xStep,0.0f);
        }

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

  pushStyle();

    fill(255,255,255,30);
    noStroke();
    rect(width/2, height-15, width, 30);

    fill(0,255,0);
    text("Permutation " + permutationNumber,550,665);
    text("Rand " + rand,550,653);

    text("'s' to save a screenshot, 'a' to switch permutations, 'd' to increase rand", 40, 665);
    text("'d' to increase rand, 'w' to ???", 40, 653);
  popStyle();

}

void drawPermutationObj(int type)
{
  pushStyle();
  switch(type)
  {
  case 0:
        circleFilledWhiteOutlineBlack(xPosStep1,yPosTrans2,1.0,0.0,4);
        circleFilledBlack(xPosStep1+formSize/2,yPosTrans2,1.0,0.0,2);
        circleFilledBlack(xPosStep1,yPosTrans2,1.0/3,0.0,2);
        circleFilledWhite(xPosStep1+7,yPosTrans2,1.0/3,0.0,2);
    break;

  case 1:
        circleFilledWhiteOutlineBlack(xPosStep2,yPosTrans2,0.95,0.0,4);
        circleFilledBlack(xPosStep2+formSize/3,yPosTrans2+31,0.95,0.0,2);
        circleFilledBlack(xPosStep2,yPosTrans2,1.05/3,0.0,2);
        circleFilledWhite(xPosStep2+3,yPosTrans2+2,1.05/3,0.0,2);
    break;

  case 2:
        circleFilledWhiteOutlineBlack(xPosStep3,yPosTrans2,0.9,0.0,4);
        circleFilledBlack(xPosStep3+formSize/3-7,yPosTrans2+32,0.9,0.0,2);
        circleFilledBlack(xPosStep3,yPosTrans2,1.1/3,0.0,2);
        circleFilledWhite(xPosStep3+1,yPosTrans2+2,1.1/3,0.0,2);
    break;

  case 3:
        circleFilledWhiteOutlineBlack(xPosStep4,yPosTrans2,0.8,0.0,4);
        circleFilledBlack(xPosStep4,yPosTrans2+35,0.8,0.0,2);
        circleFilledBlack(xPosStep4,yPosTrans2,1.15/3,0.0,2);
        circleFilledWhite(xPosStep4+2,yPosTrans2+2,1.15/3,0.0,2);
    break;

  case 4:
        circleFilledWhiteOutlineBlack(xPosStep5,yPosTrans2,0.9,0.0,4);
        circleFilledBlack(xPosStep5+20,yPosTrans2+35,0.9,0.0,2);
        circleFilledBlack(xPosStep5+2,yPosTrans2-2,1.2/3,0.0,2);
        circleFilledWhite(xPosStep5+3,yPosTrans2-1,1.2/3,0.0,2);
    break;

  case 5:
        circleFilledWhiteOutlineBlack(xPosStep6,yPosTrans2,0.9,0.0,4);
        circleFilledBlack(xPosStep6+25,yPosTrans2+25,0.9,0.0,2);
        circleFilledBlack(xPosStep6+6,yPosTrans2-4,1.25/3,0.0,2);
        circleFilledWhite(xPosStep6+7,yPosTrans2-2,1.25/3,0.0,2);
    break;

  case 6:
        circleFilledWhiteOutlineBlack(xPosStep7,yPosTrans2,0.9,0.0,2);
        circleFilledBlack(xPosStep7+25,yPosTrans2+25,0.9,0.0,2);
        circleFilledBlack(xPosStep7+6,yPosTrans2-4,1.3/3,0.0,2);
        circleFilledWhite(xPosStep7+7,yPosTrans2-3,1.15/3,0.0,2);
    break;

  default:
    break;
  }
  popStyle();
}

// Toggle funktion (indexNumber++1 if > 5; indexNumber=1)

void keyPressed()
{
  switch(key)
  {
  case 'a':
    permutationNumber++;
    if(permutationNumber > 5) {   // If permutationNumber is bigger than 5
    permutationNumber = 1;        //...set it back to 1
    }
    println("Next permutation");
    redraw();
    break;
   case 's':
    saveFrame("screenshot-####.png");      // Speichern eines Screenshots auf Druck von S
    println("Saved screenshot-##.png");
    redraw();
    break;
   case 'd':
    rand+=20;
    if(rand > 330) {   // If rand ist bigger than 330
    rand = 70;        //...set it back to 70
    }
    println("Decreased distance between signs");
    redraw();
    break;
    case 'w':
    println("The W");
    redraw();
    break;
  }
}

// SQUARES
void squareFilledWhite (int translateX, int translateY, float scaleValue, float rotateValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    fill(255);
    noStroke();
    rect(0,0,90,90);
  popMatrix();
}

void squareFilledBlack (int translateX, int translateY, float scaleValue, float rotateValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    fill(0);
    noStroke();
    rect(0,0,formSize,formSize);
  popMatrix();
}

void squareOutlineWhite (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noFill();
    stroke(255);
    strokeWeight(strokeWeightValue);
    rect(0,0,formSize,formSize);
  popMatrix();
}

void squareOutlineBlack (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noFill();
    stroke(0);
    strokeWeight(strokeWeightValue);
    rect(0,0,formSize,formSize);
  popMatrix();
}

// TRIANGLES

void triangleFilledWhite (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    fill(255);
    noStroke();
    triangle(0, formSize, 45, 0, formSize, formSize);
  popMatrix();
}

void triangleFilledBlack (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    fill(0);
    noStroke();
    triangle(0, formSize, 45, 0, formSize, formSize);
  popMatrix();
}

void triangleOutlineWhite (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noFill();
    stroke(255);
    strokeWeight(strokeWeightValue);
    triangle(0, formSize, formSize/2, 0, formSize, formSize);
  popMatrix();
}

void triangleOutlineBlack (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noFill();
    stroke(0);
    strokeWeight(strokeWeightValue);
    triangle(0, formSize, formSize/2, 0, formSize, formSize);
  popMatrix();
}

// CIRCLES

void circleFilledWhite (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noStroke();
    fill(255);
    ellipse(0,0,formSize,formSize);
  popMatrix();
}

void circleFilledWhiteOutlineBlack(int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    fill(0);
    strokeWeight(strokeWeightValue);
    fill(255);
    ellipse(0,0,formSize,formSize);
  popMatrix();
}

void circleFilledBlack (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    fill(0);
    noStroke();
    ellipse(0,0,formSize,formSize);
  popMatrix();
}

void circleOutlineWhite (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noFill();
    stroke(255);
    strokeWeight(strokeWeightValue);
    ellipse(0,0,formSize,formSize);
  popMatrix();
}

void circleOutlineBlack (int translateX, int translateY, float scaleValue, float rotateValue, int strokeWeightValue)
{
  pushMatrix();
    translate(translateX,translateY);
    scale(scaleValue);
    rotate(rotateValue);
    noFill();
    stroke(0);
    strokeWeight(strokeWeightValue);
    ellipse(0,0,formSize,formSize);
  popMatrix();
}