|
|
Zeile 1: |
Zeile 1: |
| ==CAR==
| | [http://todbot.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class4.pdf Arduino&Processing] |
|
| |
|
| int anzahl_autos = 50;
| | [http://todbot.com/blog/bionicarduino/ Beispiele & PDFs] |
| 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;
| |
| }
| |
| }
| |
| }
| |
|
| |
|
|
| |
|
| [[Kategorie:GPN8]] | | [[Kategorie:GPN8]] |