How to start an animation again from the beginning at specific point

Yep, that’s the thing where I need some help and advice. How to set it the way that it runs the animation from beginning, and at the specific point the animation starts again from the beginning and runs again at the same specific point and runs like this endlessly.

I don’t really know how to describe that correctly but hopefully you get the idea.

When you have eg a ball than runs and you register that the animation is over (ball at target or something similar) you want to give all the necessary variables the values you gave them before or in setup () or that they have automatically.

Please don’t run setup again, but you can move relevant lines from setup() into a new function init that you might call from setup() and on restarting the animation.


I didn’t get what you mean but thanks. I’m new at processing so more in depth advice would be needed. Maybe I’m just trying to create too complicated animation/motion thing.

example how to use a “INIT” at setup and keyPressed

int posx,posy;

void setup() {

void init() {
  posx = width/2;
  posy = height/2;

void draw() {

void move() {
  posx += int(random(-2,2)); 
  posy += int(random(-2,2));

void keyPressed() {
  if ( key == 'r' ) init(); 


to get more help post your code —

then we can look into it

In p5.js, you can create a button out of setup, assign a button inside setup with a function, and have that function called when a condition is met in draw. i’ve been trying to implement the same idea in processing, but i still need to do my homework.

here’s the general idea

when you click the x button next to Dijkstra, it calls a setup function,

function setup (){
pathreset = new button({
  onClick: function(){

void button(){

  void hidden (){

Sorry if this is unclear Im still very new to processing. However if the logic is the same as p5, and you can create a new a function within the property of the constructor then you can do that.

Alternatively if you don’t need a function and just want the position of the object at a particular time, so it can be reinstated later that would just require you to have global variable for the objects or, your function would need to be able to call the objects properties.

What kind of animation? Is this a sprite? Or a cartoon that you are loading a bunch of hand-drawn images for, like a flip-book? Or is it a video clip that you made / found? Or is it geometric animation, like a bouncing ball or a group of lines? This matters for choosing the best approach.

Also, will it be the only thing in the sketch, or is the looping animation only one of the elements on the screen? There are ways to start the whole sketch over – e.g. resetting frameCount – but that won’t work if the animation is looping while other things aren’t looping.