Created
August 19, 2021 18:13
-
-
Save alisterburt/8134f0cd08f9479bb7386aea247abd0b to your computer and use it in GitHub Desktop.
2d interactivity with physics simulation in the background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
import napari | |
import numpy as np | |
from napari.qt.threading import thread_worker | |
viewer = napari.Viewer() | |
bbox_layer = viewer.add_points( | |
[[-1, -1], [-1, 1], [1, -1], [1, 1]], face_color='green') | |
points_layer = viewer.add_points([0, 0], face_color='magenta') | |
@thread_worker | |
def move_point_towards_center(): | |
while True: | |
sleep(1 / 60) | |
current_position = np.array(points_layer.data, dtype=float) | |
points_layer.data = current_position - current_position / 10 | |
return | |
worker = move_point_towards_center() | |
worker.start() | |
napari.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment