Проблемы с взаимодействием Manim с сохранением обновлений без взаимодействия с клавиатуройPython

Программы на Python
Ответить
Anonymous
 Проблемы с взаимодействием Manim с сохранением обновлений без взаимодействия с клавиатурой

Сообщение Anonymous »

Я хотел достичь цели — создать круг, который будет притягивать курсор мыши без подсказок по нажатию клавиш на клавиатуре. Тем не менее, по словам Бенджамина Хакла, я обнаружил только, что Manim CE предоставляет способ, поддерживающий взаимодействие с подсказками по нажатию клавиш, что означает, что вы можете взаимодействовать только посредством нажатия одной клавиши.
Вот код:

Код: Выделить всё

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.
Я попробовал код

Код: Выделить всё

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)
Но это не сработало так, как ожидалось.
Есть ли способы немедленного взаимодействия


Подробнее здесь: https://stackoverflow.com/questions/798 ... nteraction
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»