[Tutor] Fwd: circular movement in pygame

diliup gabadamudalige diliupg at gmail.com
Wed Apr 29 10:13:49 CEST 2015


question to Lucas.

Not sure if this is what you're looking for, but I would also use cos for
the x coordinate as suggested.  If:

self.rect.x = self.radius * math.cos(self.angle) + self.center_x
self.rect.y = self.radius * math.sin(self.angle) + self.center_y

Take a derivative (assume:  angle += angular_vel * dt for every increment
in time dt), so that:

self.rect.x += -self.radius * math.sin(self.angle) * self.angular_vel * dt
self.rect.y += self.radius * math.cos(self.angle) * self.angular_vel * dt

what is dt?


On Wed, Apr 29, 2015 at 12:45 PM, diliup gabadamudalige <diliupg at gmail.com>
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
>  Above 1 works. 2 does not. Why is that?
>
> Both the same code. 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. :) )
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**********************************************************************************************


More information about the Tutor mailing list