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.

Permutation 2 – Wellen

2. Dezember 2010

Erzeuge durch einen Klick eine Welle die sich von der Mausposition
/*
*  PERMUTATION 2 - Wave Calculation
*  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};

//Wave Calucaltion
PVector posMouse;
boolean pressed = false;
float waveDistance;

//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 type = permutationsIndexList[permutationsIndex];
          
      //Set Default Object Scale
      float objScale = 1;
      
      //Is a Wave Active?
      if(pressed)
      {
        //Get Actual Position
        PVector posActual = new PVector(x,y,0);
            
        //Get Distance to Wave Center
        int distance = (int)posMouse.dist(posActual);
            
        //Check Object
        if(distance == waveDistance)
        {
          //Set Scale
          objScale = 0.75;
        }
        else if (distance+1 == waveDistance)
        {
          objScale = 0.5;
        }
        else if (distance-1 == waveDistance)
        {
          objScale = 0.5;
        }
      }
       
      //Draw Object
      drawPermutationObj(type,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);
  }
  
  //Increment Wave
  waveDistance++;
}

//Darw 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;
  }
}

//Check for Pressed Mouse
void mousePressed()
{
  //Set Wave Settings
  waveDistance = 0;
  pressed = true;
  posMouse = new PVector(map(mouseX,0,width,0,6),map(mouseY,0,height,0,6),0); 
}