Spot Can Draw Itself
// Lesson 11: Object Oriented Coding.
 
/*
 The class spot now has a display() method,
 which we call in our original draw() function. 
*/
 
Spot sp;
 
void setup() {
  size(100, 100);
  smooth();
  noStroke();
 
  sp = new Spot(); // creating new instance of spot
  sp.x = 33; // set variables of the instance
  sp.y = 50;
  sp.diameter = 30;
}
 
void draw() {
  background(0);
  sp.display(); // calling the display method of Spot to make it draw itself
}
 
// ----------------------------
// Definition of the class Spot
 
class Spot {
  float x;
  float y;
  float diameter;
 
  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