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

From Medien Wiki
(Created page with " == Formumwandlung == float seg = 0; void setup() { size(800, 800); smooth(); } void draw() { background(0); maleSegmente(300,400,400); } void maleSegmente(int r,flo...")
 
Line 2: Line 2:
== Formumwandlung ==
== Formumwandlung ==


float seg = 0;  
<source lang="Java">float seg = 0;  


void setup() {
void setup() {
Line 43: Line 43:
   }
   }
}
}
</source>

Revision as of 20:29, 14 January 2011

Formumwandlung

float seg = 0; 

void setup() {
  size(800, 800);
  smooth();
}

void draw() {
  background(0);
  maleSegmente(300,400,400);
}

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,y);
    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;
      }
    } 
  }
}