one possibility is to move your rossler equations into update() method and use a PathRecorder.
here is a similar example… you will need to press “play” for this to work.
SLIDER(center_x, -1..1);
SLIDER(center_y, -1..1);
SLIDER(k, 0..1);
SLIDER(timebase, 0.1..10).setDefaultValue(1);
#include <PathRecorder.h>
vec3 pos;
vec3 vel;
PathRecorder<100> history;
void setup(){
// give some initial position and velocity
pos = vec3(0, 0.5);
vel = vec3(0, 0.1);
}
void update(){
int subdiv = 128;
if(beatgrid(1,subdiv)){
vec3 delta = (pos - vec3(center_x, center_y));
float len_x = abs(delta.x);
float len_y = abs(delta.y);
// F=-kx is roughly hooks law, i think
vec3 F = -k*delta;
// use F=ma, assume m=0.001 and solve. so a = F/m = F/0.0001
vec3 acc = F/0.0001;
// now integrate
double dt = 1.0/subdiv;
vel += acc*dt;
pos += vel*dt;
// a bit nasty, but we dissipate some energy. friction maybe?
vel -= vel*dt;
// also nasty, but we clamp the position
pos.x = clamp(pos.x, -1, 1);
pos.y = clamp(pos.y, -1, 1);
history.add(pos);
}
}
vec3 gen(float t){
vec3 v;
v = history.gen(tri(t), false);
return v;
}
ps. the if(beatgrid(1,subdiv))
ties the simulation speed to the currently set bpm. you can eliminate this, but then the equation will run differently depending on your sample rate.
an alternative to this is to add a tick phasor at the top, like PHASOR(tick).setRange("freq",1,50)
and use if(tick.didReset)
in the update method. this gives you completely steady simulation updates without any binding to sample rate or bpm.