A Class Called Spot
// Lesson 11: Object Oriented Coding.
 
// Introduction of a class Spot
 
// Declare the variable 'sp' as an instance of the class 'Spot'
Spot sp;
 
void setup() {
  size(100, 100);
  smooth();
  noStroke();
 
  // Initialize the variable 'sp' by creating a new instance of the class 'Spot'
 
  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);
  ellipse(sp.x, sp.y, sp.diameter, sp.diameter); // use the variables inside the class
}
 
// Definition of the class Spot
// Class names always start with a capital by convention. 
class Spot {
  float x;
  float y;
  float diameter;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License