I startet doing maths animations with manim
and have the following code:
image = ImageMobject("image.png")
image.move_to(point)
image = always_redraw(lambda: image.rotate(angle=function(x)), about_point=point))
i want the image being rotated in absolute terms, for example if function(x)
at first equals 20, then the image should be rotated 20, when the function next gives 30, the image should be rotated from the initial 20 to 30, not to 50. but the code above rotates to 50, it adds to the previous state. is there a possibility to rotate in absolute terms, not in relative terms?
It does not "add" to the previous state, but it actually starts from the previous, already rotated state. Also since an always_redraw
is executed for every single frame in an animation, I don't know if this is really what you want.
I would suggest that you
a) define a ValueTracker
object for the rotation angle
b) keep an unrotated original version of the image
c) in an updater function make sure that the existing object is replaced by a new, rotated version of the image
in principle like this, but something seems still to be wrong:
class rotImage(Scene):
def construct(self):
image = ImageMobject(r"bilder\192x192RedPushPinIcon_Scala.png")
imageAngle = ValueTracker(0)
imageOnScene = image.copy().move_to([2,2,0])
def imageUpdater(mobj):
dummy = image.copy().move_to(mobj.get_center())
dummy.rotate(imageAngle.get_value(), about_point=dummy.get_center())
mobj.become(dummy)
imageOnScene.add_updater(imageUpdater)
self.add(imageOnScene)
self.wait()
self.play(imageAngle.animate.set_value(2*PI), rate_func=rate_functions.linear, run_time=3)
self.wait()