How to make a ball bounce

How do i make a ball bounce? all of the tutorials I've seen talk about the angle of the wall, but this ball is inside of a circle so it's bouncing off of rounded edges. Could anyone help me out?
Snap! ball bounce thing (berkeley.edu)

When the ball hits the edge, mentally draw the line tangent to the circle at that point. (It'll be perpendicular to the radius to that point.) You measure angles with respect to that tangent line.

How much math do you know? Algebra? Algebra II? Analytic geometry?

You may want to make a drawing with arrows denoting directions, then try to complete this script:

Hardly any goniometry required :smirk:

what if the ball falls down vertically and hits an angle? surely its not that easy...

EDIT: just reread the question. sorry. i guess this would work if I understand it correctly

My model (and it's up to the OP to complete it) only accounts for fully elastic bounces against a circular wall, with (0, 0) as its center, in 2D. The ball is supposed tgo hit the wall from the inside, at any angle between -90 and +90 degrees. My model does not take into account, e.g.: rotation, rotational inertia, friction, deformation, kinetic energy loss, ... (you can make this list as long as you like) ... gravitation, 3D, ...

I'm pretty sure I've done geometry 1 and 2 and algebra 1 and 2. just junior cycle (Ireland) maths.

what does sum and r^2 mean? i thought that the sum of something would be of 2 numbers and it's just the equivalent of x+y. And i know ^2 is to the power of 2 or squared but what's r?

Position is a list of x-position and y-position. Position * position is a list of (x * x) and (y * y). Sum (position * position) is the sum of the items, so x^2 + y^2. And r^2 is (radius * radius).
So the first test is whether the center of the ball is inside the circle’s perimeter.

Be aware my script is pseudo-code.

Okay, so, stop me when I say something you haven't seen before... You hit the circle at a point (x,y). (The circular barrier in your project is thick, but all the action happens at its inner edge, so take that inner edge as the circle. This may mean that its radius is a little less than you think it is.) Draw the radius from the center (0,0) to (x,y). Its slope is y/x. Since the tangent at (x,y) is perpendicular to the radius (if that's not obvious, consider that the picture has to be symmetrical across the radius), the slope of the tangent is the negative reciprocal of the slope of the radius, so -x/y. So the angle between the tangent and the x axis is arctan(-x/y).

Now you can add to the picture your moving ball, which is moving at a particular slope, i.e. a particular angle relative to the axes. When you know that angle, you're ready to use the law of reflection.

Snap! 's Logic programming SICP script pic (5) block is great, as it actually looks at the signs of x and y instead of the sign of the quotient: Logic programming SICP script pic (6).

I'd love to take credit for it, but I think we just use the Javascript math library. :~)

took a couple reads to fully grasp it but that makes sense to me!! I've got a vauge idea on how i can write that in code so I'll give it a go now. @qw23 thanks for the code i'll use that to fall back on if i'm stuck. Thank you everyone for the help!! :blush:
apologies for the late response I've been really busy in the last couple of days. :>