[Tutor] Fwd: circular movement in pygame

Alan Gauld alan.gauld at btinternet.com
Wed Apr 29 18:30:33 CEST 2015


On 29/04/15 10:15, diliup gabadamudalige wrote:
> x=42 good
> x += 42 -x ?
>
> That does not go by a mile of what I asked.

You've asked three different things:

1) Why the += form gives different results from the assignment form,
2) Why some code you apparently wriotre worked outside a class
    but not in a class
3) A specific question about some code for moving an object
    in PyGame around in a circle

Number 1 is the only one I can comment on as I can't see your 
attachments. That is what I (and several others) have answered.
They are fundamentally different. There is no general way
to make an augmented assignment such that

x = f(y) and
x += f(y)  (or even g(y))

produce the same result except by the trivial

x += g(y) - x

> Alan, are you telling me that there is no way that one can arrive at X2
> which is the NEXT place that X1 will be after "some increment"?
> old x position = X1

No, that is a completely separate question and has nothing
to do with using augmented assignment. But it does depend
on the specifics of the situation and is mainly a mathematical
problem rather than a Python one..

> new x position= X1 + some increment value
> which can be written as :new X = oldX + some increment value
>
> which can be simplified to X += some increment value?

That may or may not be possible, it depends on what the
original equation in the pure assignment model is.

> my orginal question was
>
> *Why does the object NOT move in a circle when implemented as a class?*

Your original question was:

is there a way to do
self.rect.x +*= some value*
self.rect.y += some value

rather than

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

Which is about the use of augmented assignment.

> All the code was provided.

No it wasn't. I have not seen any of your code because you persist
in sending it as attachments which (as you've been told) do not
work reliably in a text based mailing list. If you want
comments on the code either post it inline in your message
or as a link to a web site where we can all see it.

> The above is  what I asked. (I hope this is clear enough)

Your class based code should work but without sight of it
I cannot begin to guess about that aspect of your problem.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list