Accueil
Rechercher:
sur developpez.com sur les forums
Forums | Tutoriels | F.A.Q's | Participez | Hébergement | Contacts
Accueil Conception Java DotNET Visual Basic  C  C++ Delphi MS-Office SQL & SGBD Oracle  4D  Business Intelligence
Club Emploi Blogs   TV   Dév. Web PHP XML Python Autres 2D-3D-Jeux Sécurité Windows Linux PC Mac
FORUM PYTHON F.A.Q PYTHON TUTORIELS PYTHON SOURCES PYTHON OUTILS PYTHON LIVRES PYTHON
Description of Objects in VPython

Specifying Colors

In 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 Visual:

    (1,0,0) color.red (1,1,0) color.yellow (0,0,0) color.black
    (0,1,0) color.green (1,0.5,0) color.orange (1,1,1) color.white
    (0,0,1) color.blue (0,1,1) color.cyan  
     (1,0,1) color.magenta  

You can also create your own colors, such as these:

(0.5, 0.5, 0.5) a rather dark grey

(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).

The VPython demo program colorsliders.py 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.

Currently Visual only accepts RGB color descriptions, but there are functions for converting color triples between RGB and HSV:

c = (1,1,0)

c2 = color.rgb_to_hsv(c) # convert RGB to HSV

print hsv # (0.16667, 1, 1)

c3 = color.hsv_to_rgb(c2) # convert back to RGB

print c3 # (1, 1, 0)

Another example: sphere(radius=2, color=hsv_to_rgb( (0.5,1,0.8) )

 


Responsable bénévole de la rubrique Python : Guillaume Duriaud - Contacter par EMail :
Vos questions techniques : forum d'entraide Python - Publiez vos articles, tutoriels et cours
et rejoignez-nous dans l'équipe de rédaction du club d'entraide des développeurs francophones
Nous contacter - Copyright © 2000-2008 www.developpez.com - Legal informations.