How do I animate the second ellipse to fly around the screen and bounce off the walls?

function draw()
    fill(0, 16, 255, 255)
    background(0, 0, 0, 255)
    stroke(255, 84, 0, 255)
    strokeWidth(3)
    ellipse( CurrentTouch.x, CurrentTouch.y, 100)
    
    
    fill(255, 29, 0, 255)
    ellipse(400, 400, 50)
  
    
    
    





  end
    
    
    
    
    

I tried looking at examples but I still don’t understand.

I would use physics, look at Here for that

( I don’t mean the Physics lab type, but like velocity, acceleration, gravity, that sort of thing)

You can do this without physics, as long as the ellipses don’t have to bounce off each other, just off walls…

  1. Set an x and y value for the number of pixels the ellipse moves each time it draws, eg x=2, y=-3 (maybe use random numbers to set them), as well as a starting position

  2. In draw, add x to the current x value and y to the current y value

  3. Then check if x>WIDTH-EllipseDiameter/2 or x<EllipseDiameter/2. If so, you say x=-x, ie if you were adding pixels before each time, now you will subtracting them, so the ellipse reverses direction

  4. Do the same for y, using HEIGHT instead of WIDTH

The reason for subtracting half the diameter of the ellipse above is that if the ellipse is centred at X,Y, then its left hand side is at X-EllipseDiameter/2, and you want to bounce when that edge reaches the left hand side.

@Ignatz thank you! Your always the one that helps me the most!(:

@Willkassens - if you say that, then you obviously have not come across dave1707 (and a few others I can think of)!

The best thing about this forum is that all the regulars are very helpful.