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 …“)
 
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);
  size(300,400);
  for(int i = 0; i < anzahl_autos; i++) {
  for(int i = 0; i < anzahl_autos; i++) {
    autos[i] = new Car(color(0,1,1),random(100),random(height),random(1,5));
    autos[i] = new Car(color(0,1,1),random(100),random(height),random(1,5));
  }
  }
}
}


void draw() {
void draw() {
  background(128);
  background(128);
  for(int i = 0; i < anzahl_autos; i++) {
  for(int i = 0; i < anzahl_autos; i++) {
    autos[i].move();
    autos[i].move();
    autos[i].display();
    autos[i].display();
  }
  }
}
}


--- TEIL2 ---
--- TEIL2 ---


class Car {  
class Car {  
  color c;
  color c;
  float xpos;
  float xpos;
  float ypos;
  float ypos;
  float xspeed;
  float xspeed;


  // The Constructor is defined with arguments.
  // The Constructor is defined with arguments.
  Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) {  
  Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) {  
    c = tempC;
    c = tempC;
    xpos = tempXpos;
    xpos = tempXpos;
    ypos = tempYpos;
    ypos = tempYpos;
    xspeed = tempXspeed;
    xspeed = tempXspeed;
  }
  }


  void display() {
  void display() {
    stroke(0);
    stroke(0);
    fill(c);
    fill(c);
    rectMode(CENTER);
    rectMode(CENTER);
    rect(xpos,ypos,20,10);
    rect(xpos,ypos,20,10);
  }
  }


  void move() {
  void move() {
    xpos = xpos + xspeed;
    xpos = xpos + xspeed;
    if (xpos > width) {
    if (xpos > width) {
      xpos = 0;
      xpos = 0;
    }
    }
  }
  }
}
}

Version vom 16. Juni 2009, 10: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;
    }
  }
}