< GMU:Immersive Strategien | Inhalte | Bälle
(Created page with " == Code == == Objekt Ball ==") |
(→Code) |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
''Die Bildschirmgröße stimmt nicht für das Tischtheater. Sie ist an die Bildschrimgröße meines PCs angepasst, weil sonst nicht alles zu sehen war, eher gesagt, er hat das Bild abgeschnitten (wie in der gallery zu sehen).'' | |||
== Code == | == Code == | ||
<source lang="Java">Ball[] ball = new Ball[15]; | |||
int a,b,c; //Abstände der Ebenen | |||
void setup() { | |||
size(1280,1024); | |||
smooth(); | |||
noStroke(); | |||
colorMode(HSB,360,100,100,100); | |||
a = 500; //erste Ebene | |||
b = 400; //zweite Ebene | |||
c = 40; //Lücke | |||
for (int i=0; i < 5; i++) { | |||
ball[i] = new Ball(); | |||
ball[i].x = random(ball[i].g,a-ball[i].g); | |||
ball[i].y = random(ball[i].g,height-ball[i].g); | |||
} | |||
for (int i=5; i < 10; i++) { | |||
ball[i] = new Ball(); | |||
ball[i].x = random(a+c+ball[i].g,a+c+b-ball[i].g); | |||
ball[i].y = random(ball[i].g,height-ball[i].g); | |||
} | |||
for (int i=10; i < ball.length; i++) { | |||
ball[i] = new Ball(); | |||
ball[i].x = random(a+c+b+c+ball[i].g,width-ball[i].g); | |||
ball[i].y = random(ball[i].g,height-ball[i].g); | |||
} | |||
} | |||
void draw() { | |||
background(0); | |||
fill(255); | |||
rect(a,0,c,height); | |||
fill(255); | |||
rect(a+c+b,0,c,height); | |||
for (int i=0; i < 5; i++) { | |||
ball[i].maleBall(); | |||
ball[i].x = ball[i].x + ball[i].vx; | |||
ball[i].y = ball[i].y + ball[i].vy; | |||
if (ball[i].x <= 0+ball[i].g/2 || ball[i].x >= a-ball[i].g/2) { | |||
ball[i].vx = -ball[i].vx; | |||
} | |||
if (ball[i].y <= 0-ball[i].g) { | |||
ball[i].y = height; | |||
} | |||
if (ball[i].y >= height+ball[i].g) { | |||
ball[i].y = 0; | |||
} | |||
} | |||
for (int i=5; i < 10; i++) { | |||
ball[i].maleBall(); | |||
ball[i].x = ball[i].x + ball[i].vx; | |||
ball[i].y = ball[i].y + ball[i].vy; | |||
if (ball[i].x <= a+c+ball[i].g/2 || ball[i].x >= a+c+b-ball[i].g/2) { | |||
ball[i].vx = -ball[i].vx; | |||
} | |||
if (ball[i].y <= 0-ball[i].g) { | |||
ball[i].y = height; | |||
} | |||
if (ball[i].y >= height+ball[i].g) { | |||
ball[i].y = 0; | |||
} | |||
} | |||
for (int i=10; i < ball.length; i++) { | |||
ball[i].maleBall(); | |||
ball[i].x = ball[i].x + ball[i].vx; | |||
ball[i].y = ball[i].y + ball[i].vy; | |||
if (ball[i].x <= a+c+b+c+ball[i].g/2 || ball[i].x >= width-ball[i].g/2) { | |||
ball[i].vx = -ball[i].vx; | |||
} | |||
if (ball[i].y <= 0-ball[i].g) { | |||
ball[i].y = height; | |||
} | |||
if (ball[i].y >= height+ball[i].g) { | |||
ball[i].y = 0; | |||
} | |||
} | |||
} | |||
</source> | |||
== Objekt Ball == | == Objekt Ball == | ||
<source lang="Java">class Ball { | |||
int g; //Größe | |||
float x,y; //Position | |||
int h,s,b,a; //Farbe | |||
float vx,vy; //Geschwindigkeit | |||
Ball() { | |||
g = 100; | |||
vx = random(1,10); | |||
vy = random(1,10); | |||
h = (int)random(360); | |||
s = 100; | |||
b = 100; | |||
} | |||
void maleBall() { | |||
fill(h,s,b); | |||
ellipse(x,y,g,g); | |||
} | |||
} | |||
</source> |
Latest revision as of 19:26, 23 February 2011
Die Bildschirmgröße stimmt nicht für das Tischtheater. Sie ist an die Bildschrimgröße meines PCs angepasst, weil sonst nicht alles zu sehen war, eher gesagt, er hat das Bild abgeschnitten (wie in der gallery zu sehen).
Code
Ball[] ball = new Ball[15];
int a,b,c; //Abstände der Ebenen
void setup() {
size(1280,1024);
smooth();
noStroke();
colorMode(HSB,360,100,100,100);
a = 500; //erste Ebene
b = 400; //zweite Ebene
c = 40; //Lücke
for (int i=0; i < 5; i++) {
ball[i] = new Ball();
ball[i].x = random(ball[i].g,a-ball[i].g);
ball[i].y = random(ball[i].g,height-ball[i].g);
}
for (int i=5; i < 10; i++) {
ball[i] = new Ball();
ball[i].x = random(a+c+ball[i].g,a+c+b-ball[i].g);
ball[i].y = random(ball[i].g,height-ball[i].g);
}
for (int i=10; i < ball.length; i++) {
ball[i] = new Ball();
ball[i].x = random(a+c+b+c+ball[i].g,width-ball[i].g);
ball[i].y = random(ball[i].g,height-ball[i].g);
}
}
void draw() {
background(0);
fill(255);
rect(a,0,c,height);
fill(255);
rect(a+c+b,0,c,height);
for (int i=0; i < 5; i++) {
ball[i].maleBall();
ball[i].x = ball[i].x + ball[i].vx;
ball[i].y = ball[i].y + ball[i].vy;
if (ball[i].x <= 0+ball[i].g/2 || ball[i].x >= a-ball[i].g/2) {
ball[i].vx = -ball[i].vx;
}
if (ball[i].y <= 0-ball[i].g) {
ball[i].y = height;
}
if (ball[i].y >= height+ball[i].g) {
ball[i].y = 0;
}
}
for (int i=5; i < 10; i++) {
ball[i].maleBall();
ball[i].x = ball[i].x + ball[i].vx;
ball[i].y = ball[i].y + ball[i].vy;
if (ball[i].x <= a+c+ball[i].g/2 || ball[i].x >= a+c+b-ball[i].g/2) {
ball[i].vx = -ball[i].vx;
}
if (ball[i].y <= 0-ball[i].g) {
ball[i].y = height;
}
if (ball[i].y >= height+ball[i].g) {
ball[i].y = 0;
}
}
for (int i=10; i < ball.length; i++) {
ball[i].maleBall();
ball[i].x = ball[i].x + ball[i].vx;
ball[i].y = ball[i].y + ball[i].vy;
if (ball[i].x <= a+c+b+c+ball[i].g/2 || ball[i].x >= width-ball[i].g/2) {
ball[i].vx = -ball[i].vx;
}
if (ball[i].y <= 0-ball[i].g) {
ball[i].y = height;
}
if (ball[i].y >= height+ball[i].g) {
ball[i].y = 0;
}
}
}
Objekt Ball
class Ball {
int g; //Größe
float x,y; //Position
int h,s,b,a; //Farbe
float vx,vy; //Geschwindigkeit
Ball() {
g = 100;
vx = random(1,10);
vy = random(1,10);
h = (int)random(360);
s = 100;
b = 100;
}
void maleBall() {
fill(h,s,b);
ellipse(x,y,g,g);
}
}