(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Objektorientiertes Gestaltungsprogramm == | == Objektorientiertes Gestaltungsprogramm == | ||
<source lang="Java">Segmente[] objekt = new Segmente[6]; | <source lang="Java" highlight="48,10">Segmente[] objekt = new Segmente[6]; | ||
void setup() { | void setup() { | ||
Line 23: | Line 23: | ||
objekt[i].s = 100; | objekt[i].s = 100; | ||
objekt[i].b = 100; | objekt[i].b = 100; | ||
objekt[i].a = | objekt[i].a = 100; | ||
objekt[i].mouseOver = false; | objekt[i].mouseOver = false; | ||
objekt[i]. | objekt[i].visible = false; | ||
} | } | ||
} | } | ||
Line 34: | Line 34: | ||
for (int i=0; i < objekt.length; i++) { | for (int i=0; i < objekt.length; i++) { | ||
if (objekt[i]. | if (objekt[i].visible == true) { | ||
objekt[i].maleSegmente(); | objekt[i].maleSegmente(); | ||
} | } | ||
Line 72: | Line 72: | ||
void keyPressed() { | void keyPressed() { | ||
if (key == '0') { | if (key == '0') { | ||
objekt[0]. | objekt[0].visible = true; | ||
} | } | ||
if (key == '1') { | if (key == '1') { | ||
objekt[1]. | objekt[1].visible = true; | ||
} | } | ||
if (key == '2') { | if (key == '2') { | ||
objekt[2]. | objekt[2].visible = true; | ||
} | } | ||
if (key == '3') { | if (key == '3') { | ||
objekt[3]. | objekt[3].visible = true; | ||
} | } | ||
if (key == '4') { | if (key == '4') { | ||
objekt[4]. | objekt[4].visible = true; | ||
} | } | ||
if (key == '5') { | if (key == '5') { | ||
objekt[5]. | objekt[5].visible = true; | ||
} | } | ||
Line 94: | Line 94: | ||
if (objekt[i].mouseOver == true) { | if (objekt[i].mouseOver == true) { | ||
if (keyCode == UP) { | if (keyCode == UP) { | ||
if (objekt[i].seg <= | if (objekt[i].seg <= 100) { | ||
objekt[i].seg += 1; | objekt[i].seg += 1; | ||
} | } | ||
Line 104: | Line 104: | ||
} | } | ||
if (keyCode == RIGHT) { | if (keyCode == RIGHT) { | ||
if (objekt[i].h <= | if (objekt[i].h <= 360) { | ||
objekt[i].h += 1; | objekt[i].h += 1; | ||
} | } | ||
Line 131: | Line 131: | ||
boolean mouseOver; //Maus über dem Objekt | boolean mouseOver; //Maus über dem Objekt | ||
boolean | boolean visible; //Objekt sichtbar | ||
int h,s,b,a; // Farbe HSB und Alpha | int h,s,b,a; // Farbe HSB und Alpha |
Latest revision as of 17:44, 23 January 2011
Objektorientiertes Gestaltungsprogramm
Segmente[] objekt = new Segmente[6];
void setup() {
size(800, 800);
smooth();
noStroke();
frameRate(5);
colorMode(HSB,360,100,100,100);
for (int i=0; i < objekt.length; i++) {
objekt[i] = new Segmente();
objekt[i].x = width/2; // Mitte
objekt[i].y = height/2;
objekt[i].seg = 0; // Dreieck
objekt[i].r = 100;
objekt[i].g = 90; // Richtung nach oben
objekt[i].h = 0; // Rot
objekt[i].s = 100;
objekt[i].b = 100;
objekt[i].a = 100;
objekt[i].mouseOver = false;
objekt[i].visible = false;
}
}
void draw() {
background(0);
for (int i=0; i < objekt.length; i++) {
if (objekt[i].visible == true) {
objekt[i].maleSegmente();
}
}
for (int i=0; i < objekt.length; i++) {
if ((mouseX >= objekt[i].x-objekt[i].r) && (mouseX <= objekt[i].x+objekt[i].r) && (mouseY >= objekt[i].y-objekt[i].r) && (mouseY <= objekt[i].y+objekt[i].r)) {
objekt[i].mouseOver = true;
}else {
objekt[i].mouseOver = false;
}
}
}
void mouseDragged() {
if (objekt[0].mouseOver == true) {
objekt[0].x = mouseX;
objekt[0].y = mouseY;
}else if (objekt[1].mouseOver == true) {
objekt[1].x = mouseX;
objekt[1].y = mouseY;
}else if (objekt[2].mouseOver == true) {
objekt[2].x = mouseX;
objekt[2].y = mouseY;
}else if (objekt[3].mouseOver == true) {
objekt[3].x = mouseX;
objekt[3].y = mouseY;
}else if (objekt[4].mouseOver == true) {
objekt[4].x = mouseX;
objekt[4].y = mouseY;
}else if (objekt[5].mouseOver == true) {
objekt[5].x = mouseX;
objekt[5].y = mouseY;
}
}
void keyPressed() {
if (key == '0') {
objekt[0].visible = true;
}
if (key == '1') {
objekt[1].visible = true;
}
if (key == '2') {
objekt[2].visible = true;
}
if (key == '3') {
objekt[3].visible = true;
}
if (key == '4') {
objekt[4].visible = true;
}
if (key == '5') {
objekt[5].visible = true;
}
if (key == CODED) {
for (int i=0; i < objekt.length; i++) {
if (objekt[i].mouseOver == true) {
if (keyCode == UP) {
if (objekt[i].seg <= 100) {
objekt[i].seg += 1;
}
}
if (keyCode == DOWN) {
if (objekt[i].seg >= 1) {
objekt[i].seg -= 1;
}
}
if (keyCode == RIGHT) {
if (objekt[i].h <= 360) {
objekt[i].h += 1;
}
}
if (keyCode == LEFT) {
if (objekt[i].h >= 1) {
objekt[i].h -= 1;
}
}
}
}
}
}
Segmente
class Segmente {
float x; // X-Position
float y; // Y-Position
float seg; // Segmentzähler
int r; // Radius
float g; // Richtung
boolean mouseOver; //Maus über dem Objekt
boolean visible; //Objekt sichtbar
int h,s,b,a; // Farbe HSB und Alpha
Segmente() {
println("Segmente erstellt!");
}
void maleSegmente() {
fill(h,s,b,a);
maleSegmente(seg,r,g,x,y);
}
void maleSegmente(float seg,int r,float g,float x,float y) {
float segmentzahl = 3 + seg;
float angleStep = 360/segmentzahl;
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();
}
}