sliders2.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Sliders and buttons controlling objects"""
  2. from vedo import *
  3. settings.use_depth_peeling = True
  4. def slider0(widget, event):
  5. sphere.color(widget.value)
  6. def slider1(widget, event):
  7. val = widget.value
  8. widget.title = get_color_name(val)
  9. cube.color(val)
  10. def button_func(obj, event):
  11. cube.alpha(1 - cube.alpha()) # toggle mesh transparency
  12. sphere.alpha(1 - sphere.alpha())
  13. button.switch() # change to next status
  14. ######
  15. sphere = Sphere(r=0.6).lw(1).color(0).alpha(0.8)
  16. cube = Cube().lw(1).color(0).alpha(0.8)
  17. plt = Plotter(N=2, axes=True)
  18. ######
  19. plt.at(0).show(sphere, __doc__) # show the sphere on the first renderer
  20. plt.add_slider(
  21. slider0,
  22. -9, 9, # slider range
  23. value=0, # initial value
  24. pos=([0.1,0.1], # first point of slider in the renderer
  25. [0.4,0.1]), # 0.4 = 40% of the window size width
  26. title="slider nr.0, color number",
  27. )
  28. ######
  29. plt.at(1).show(cube)
  30. plt.add_slider(
  31. slider1,
  32. -9, 9,
  33. value=0,
  34. pos=([0.1,0.1], [0.4,0.1]),
  35. title="slider nr.1, color number",
  36. )
  37. ######
  38. button = plt.at(1).add_button(
  39. button_func,
  40. pos=(0.5, 0.95), # x,y fraction from bottom left corner
  41. states=["HIGH alpha (click here!)", "LOW alpha (click here!)"],
  42. c = ["w", "k"], # colors of states (foreground)
  43. bc= ["k", "grey"], # colors of states (background)
  44. font="Quikhand",
  45. size=35,
  46. )
  47. plt.show().interactive().close()