Manim-Interaktionsprobleme durch ständige Aktualisierung ohne TastaturinteraktionPython

Python-Programme
Anonymous
 Manim-Interaktionsprobleme durch ständige Aktualisierung ohne Tastaturinteraktion

Post by Anonymous »

Ich wollte das Ziel erreichen, einen Kreis zu erstellen, der den Mauszeiger ständig anzieht, ohne dass ein Tastendruck auf der Tastatur angezeigt wird. Laut Benjamin Hackl habe ich jedoch nur herausgefunden, dass Manim CE eine Möglichkeit bietet, die Interaktion mit Tastendruckhinweisen zu unterstützen, was bedeutet, dass Sie nur durch Tastendruck einer Taste interagieren können.
Hier ist der Code:

Code: Select all

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.
Ich habe den Code ausprobiert

Code: Select all

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)
Aber es hat nicht wie erwartet funktioniert.
Gibt es Möglichkeiten für eine sofortige Interaktion?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post