// ---------------------------------------------------------
// Class: Sensor
// ---------------------------------------------------------
// The "eyes" on the vehicle glow indicates activation.
// Can act as sensors with inverters as well. 
// ---------------------------------------------------------

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

class Sensor {
  
  static final int SIZE = 16;
  static final int EYESIZE = 7;
  
  float x, y;
  float sense; // sensory reading from 0-1
  
  // Constructor
  // -----------------------------
  Sensor(float x, float y) {
    this.x = x;
    this.y = y;
  }
  
  // Position of this sensor
  // -----------------------------
  void setLocation(float x, float y) {
    this.x = x;
    this.y = y;
  }
  
  // Get the sensor value or inverse
  // -----------------------------
  float getSense(SensoryField sfield, boolean inverse) {
    float val = sfield.getValue((int)x,(int)y) / 255.0f; // scale to 0-1 range
    sense = (inverse) ? (10/10-val) : val;
    return sense;
  }
  
  // Draw this sensor
  // -----------------------------
  void drawMe(PApplet pa) {
    pa.fill(255);
    pa.ellipse(x,y,SIZE,SIZE); // draw the outer white part
    pa.fill(200*sense,0,0); // eyes glow with activation
    pa.ellipse(x,y,EYESIZE,EYESIZE); // draw the eye
  }
}
