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.

Interactive Permutations v2

14. Dezember 2010

I've changed the circles in this one. Also, you can increase the amounts of circles by using the mouse wheel. The main class:
//for mouse wheel
import java.awt.event.*;
float wheel;

int     anzahl = 7;
int     rand = 60;
float   xStep;
float   yStep;
float mX, mY, joker, param2;
ArrayList Symbols;
//create dynamic perm.index list dynamicaly from anzahl (amount)
int[] permutationsIndexList = new int[2*anzahl-2];

int version;
Symbol symbol;

void setup()
{
  size(600, 600);
  smooth();
  Symbols = new ArrayList();
  permutationsIndexList = getIndexList(anzahl);

  // add mouse wheel listener  
  frame.addMouseWheelListener(new MouseWheelInput());  

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

  mX = 1;
  mY = 1;
  joker = 0;
  symbol = new Symbol();  //initialize my symbol

    version=1;  //symmetry versions
}

void draw()
{
  background(255);
  noStroke();

  pushMatrix();
  translate(rand,rand);
  for(int y=0; y<anzahl; y++)
  { 
    int j = 0;
    pushMatrix();
    for(int x=0; x<anzahl;x++)
    {
      //symmetry presets..perhaps nicer with a switch method
      if(version==1)
        param2 = mX*2*(x+y+1)*PI/(anzahl*1.0);
      else if(version==2)
        param2 = mX*2*(x+1)*PI/(anzahl*1.0);
      else if(version==3)
        param2 = mX*2*(y+1)*PI/(anzahl*1.0);
      else if(version==4)
        param2 = mX*2*(-x-y+1)*PI/(anzahl*1.0);
      else if(version==5)
        param2 = mX*2*(-x+1)*PI/(anzahl*1.0);
      else
        param2 = mX*2*(-y+1)*PI/(anzahl*1.0);

      symbol.drawPermutationObj(permutationsIndexList[x+j], 75, param2, mY,anzahl);

      translate(xStep,0.0f);
    }
    j++;
    popMatrix();
    translate(0.0f,yStep);
  }
  popMatrix();
  fill(0);
  text("key 1-6: symmetry presets | x-mouse: main rotation | y-mouse: inner-rotation | mouse wheel multiply",10, height-15, 700, 100);
}


void mouseMoved() {
  //mouse mapping
  mX = map(mouseX, 0, width, 0, PI);
  mY = map(mouseY, 0, height, 4.0, 0.25);
}
void mousePressed() {
}

void keyPressed()
{
  switch(key)
  {
  case '1':
    version = 1;
    break;
  case '2':
    version = 2;
    break;
  case '3':
    version = 3;
    break;
  case '4':
    version = 4;
    break;
  case '5':
    version = 5;
    break;
  case '6':
    version = 6;
    break;
  }
}
//calculate my lookup-array, for example of 5: [0,1,2,4,3,2,1,0]
int[] getIndexList(int a) {
  int aIndex = (2*a)-1;
  int[] lookup = new int[aIndex];
  for(int i=0; i<a; i++) {
    lookup[i] = i;
    lookup[aIndex-1-i] = i;
  }
  return lookup;
}

// convenience class to listen for MouseWheelEvent  
class MouseWheelInput implements MouseWheelListener {  

  void mouseWheelMoved(MouseWheelEvent e) {  
    int step=e.getWheelRotation();
    anzahl=anzahl+step;  //mouse wheel increases the symbols
    if(anzahl<=0)  //not less than one
      anzahl = 1;
    permutationsIndexList = new int[2*anzahl-2];
    permutationsIndexList = getIndexList(anzahl);

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

    println("mouse: "+anzahl);
  }
}  

And here is my symbol class:
class Symbol {
  //parameters: [switch type, diameter, rotation, inner-circle rotation, multiply factor (scaling)]
  void drawPermutationObj(int type, float d, float angle, float growY, int anzahl)
  {
    type = type%7; //permutation of 7
    float r = d/2;  //radius of container circle
    pushStyle();
    fill(0);
    ellipse(((r-35) * cos(angle-PI)), ((r-35) * sin(angle-PI)), 7*80/anzahl, 7*80/anzahl); 
    fill(255);
    ellipse(((r-35) * cos(angle-PI/2)), ((r-35) * sin(angle-PI/2)),  7*70/anzahl,  7*70/anzahl);  
    fill(0);
    ellipse(((r-30) * cos(angle-growY*PI/4)), ((r-30) * sin(angle-growY*PI/4)), 60*7/anzahl, 60*7/anzahl);         
    fill(255);
    ellipse(((r-25) * cos(angle-growY*PI/6)), ((r-25) * sin(angle-growY*PI/6)), 50*7/anzahl, 50*7/anzahl);      
    fill(0);
    ellipse(((r-20) * cos(angle-growY*PI/8)), ((r-20) * sin(angle-growY*PI/8)), 40*7/anzahl, 40*7/anzahl);
    fill(255);
    ellipse(((r-15) * cos(angle-growY*PI/12)), ((r-15) * sin(angle-growY*PI/12)), 30*7/anzahl, 30*7/anzahl); 
    popStyle();
  }
}