Your sketch depends on frameCount
. Resetting the sketch would mean resetting the frameCount
. Unfortunately, the framecCunt
cannot be reset. You have to implement your own frameCount
:
Add a variable:
int myFrameCount = 0;
Increment the variable every frame and replace frameCount
with myFrameCount
in your code:
void draw() {
myFrameCount += 1;
// [...]
}
Reset the myFrameCount
when r is pressed:
void keyPressed() {
if (key == 'r') {
myFrameCount = 0;
}
}
Complete code:
int toggle =1;
int width=640;
int height=360;
int myFrameCount = 0;
void setup() {
size(1280, 720);
}
void draw() {
myFrameCount += 1;
background(255);
noStroke();
fill(0);
float s=5.0;
for (int i=0; i<height; i++) {
for (int j=0; j<width; j++) {
float x=noise(s*(j+5*myFrameCount)/width, s*i/height);
float y=noise(s*j/width, s*(i+3*myFrameCount)/height);
float x1=j + 18*map(x, 0, 1, -0.6, 0.6);
float y1=i + 18*map(y, 0, 1, -0.6, 0.6);
float t= map(cos(0.007*myFrameCount), -1, 1, 0.01, 0.0005);
float theta= lerp(noise(t*x1, t*y1 ), noise(4*t*x1, 4*t*y1 ), 0.2);
fill(map( cos(theta*0.04*(1+0.004*myFrameCount)/t), -1, 1, 0, 255));
rect( j*2, i*2, 2, 2);
}
}
}
void keyPressed() {
if (key == 'r') {
myFrameCount = 0;
}
}