Yes, this is possible. Just make everything dependent on a time variable.
Then when you go back and forth in time, it will have an impact on the output. See the below code example that uses
controlP5 for the sliders. It already has a pause button, but implementing playing backwards, speed up or slow-motion would all be very easy to implement in a sketch like this (hint: playing with time directly affects the output).
- import controlP5.*;
- ControlP5 controlP5;
- int time;
- boolean playPause = true; // true = play, false = pause
- void play() { playPause = !playPause; } // toggle
- void setup() {
- size(500,500);
- frameRate(30);
- smooth();
- controlP5 = new ControlP5(this);
- controlP5.addSlider("time",0,width,10,height-30,width-75,20);
- controlP5.addButton("play",0,width-40,height-30,30,20);
- }
- void draw() {
- background(125);
- if (playPause) { time++; controlP5.controller("play").setLabel("Pause"); }
- else { controlP5.controller("play").setLabel("Play"); }
- if (time >= width) { time = 0; } // reset when right side is reached (only useful for this particular sketch)
- controlP5.controller("time").setValue(time); // set the slider to time value
- randomSeed(1); // controls the randomness, to get the same output every time
- for (int i=0; i<time; i++) { // the time variable controls the output
- float c = map(i,0,time,0,255);
- fill(c,c);
- ellipse(i%width,random(height),40,40);
- }
- }