|
If you're new to Python Pictures of 3D objects |
ColorIn the RGB color system, you specify a color in terms of fractions of red, green, and blue, corresponding to how strongly glowing are the tiny red, green, and blue dots of the computer screen. In the RGB scheme, white is the color with a maximum of red, blue, and green (1, 1, 1). Black has minimum amounts (0, 0, 0). The brightest red is represented by (1, 0, 0); that is, it has the full amount of red, no green, and no blue. Here are some examples of RGB colors, with names you can use in VPython:
You can also create your own colors, such as these: vector(0.5, 0.5, 0.5) a rather dark gray; or you can say color=color.gray(0.5) to mean (0.5,0.5,0.5) vector(1,0.7,0.2) a coppery color Colors may appear differently on different computers, and under different 3D lighting conditions. The named colors above are most likely to display appropriately, because RGB values of 0 or 1 are unaffected by differing color corrections ("gamma" corrections). There is a VPython demo program that lets you adjust RGB sliders to visualize colors and print color triples that you copy into your program. It also provides HSV sliders to adjust hue, saturation (how much white is added to dilute the hue), and value (brightness), which is an alternative way to describe colors. VPython only accepts RGB color descriptions, but there are functions for converting color triples between RGB and HSV: c = vector(1,1,0) Another example: sphere(radius=2, color=color.hsv_to_rgb(vector (0.5,1,0.8) ) OpacityYou can make most objects be transparent by specifying a value from 0-1 inclusive for the attribute "opacity". For example, box(color=color.red, opacity=0.8) is slightly transparent. An opacity value of 0 means totally transparent, and 1 means totally opaque. Currently curve and helix objects do not allow transparency. |
||||||||||||||