Skip to content

Instantly share code, notes, and snippets.

@GuillaumeFavelier
Created January 10, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuillaumeFavelier/1bfa7ad2160d86b0814ed890dd7f27bc to your computer and use it in GitHub Desktop.
Save GuillaumeFavelier/1bfa7ad2160d86b0814ed890dd7f27bc to your computer and use it in GitHub Desktop.
Demonstration of PyVista with checkbox button
import pyvista as pv
import numpy as np
from pyvista import examples
mesh = examples.download_dragon()
p = pv.BackgroundPlotter()
# describe the movement
class Animate(object):
def __init__(self):
self.angle = 0
self.animation_state = False
def __call__(self):
if self.animation_state:
self.angle = (self.angle + 1) % 360
position = (
np.cos(self.angle * np.pi / 180.),
0.5,
np.sin(self.angle * np.pi / 180.)
)
p.camera_position = (
position,
(0, 0, 0),
(0, 1, 0)
)
p.reset_camera()
animate = Animate()
# define the animation switch
def toggle_animation(state):
animate.animation_state = state
p.add_mesh(mesh, smooth_shading=True, specular=1.0, color='green')
p.add_checkbox_button_widget(toggle_animation, value=False, color_on='green')
p.add_callback(animate, interval=16) # to be smooth on 60Hz
p.add_text("Animate", position=(70, 10))
p.enable_anti_aliasing()
p.hide_axes()
p.set_background(color='black')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment