GPN8:Processing-Workshop: Unterschied zwischen den Versionen
aus dem Wiki des Entropia e.V., CCC Karlsruhe
(Die Seite wurde neu angelegt: „==CAR== int anzahl_autos = 50; Car[] autos = new Car[anzahl_autos]; void setup(){ size(300,400); for(int i = 0; i < anzahl_autos; i++) { autos[i] = new …“) |
(→CAR) |
||
Zeile 1: | Zeile 1: | ||
==CAR== | ==CAR== | ||
int anzahl_autos = 50; | int anzahl_autos = 50; | ||
Car[] autos = new Car[anzahl_autos]; | Car[] autos = new Car[anzahl_autos]; | ||
void setup(){ | void setup(){ | ||
size(300,400); | |||
for(int i = 0; i < anzahl_autos; i++) { | |||
autos[i] = new Car(color(0,1,1),random(100),random(height),random(1,5)); | |||
} | |||
} | } | ||
void draw() { | void draw() { | ||
background(128); | |||
for(int i = 0; i < anzahl_autos; i++) { | |||
autos[i].move(); | |||
autos[i].display(); | |||
} | |||
} | } | ||
--- TEIL2 --- | --- TEIL2 --- | ||
class Car { | class Car { | ||
color c; | |||
float xpos; | |||
float ypos; | |||
float xspeed; | |||
// The Constructor is defined with arguments. | |||
Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) { | |||
c = tempC; | |||
xpos = tempXpos; | |||
ypos = tempYpos; | |||
xspeed = tempXspeed; | |||
} | |||
void display() { | |||
stroke(0); | |||
fill(c); | |||
rectMode(CENTER); | |||
rect(xpos,ypos,20,10); | |||
} | |||
void move() { | |||
xpos = xpos + xspeed; | |||
if (xpos > width) { | |||
xpos = 0; | |||
} | |||
} | |||
} | } |
Version vom 16. Juni 2009, 09:51 Uhr
CAR
int anzahl_autos = 50; Car[] autos = new Car[anzahl_autos];
void setup(){ size(300,400); for(int i = 0; i < anzahl_autos; i++) { autos[i] = new Car(color(0,1,1),random(100),random(height),random(1,5)); } }
void draw() { background(128); for(int i = 0; i < anzahl_autos; i++) { autos[i].move(); autos[i].display(); } }
--- TEIL2 ---
class Car { color c; float xpos; float ypos; float xspeed;
// The Constructor is defined with arguments. Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) { c = tempC; xpos = tempXpos; ypos = tempYpos; xspeed = tempXspeed; }
void display() { stroke(0); fill(c); rectMode(CENTER); rect(xpos,ypos,20,10); }
void move() { xpos = xpos + xspeed; if (xpos > width) { xpos = 0; } } }