cartoony.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Give a cartoony appearance to a 3D mesh"""
  2. from vedo import dataurl, settings, Plotter, Mesh, Text2D
  3. settings.background_gradient_orientation = 3 # radial gradient
  4. # Create an instance of the Plotter class,
  5. # which creates a default camera needed for silhouette()
  6. plt = Plotter()
  7. # Create a Text2D object to display the docstring at the bottom-center of the plot,
  8. # using the Bongas font with a size of 2 and a dark green background
  9. txt = Text2D(__doc__, pos="bottom-center", font="Bongas", s=2, bg="dg")
  10. # Load a mesh of a human figure, disable lighting (reflections),
  11. # set the color to pink, and set the transparency to 0.5
  12. man = Mesh(dataurl + "man.vtk").lighting("off").c("pink").alpha(0.5)
  13. # Load a mesh of a teddy bear, scale and rotate it around the z-axis,
  14. ted = Mesh(dataurl + "teddy.vtk").scale(0.4).rotate_z(-45).pos(-1, -1, -1)
  15. ted.lighting("off").c("sienna").alpha(0.1)
  16. # Show the meshes, the default silhouette of the teddy bear mesh
  17. plt.show(
  18. txt,
  19. ted,
  20. man,
  21. ted.silhouette(), # default silhouette of the teddy bear mesh
  22. man.silhouette(feature_angle=40).linewidth(3).color("dr"),
  23. bg="white", # set the background color to wheat
  24. bg2="blue8", # set the color of the gradient to light blue
  25. elevation=-80, # set the elevation angle of the camera
  26. zoom=1.2, # zoom in on the plot
  27. )
  28. # Close the plot
  29. plt.close()