Advertisement
xeromino

paolaExample

Aug 18th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. Particle[] particles = new Particle[10]; // an array of objects from the Particle class
  2.  
  3. void setup() {
  4.   size(500, 500);
  5.   for (int i=0; i<particles.length; i++) {
  6.     float x = i*50; // based on your example
  7.     float y = i*20; // I made something up
  8.     particles[i] = new Particle(x,y); // create new objects of the Particle kind
  9.   }
  10. }
  11.  
  12. void draw() {
  13.   background(255);
  14.   for (int i=0; i<particles.length; i++) {
  15.     particles[i].paint();  // draw the Particle objects
  16.   }
  17. }
  18.  
  19. class Particle {
  20.  
  21.   float x, y;
  22.   float sz = 10;
  23.  
  24.   Particle(float _x, float _y) {
  25.     x = _x;
  26.     y = _y;
  27.   }
  28.  
  29.   void paint() {
  30.     ellipse(x, y, sz, sz);
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement