[Tutor] circular movement in pygame

Dave Angel davea at davea.name
Wed Apr 29 14:32:29 CEST 2015


On 04/29/2015 03:15 AM, diliup gabadamudalige wrote:
> Thanks all for the responses.
> Charles Cossé -  yes I can write a simple pygame program that makes a
> sprite move in a circle but it may not be the style and order that many may
> approve or accept. I consider myself a student. :)
> No one has pointed out why the object moves in a circle properly in the bit
> of code where it is addressed directly and why it does not when the same
> code is applied thru a class.
> I know that an object can be made to move around the circumference of a
> circle by constantly calculating the point and giving the x and y values
>
> 1. x = some code
>
> That is what I used and it worked. I was trying to find how we can do the
> same thing by updating the current position by doing
>
> 2. x += some code

2.  x +=  some different code

>   Above 1 works. 2 does not. Why is that?

Because there is always some little error in the value you're adding to 
x, since it's a floating point value calculated using transcendentals. 
If you're going to loop thousands of times, those little errors add up.

Sometime try measuring a mile using two 12-inch rulers, placing each one 
before picking up the previous. By the time you're done, you'll probably 
be off a hundred feet.


>
> Both the same code.

Not at all the same.

> The same variable is used with different names cause
> some others were confused when they were the same.
>
>   I hope this time I have answered correctly. No more attachments. (e mail
> or otherwise. :) )
>

I can't necessarily understand the code since you use pygame and I'm not 
familiar with pygame.  In your itertools loop, you always reset the 
angle back to 100 degrees.

In your while loop, you issue a call to draw.circle().  Perhaps that's 
the working code you're talking about.



-- 
DaveA


More information about the Tutor mailing list