ARTICLE AD BOX
I wanted to achieve the goal that creating a circle which keeps attracting the mouse cursor with no keyboard keypress hinting. Nevertheless, according to Benjamin Hackl, I only found that Manim CE provided a way that supports interaction with keypress hinting, which means that you can only make interaction through keypressing one key.
Here is the code:
class InteractivePyglet(Scene): def construct(self): # 1. Create a Manim object self.circ = Circle(fill_opacity=0.5, color=BLUE) self.sq = Square(color=RED).shift(RIGHT * 3) self.add(self.circ, self.sq) self.interactive_embed() def on_key_press(self,symbol, modifiers): from pyglet.window import key as pyglet_key """ When pressing key S, the circle will then move to the mouse cursor""" if symbol==pyglet_key.S: mouse_pos = self.mouse_point.get_center() # Make the circle follow the mouse self.circ.move_to(mouse_pos) # Logic: Change square color if circle is near if np.linalg.norm(self.circ.get_center() - self.sq.get_center()) < 2: self.sq.set_color(YELLOW) else: self.sq.set_color(RED) # I used "manim -qm -p --renderer=opengl file.py InteractivePyglet to render this scene to make interaction.I tried the code
class InteractivePyglet(Scene): def construct(self): # 1. Create a Manim object self.circ = Circle(fill_opacity=0.5, color=BLUE) self.sq = Square(color=RED).shift(RIGHT * 3) self.add(self.circ, self.sq) self.interactive_embed() def on_mouse_motion(self,symbol, modifiers): #trying to use om_mouse_motion to replace om_key_press to achieve goal mouse_pos = self.mouse_point.get_center() # Make the circle follow the mouse self.circ.move_to(mouse_pos) # Logic: Change square color if circle is near if np.linalg.norm(self.circ.get_center() - self.sq.get_center()) < 2: self.sq.set_color(YELLOW) else: self.sq.set_color(RED)But it didn't work as expected. Are there any ways to make immediate interaction
