I need to write a program whereby, a ball of radius 40 is moved randomly within a red circle of framesize (300,300) when a button is clicked. However, i can only manage the ball to move all around the frame, how can i ge it to move within the red circle only? Any help would be greatly appreciated! Thanks! Im a beginner so detailed explanations would be better. Thanks again.
Well my best guess for that would be to use a fixed starting point for your ball and then subtract or add x and y values to that origin value. To decide what to add you will have to write an equation.
To help you see this better get a piece of paper and a pencil. Draw a line from the center to the edge. Now draw a two lines from the endpoints of that line to make a right triange. The radius of the circle, aka the hypotenuse of your triange, has a lenght equal to ((x^2)+(y^2))^(1/2). Thank Unckle Pythagoras for that one.
If you solve out the algebra you should be able to generate a y value between the + and - absolute value of the radius and run that thru the equation to find the appropriate x value.
keep in mind that there is always,excepting y=raduis, a positive and a negative posiblity for x. I hope this helps.