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

From Medien Wiki
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Schachbrett ==


== Bauhaus Formen ==
<source lang="Java" highlight="11">
 
float seg = 0; //Segmentzähler
<source lang="Java">float seg = 0; //Segmentzähler


void setup() {
void setup() {
   size(800, 800);
   size(600, 600);
   smooth();
   smooth();
   noStroke();
   noStroke();
Line 12: Line 12:
void draw() {
void draw() {
   background(0);
   background(0);
   fill(255,255,0);
   for (float i=0; i<=400; i+=200) {
  maleSegmente(100,mouseX,mouseY,0,90);
    maleSegmente(100,100+i,100);
  fill(255,0,0);
    maleSegmente(100,100+i,300);
  maleSegmente(100,mouseX*2,mouseY*2,1,45);
    maleSegmente(100,100+i,500);
   fill(0,0,255);
   }
  maleSegmente(80,mouseY,mouseX,40,90);
}
}


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


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


void keyReleased() {
void keyPressed() {
   if (key == CODED) {
   if (key == CODED) {
     if (keyCode == UP) {
     if (keyCode == UP) {

Latest revision as of 17:29, 23 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;
      }
    } 
  }
}