Mehrere Formen
Segmente Objekt1,Objekt2,Objekt3;
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() {
size(800, 800); smooth(); 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() {
background(0); fill(h1,s,b); Objekt1.maleSegmente(seg1,r,g,x1,y1); fill(h2,s,b); Objekt2.maleSegmente(seg2,r,g,x2,y2); fill(h3,s,b); Objekt3.maleSegmente(seg3,r,g,x3,y3); 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() {
if (mouseOver1 == true) { x1 = mouseX; y1 = mouseY; }else if (mouseOver2 == true) { x2 = mouseX; y2 = mouseY; }else if (mouseOver3 == true) { x3 = mouseX; y3 = mouseY; }
}
void keyPressed() {
if (key == CODED) { if (mouseOver1 == true) { if (keyCode == UP) { if (seg1 <= 101) { seg1 += 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; } } } }
}
Objekt: Segmente
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(); }
}