background color based on array
in
Programming Questions
•
2 years ago
I am trying to have the background color change based on which position of the array the timer is at--I want it to alternate between red and green based- I have an if statement that isnt working, it says || is undefined in a boolean and also that my timerData[] cannot be converted from an int. Please Help!
- Timer timer;
- //int timerData[]= {31,55,30,56,29,56};
- int timerData[]= {3,5,3,5,2,5};
- int dataCounter = 0;
- void setup(){
- size(400,400);
- timer = new Timer(timerData[0]);
- timer.start();
- }
- void draw() {
- if(timer.isFinished()){
- if(timerData[1] || timerData[3] || timerData[5]){
- background(255,timerData[dataCounter], timerData[dataCounter]);
- dataCounter = (dataCounter + 1) % timerData.length;
- timer = new Timer(timerData[0]*1000);
- println(timerData[dataCounter]);
- timer.start();
- } else if (timerData[0] ) timerData[2] || timerData[4]){
- background(timerData[dataCounter],255, timerData[dataCounter]);
- dataCounter = (dataCounter + 1) % timerData.length;
- timer = new Timer(timerData[0]*1000);
- println(timerData[dataCounter]);
- timer.start();
- }
- }
- }
- class Timer {
- int savedTime; // When Timer started
- int totalTime; // How long Timer should last
- Timer(int totalTime_) {
- totalTime = totalTime_;
- }
- // Starting the timer
- void start() {
- // When the timer starts it stores the current time in milliseconds.
- savedTime = millis();
- }
- // The function isFinished() returns true if "totalTime" has passed.
- // The work of the timer is farmed out to this method.
- boolean isFinished() {
- // Check how much time has passed
- int passedTime = millis()- savedTime;
- if (passedTime > totalTime) {
- return true;
- } else {
- return false;
- }
- }
- }
1
