Spot And Sketch Gets Seperated

the main sketch,
oo_sketch_6.pde

// Lesson 11: Object Oriented Coding.
 
/*
  The code of the class Spot is seperated into its own tab.
  Modularation of classes and abstraction of functionality makes for
  much cleaner and well organized code.
  This allows to experiment with more than one instance of spot.
*/
 
Spot sp1; // Declaring multiple instances
Spot sp2;
Spot sp3;
 
void setup() {
  size(100, 100);
  smooth();
  noStroke();
 
  sp1 = new Spot(33, 50, 30, 0.2); // creating new instances of Spot
  sp2 = new Spot(50, 20, 10, 1.5);
  sp3 = new Spot(70, 90, 35, 0.5);
}
 
void draw() {
  background(0);
 
  sp1.move(); // Move all spots to their new location
  sp2.move();
  sp3.move();
  sp1.display(); // Have all spots draw themselves
  sp2.display();
  sp3.display();
}

The class definition of Spot in a new tab
Spot.pde

/*
The definition of the class Spot is moved to its own file.
*/
 
class Spot {
  float x;
  float y;
  float diameter;
  float speed;
 
  Spot(float newx, float newy, float newd, float newSpeed) {
    x = newx;
    y = newy;
    diameter = newd;
    speed = newSpeed;
  }
 
  void move() {
    y = y + speed;
    if ((y < 0) || (y > height)) {
      speed = speed * -1;
    } 
  }
 
  void display() {
    ellipse(x, y, diameter, diameter);
  }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License