GMU:Immersive Strategien/Inhalte/Bälle/Code: Difference between revisions

From Medien Wiki
 
(7 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 ==


Ball[] ball = new Ball[15];
<source lang="Java">Ball[] ball = new Ball[15];
int a,b,c;
int a,b,c; //Abstände der Ebenen


void setup() {
void setup() {
Line 9: Line 10:
   smooth();
   smooth();
   noStroke();
   noStroke();
  //frameRate(5);
   colorMode(HSB,360,100,100,100);
   colorMode(HSB,360,100,100,100);
    
    
   a = 500;
   a = 500; //erste Ebene
   b = 400;
   b = 400; //zweite Ebene
   c = 40;
   c = 40; //Lücke
    
    
   for (int i=0; i < 5; i++) {
   for (int i=0; i < 5; i++) {
     ball[i] = new Ball();
     ball[i] = new Ball();  
   
     ball[i].x = random(ball[i].g,a-ball[i].g);
     ball[i].x = random(ball[i].g,a-ball[i].g);
     ball[i].y = random(ball[i].g,height-ball[i].g);
     ball[i].y = random(ball[i].g,height-ball[i].g);
   
    ball[i].h = (int)random(360);
   
    ball[i].vx = random(1,10);
    ball[i].vy = random(1,10);
   }
   }
    
    
   for (int i=5; i < 10; i++) {
   for (int i=5; i < 10; i++) {
     ball[i] = new Ball();
     ball[i] = new Ball();
   
     ball[i].x = random(a+c+ball[i].g,a+c+b-ball[i].g);
     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);
     ball[i].y = random(ball[i].g,height-ball[i].g);
   
    ball[i].h = (int)random(360);
   
    ball[i].vx = random(1,10);
    ball[i].vy = random(1,10);
   }
   }
    
    
   for (int i=10; i < ball.length; i++) {
   for (int i=10; i < ball.length; i++) {
     ball[i] = new Ball();
     ball[i] = new Ball();
   
     ball[i].x = random(a+c+b+c+ball[i].g,width-ball[i].g);
     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);
     ball[i].y = random(ball[i].g,height-ball[i].g);
   
    ball[i].h = (int)random(360);
   
    ball[i].vx = random(1,10);
    ball[i].vy = random(1,10);
   }
   }
}
}
Line 73: Line 55:
     }
     }
     if (ball[i].y >= height+ball[i].g) {
     if (ball[i].y >= height+ball[i].g) {
       ball[i].y = 0-ball[i].g;
       ball[i].y = 0;
     }
     }
   }
   }
Line 90: Line 72:
     }
     }
     if (ball[i].y >= height+ball[i].g) {
     if (ball[i].y >= height+ball[i].g) {
       ball[i].y = 0-ball[i].g;
       ball[i].y = 0;
     }
     }
   }
   }
Line 107: Line 89:
     }
     }
     if (ball[i].y >= height+ball[i].g) {
     if (ball[i].y >= height+ball[i].g) {
       ball[i].y = 0-ball[i].g;
       ball[i].y = 0;
     }
     }
   }
   }
}
}
</source>


== Objekt Ball ==
== Objekt Ball ==


class Ball {
<source lang="Java">class Ball {
    
    
   int g; //Größe
   int g; //Größe
Line 125: Line 108:
   Ball() {
   Ball() {
     g = 100;
     g = 100;
      
 
     vx = random(1,10);
    vy = random(1,10);
 
    h = (int)random(360);
     s = 100;
     s = 100;
     b = 100;  
     b = 100;  
Line 135: Line 122:
   }
   }
}
}
</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);
  }
}