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

From Medien Wiki
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Mehrere Formen ==
== Bauhaus Formen ==


<source lang="Java">Segmente Objekt1,Objekt2,Objekt3;
<source lang="Java" highlight="12,14,16">
 
float seg = 0; //Segmentzähler
float x1,x2,x3; // X-Position
float y1,y2,y3; // Y-Position
 
float seg1,seg2,seg3; // Segmentzähler
int r; // Radius
float g; // Richtung
 
int h1,h2,h3,s,b; // Farbe HSB
 
boolean mouseOver1,mouseOver2,mouseOver3; //Maus über dem Objekt


void setup() {
void setup() {
Line 18: Line 8:
   smooth();
   smooth();
   noStroke();
   noStroke();
  frameRate(5);
  colorMode(HSB,360,100,100);
 
  Objekt1 = new Segmente();
  Objekt2 = new Segmente();
  Objekt3 = new Segmente();
 
  x1 = 200; x2 = 400; x3 = 600;
  y1 = 400; y2 = 400; y3 = 400;
 
  seg1 = 0; seg2 = 0; seg3 = 0; // Dreieck
  r = 100;
  g = 90; // Richtung nach oben
 
  h1 = 0; h2 = 90; h3 = 180;
  s = 100;
  b = 100;
 
  mouseOver1 = false; mouseOver2 = false; mouseOver3 = false;
}
}


void draw() {
void draw() {
   background(0);
   background(0);
   fill(h1,s,b);
   fill(255,255,0);
   Objekt1.maleSegmente(seg1,r,g,x1,y1);
   maleSegmente(100,mouseX,mouseY,0,90);
   fill(h2,s,b);
   fill(255,0,0);
   Objekt2.maleSegmente(seg2,r,g,x2,y2);
   maleSegmente(100,mouseX*2,mouseY*2,1,45);
   fill(h3,s,b);
   fill(0,0,255);
   Objekt3.maleSegmente(seg3,r,g,x3,y3);
   maleSegmente(80,mouseY,mouseX,40,90);
 
  if (mouseX >= x1-r && mouseX <= x1+r && mouseY >= y1-r && mouseY <= y1+r) {
    mouseOver1 = true;
  }else {
    mouseOver1 = false;
  }
  if (mouseX >= x2-r && mouseX <= x2+r && mouseY >= y2-r && mouseY <= y2+r) {
    mouseOver2 = true;
  }else {
    mouseOver2 = false;
  }
  if (mouseX >= x3-r && mouseX <= x3+r && mouseY >= y3-r && mouseY <= y3+r) {
    mouseOver3 = true;
  }else {
    mouseOver3 = false;
  }
}
}


void mouseDragged() {
void maleSegmente(int r,float x,float y, float s, float g) {
   if (mouseOver1 == true) {
   float segmente = 0;
    x1 = mouseX;
  segmente = 3 + seg + s;
    y1 = mouseY;
  float angleStep = 360/segmente;
   }else if (mouseOver2 == true) {
 
    x2 = mouseX;
   beginShape();
    y2 = mouseY;
  vertex(x, y);  
   }else if (mouseOver3 == true) {
   for (float angle=0; angle<=360; angle+=angleStep) {
     x3 = mouseX;
     float vx = x + cos(radians(angle-g))*r;
     y3 = mouseY;
     float vy = y + sin(radians(angle-g))*r;
    vertex(vx, vy);
   }
   }
  vertex(x + cos(radians(360-g))*r, y + sin(radians(360-g))*r);
  endShape();
}
}


void keyPressed() {
void keyReleased() {
   if (key == CODED) {
   if (key == CODED) {
     if (mouseOver1 == true) {
     if (keyCode == UP) {
       if (keyCode == UP) {
       seg += 1;
        if (seg1 <= 101) {
    } else if (keyCode == DOWN) {
          seg1 += 1;
      if (seg >= 1) {
        }
        seg -= 1;
       }
       }
      if (keyCode == DOWN) {
     }  
        if (seg1 >= 1) {
          seg1 -= 1;
        }
      }
      if (keyCode == RIGHT) {
        if (h1 <= 361) {
          h1 += 1;
        }
      }
      if (keyCode == LEFT) {
        if (h1 >= 1) {
          h1 -= 1;
        }
      }
    }
    if (mouseOver2 == true) {
      if (keyCode == UP) {
        if (seg2 <= 101) {
          seg2 += 1;
        }
      }
      if (keyCode == DOWN) {
        if (seg2 >= 1) {
          seg2 -= 1;
        }
      }
      if (keyCode == RIGHT) {
        if (h2 <= 361) {
          h2 += 1;
        }
      }
      if (keyCode == LEFT) {
        if (h2 >= 1) {
          h2 -= 1;
        }
      }
    }
    if (mouseOver3 == true) {
      if (keyCode == UP) {
        if (seg3 <= 101) {
          seg3 += 1;
        }
      }
      if (keyCode == DOWN) {
        if (seg3 >= 1) {
          seg3 -= 1;
        }
      }
      if (keyCode == RIGHT) {
        if (h3 <= 361) {
          h3 += 1;
        }
      }
      if (keyCode == LEFT) {
        if (h3 >= 1) {
          h3 -= 1;
        }
      }
     }
  }
}
</source>
 
== Objekt: Segmente ==
 
<source lang="Java" line highlight="3">class Segmente {
 
  Segmente() {
    println("Segmente erstellt!");
  }
 
  void maleSegmente(float s,int r,float g,float x,float y) {
    float seg = 3 + s;
    float angleStep = 360/seg;
   
    beginShape();
    vertex(x, y);
    for (float angle=0; angle<=360; angle+=angleStep) {
      float vx = x + cos(radians(angle-g))*r;
      float vy = y + sin(radians(angle-g))*r;
      vertex(vx, vy);
    }
    vertex(x + cos(radians(360-g))*r, y + sin(radians(360-g))*r);
    endShape();
   }
   }
}
}
</source>
</source>

Latest revision as of 17:59, 23 January 2011

Bauhaus Formen

float seg = 0; //Segmentzähler

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

void draw() {
  background(0);
  fill(255,255,0);
  maleSegmente(100,mouseX,mouseY,0,90);
  fill(255,0,0);
  maleSegmente(100,mouseX*2,mouseY*2,1,45);
  fill(0,0,255);
  maleSegmente(80,mouseY,mouseX,40,90);
}

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

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

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