Encapsulate Example 13-6 into an Oscillator class. Create an array of Oscillator objects, each moving at different rates along the x and y axes. Here is some code for the Oscillator class to help you get started.

class Oscillator  {   
  
  float xtheta;  
  float ytheta;  
  ___________________________________________ 
  ___________________________________________ 
  
  Oscillator()  {   
    xtheta = 0;  
    ytheta = 0;  
    __________________________________________  
    __________________________________________  
  }   
  
  void oscillate()  {   
    __________________________________________  
    __________________________________________  
  }   
  
  void display()  {   
    float x = ____________________________________________  
    float y = ____________________________________________  
    ellipse(x,y,16,16);  
  }
  
}   
Example
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Exercise 13-6: Encapsulate Example 13-6 into an Oscillator object. Create an array 
// of Oscillators, each moving at diff erent rates along the x and y axes. Here is some code for the 
// Oscillator class to help you get started.  

// An array of objects
Oscillator[] oscillators = new Oscillator[10];

void setup()  {   
  size(200,200);  
  smooth();  
  // Initialize all objects
  for (int i = 0; i < oscillators.length; i++) {
    oscillators[i] = new Oscillator();
  }
}   

void draw() {   
  background(255);  
  // Run all objects
  for (int i = 0; i < oscillators.length; i++) {
    oscillators[i].oscillate();
    oscillators[i].display();
  }
}   
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Exercise 13-6: Encapsulate Example 13-6 into an Oscillator object. Create an array 
// of Oscillators, each moving at diff erent rates along the x and y axes. Here is some code for the 
// Oscillator class to help you get started.  

class Oscillator  {   

  // Two angles
  float xtheta;  
  float ytheta;
  // Increment value for both angles  
  float dxtheta;
  float dytheta;

  Oscillator()  {   
    xtheta = 0;  
    ytheta = 0;  
    // Start randomly
    dxtheta = random(-0.05,0.05);
    dytheta = random(-0.05,0.05);
  }   

  void oscillate()  {
    // Increment angles   
    xtheta += dxtheta;
    ytheta += dytheta;
  }   

  void display()  {   
    // Map results of sine / cosine to width and height of window
    float x = (sin(xtheta) + 1) * width/2;   
    float y = (cos(ytheta) + 1) * height/2;
    stroke(0);
    fill(175);
    // draw circle and line
    line(width/2,height/2,x,y);  
    ellipse(x,y,16,16);  
  }

}