// ---------------------------------------------------------
// Class: Wheel
// ---------------------------------------------------------
// Two wheels for each vehicle perform its movement.
// ---------------------------------------------------------

import processing.*;
import processing.core.*;

class Wheel {

  float x, y;
  float angvel, linvel; // angular and linear velocity
  float radius; // wheel radius
  float ang; // wheel angle used for drawing wheels with wiggle

  // Constructor
  // -----------------------------
  Wheel(float x, float y, float radius, float angvel) {
    this.x = x;
    this.y = y;
    this.radius = radius;
    this.angvel = angvel;
    linvel = angvel * radius; // linear velocity is angular velocity * radius
    ang = 0;
  }

  // Set the angular velocity of this wheel
  // -----------------------------
  void setVelocity(float angvel) {
    this.angvel = angvel;
    
    // linear velocity updated based on wheel radius and angular velocity
    linvel = angvel * radius; 
  }

  // Draw Me!
  // -----------------------------
  void drawMe(PApplet pa, float a, int dir, float bigg) {
    // make the wheel wiggle based on its angular velocity
    ang += angvel;   
    if (ang > pa.TWO_PI) {
      ang -= pa.TWO_PI;
    }
    float fa = a + pa.HALF_PI * pa.sin(ang);
    float n = 10*dir;
    
    // do the drawing
    pa.ellipse(x + n*pa.cos(fa),y + n*pa.sin(fa),2*bigg,2*bigg);

  }
}
