// ---------------------------------------------------------------------------------------------------------------- // Stimulus // ---------------------------------------------------------------------------------------------------------------- class Stimulus { // Variables int i_mystimulusType; float f_myX, f_myY, f_mystimulusStrength, f_switcherDiv = .5; color c_myColor; // Constructor (requires x and y coordinates, stimulus type, and stimulus strength Stimulus (float f_X, float f_Y, int i_stimulusType, float f_stimulusStrength) { f_myX = f_X; f_myY = f_Y; i_mystimulusType = i_stimulusType; f_mystimulusStrength = f_stimulusStrength; } // ---------------------------------------------------------------------------------------------------------------- UPDATE METHOD (usually called every time draw is calculated) void update() { // change the color of stimulus depending on the type if (i_mystimulusType == 1) { c_myColor = color(100, 100, 100); } if (i_mystimulusType == 2) { c_myColor = color(200, 100, 100); //stroke(200, 100, 100); } noFill(); stroke(c_myColor); pushMatrix(); translate(f_myX, f_myY); //rotate(radians(0)); // draw a circle to indicate the location of stimulus ellipse(0, 0, 10, 10); // draw another circle that is constantly changing to indicate its a live stimulus f_switcherDiv *= -1; stroke(c_myColor, 50); ellipse(0, 0, 15+f_switcherDiv, 15+f_switcherDiv); popMatrix(); } // ---------------------------------------------------------------------------------------------------------------- LOCATION METHODS // get x coordinate of stimulus float getlocationX() { return f_myX; } // get y coordinate of stimulus float getlocationY() { return f_myY; } // set x coordinate of stimulus void setlocationX(float f_newX) { f_myX = f_newX; } // set y coordinate of stimulus void setlocationY(float f_newY) { f_myY = f_newY; } // ---------------------------------------------------------------------------------------------------------------- EXTRA GET/SET METHODS // get stimulus strength float getstimulusStrength() { return f_mystimulusStrength; } // set stimulus strength void setstimulusStrength(float f_newstimulusStrength) { f_mystimulusStrength = f_newstimulusStrength; } // get stimulus type int getstimulusType() { return i_mystimulusType; } // set stimulus type void setstimulusType(int i_newstimulusType) { i_mystimulusType = i_newstimulusType; } // ---------------------------------------------------------------------------------------------------------------- EXTRA METHODS boolean dead() { return false; } } // ---------------------------------------------------------------------------------------------------------------- // StimulusSystem // ---------------------------------------------------------------------------------------------------------------- // keeps tracks of all stimuli and allows to easily add and remove sensors realtime class StimulusSystem { // Variables ArrayList stimuli; // Constructor (you can have the system start with a certian number of them at the start) StimulusSystem(int num) { stimuli = new ArrayList(); for (int i = 0; i < num; i++) { stimuli.add(new Stimulus(50, 50, 1, 100)); } } // ---------------------------------------------------------------------------------------------------------------- RUN METHOD (usually run at draw) // run all existing stimuli and remove any that are 'dead' from the list void run() { // look at all stimuli for (int i = stimuli.size()-1; i >= 0; i--) { // store current stimulus in s Stimulus s = (Stimulus) stimuli.get(i); // have that stimulus update s.update(); // chec if its dead if (s.dead()) { // remove dead stimulus stimuli.remove(i); } } } // ---------------------------------------------------------------------------------------------------------------- STIMULUS COORDINATE METHODS (needed to specify which sensor is being worked on) // get x location of stimulus float getlocationX(int i) { Stimulus s = (Stimulus) stimuli.get(i); return s.getlocationX(); } // get y location of stimulus float getlocationY(int i) { Stimulus s = (Stimulus) stimuli.get(i); return s.getlocationY(); } // set x location of stimulus void setlocationX(int i, float f_newX) { Stimulus s = (Stimulus) stimuli.get(i); s.setlocationX(f_newX); } // set y location of stimulus void setlocationY(int i, float f_newY) { Stimulus s = (Stimulus) stimuli.get(i); s.setlocationY(f_newY); } // ---------------------------------------------------------------------------------------------------------------- EXTRA GET/SET METHODS (needed to specify which sensor is being worked on) // get stimulus strength of stimulus i float getstimulusStrength(int i) { Stimulus s = (Stimulus) stimuli.get(i); return s.getstimulusStrength(); } // set stimulus strength of stimulus i void setstimulusStrength(int i, float f_newstimulusStrength) { Stimulus s = (Stimulus) stimuli.get(i); s.setstimulusStrength(f_newstimulusStrength); } // get stimulus type of stimulus i int getstimulusType(int i) { Stimulus s = (Stimulus) stimuli.get(i); return s.getstimulusType(); } // set stimulus type of stimulus i void setstimulusType(int i, int i_newstimulusType) { Stimulus s = (Stimulus) stimuli.get(i); s.setstimulusType(i_newstimulusType); } // ---------------------------------------------------------------------------------------------------------------- SPECIFIC ARRAYLIST MEHTHODS // fuction for adding a stimulus without any input void addStimulus() { stimuli.add(new Stimulus(50, 50, 1, 100)); } // function for adding a stimulus with input void addStimulus(Stimulus s) { stimuli.add(s); } // function for removing specific stimulus i void removeStimulus(int i) { //Sensor s = (Sensor) sensors.get(i); stimuli.remove(i); } // get number of stimulus in system int sizeStimulus() { return stimuli.size(); } // function to tell if there are any stimuli left boolean dead() { if (stimuli.isEmpty()) { return true; } else { return false; } } }