Created
November 26, 2014 15:18
-
-
Save ollpu/cf0b077612f9b574bd12 to your computer and use it in GitHub Desktop.
Scheduler Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scheduler sched = new scheduler("drawSomething"); | |
void setup() { | |
size(500, 500); | |
sched.scheduleLoopingTask(1000); | |
frameRate(2); | |
} | |
void draw() { | |
background(0); | |
} | |
void callSchedulerDoWork() { | |
sched.doWork(); | |
} | |
class scheduler { | |
int timer; | |
boolean timing; | |
String call; | |
scheduler(String whatToCall) { | |
timer = 0; | |
call = whatToCall; | |
} | |
void scheduleLoopingTask(int interval) { | |
timer = interval; | |
timing = true; | |
thread("callSchedulerDoWork"); | |
} | |
void stop() { | |
timing = false; | |
} | |
//Requires to be executed in a thread to not obstruct rest of the program | |
void doWork() { | |
while (timing) { | |
thread(call); | |
delay(timer); | |
} | |
} | |
} | |
void drawSomething() { | |
println("jeee"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment