colorcubes.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """Show a cube for each available color name"""
  2. from operator import itemgetter
  3. from vedo import Cube, Text2D, show, settings
  4. from vedo.colors import colors
  5. # Print the docstring
  6. print(__doc__)
  7. # Set immediate rendering to False for faster rendering with multi-renderers
  8. settings.immediate_rendering = False
  9. # Sort the colors by hex color code (matplotlib colors)
  10. sorted_colors1 = sorted(colors.items(), key=itemgetter(1))
  11. # Create a list of cubes for each color name
  12. cbs=[]
  13. for sc in sorted_colors1:
  14. # Get the color name
  15. cname = sc[0]
  16. # Skip the color if it ends in a number
  17. if cname[-1] in "123456789":
  18. continue
  19. # Create a cube and text object for the color name
  20. cb = Cube().lw(1).color(cname)
  21. tname = Text2D(cname, s=0.9)
  22. # Add the cube and text object to the list
  23. cbs.append([tname, cb])
  24. # Display the cubes and text objects in a grid
  25. plt1= show(cbs, N=len(cbs), azimuth=.2, size=(2100,1300),
  26. title="matplotlib colors", interactive=False)
  27. plt1.render()
  28. # Sort the colors by name (bootstrap5 colors)
  29. sorted_colors2 = sorted(colors.items(), key=itemgetter(0))
  30. # Create a list of cubes for each color name
  31. cbs = []
  32. for sc in sorted_colors2:
  33. # Get the color name
  34. cname = sc[0]
  35. # Skip the color if it doesn't end in a number
  36. if cname[-1] not in "123456789":
  37. continue
  38. # Create a cube for the color
  39. cb = Cube().lw(1).lighting('off').color(cname)
  40. # Add the cube to the list
  41. cbs.append([cname, cb])
  42. # Display the cubes in a grid
  43. plt2= show(cbs, shape=(11,9), azimuth=0.2, size=(800,1000),
  44. title="bootstrap5 colors", new=True)
  45. # Close the plots
  46. plt2.close()
  47. plt1.close()