Digital Bauhaus Vorkurs/Projekte/Form und Raum/Code3: Difference between revisions

From Medien Wiki
No edit summary
Line 1: Line 1:
 
== Schachbrett ==
== Bauhaus Formen ==


<source lang="Java">
<source lang="Java">

Revision as of 21:55, 14 January 2011

Schachbrett

float seg = 0; //Segmentzähler

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

void draw() {
  background(0);
  for (float i=0; i<=400; i+=200) {
    maleSegmente(100,100+i,100);
    maleSegmente(100,100+i,300);
    maleSegmente(100,100+i,500);
  }
}

void maleSegmente(int r,float x,float y) {  
  float segmente = 0;
  segmente = 3 + seg;
  float angleStep = 360/segmente;

  beginShape();
  vertex(x, y); 
  for (float angle=0; angle<=360; angle+=angleStep) {
    float vx = x + cos(radians(angle-90))*r;
    float vy = y + sin(radians(angle-90))*r;
    vertex(vx, vy);
  }
  vertex(x + cos(radians(270))*r, y + sin(radians(270))*r);
  endShape();
}

void keyPressed() {
  if (key == CODED) {
    if (keyCode == UP) {
      seg += 1;
    } else if (keyCode == DOWN) {
      if (seg >= 1) {
        seg -= 1;
      }
    } 
  }
}