1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>color</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #0000A0}
-->
</style>
<!-- InstanceEndEditable -->
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutDefaultTable-->
<tr>
<td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td>
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p> </p> </td>
<td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
<p class="Normal">If you're new to Python <br />
and VPython: <a href="VisualIntro.html">Introduction</a></p>
<p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
<p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
<p class="Normal">Choose a 3D object:</p>
<select name="jumpMenu4" id="jumpMenu4" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose an object</option>
<option value="cylinder.html">Overview</option>
<option value="arrow.html">arrow</option>
<option value="box.html">box</option>
<option value="cone.html">cone</option>
<option value="convex.html">convex</option>
<option value="curve.html">curve</option>
<option value="cylinder.html">cylinder</option>
<option value="ellipsoid.html">ellipsoid</option>
<option value="faces.html">faces</option>
<option value="frame.html">frame</option>
<option value="helix.html">helix</option>
<option value="label.html">label</option>
<option value="lights.html">lights</option>
<option value="points.html">points</option>
<option value="pyramid.html">pyramid</option>
<option value="ring.html">ring</option>
<option value="sphere.html">sphere</option>
</select>
<p class="Normal">Work with 3D objects:</p>
<select name="jumpMenu4" id="jumpMenu5" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose an option</option>
<option value="color.html">Color & Opacity</option>
<option value="lights.html">Lighting</option>
<option value="materials.html">Materials & Textures</option>
<option value="defaults.html">Defaults</option>
<option value="rate.html">Animation Speed</option>
<option value="rotation.html">Rotations</option>
<option value="options.html">Additional Options</option>
<option value="delete.html">Delete an Object</option>
<option value="float.html">3/4 = 0?</option>
</select>
<p class="Normal">Windows, Events, & Files:</p>
<select name="jumpMenu4" id="jumpMenu6" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose a topic</option>
<option value="display.html">Windows</option>
<option value="lights.html">Lighting</option>
<option value="mouse.html">Mouse Events</option>
<option value="mouse_click.html"> Mouse Click</option>
<option value="mouse_drag.html"> Mouse Drag</option>
<option value="keyboard.html">Keyboard Events</option>
<option value="controls.html">Buttons and Sliders</option>
<option value="files.html">Reading/Writing Files</option>
</select>
<p class="Normal"><a href="vector.html">Vector operations </a></p>
<p class="Normal"><a href="graph.html">Graphs</a></p>
<p class="Normal"><a href="factorial.html">factorial/combin</a></p>
<p class="Normal">What's new in <a href="new_features.html">Visual 5</a></p>
<p class="Normal"><a href="http://vpython.org" target="_blank">VPython web site</a><br />
<a href="license.txt" target="_blank">Visual license</a><br />
<a href="http://www.python.org" target="_blank">Python web site</a> <br />
<a href="http://www.python.org/doc/2.5.2/lib/module-math.html" target="_blank">Math module</a> (sqrt etc.)<br />
<a href="http://www.scipy.org/Documentation" target="_blank">Numpy module</a> (arrays) </p></td>
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td>
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
<div>
<h1 class="Heading-1"><font color="#0000A0">Color </font></h1>
</div>
<div>
<p class="Normal"> 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.</p>
<p class="Normal"> Here are some examples of RGB colors, with names you can
use in Visual:</p>
<table width="75%" border="0">
<tr>
<td width="32%"><font size="3"> (1,0,0) color.red</font></td>
<td width="37%"><font size="3">(1,1,0) color.yellow</font></td>
<td width="31%"><font size="3">(0,0,0) color.black</font></td>
</tr>
<tr>
<td><font size="3"> (0,1,0) color.green</font></td>
<td>(1,0.5,0) color.orange</td>
<td><font size="3">(1,1,1) color.white</font></td>
</tr>
<tr>
<td><font size="3"> (0,0,1) color.blue</font></td>
<td><font size="3">(0,1,1) color.cyan</font></td>
<td> </td>
</tr>
<tr>
<td><font size="3"> </font></td>
<td><font size="3">(1,0,1) color.magenta</font></td>
<td> </td>
</tr>
</table>
<p class="Normal">You can also create your own colors, such as these:</p>
<p class="attributes"> (0.5, 0.5, 0.5) a rather dark grey; or you can say <span class="attribute"><strong>color=color.gray(0.5)</strong></span> to mean (0.5,0.5,0.5)</p>
<p class="attributes">(1,0.7,0.2) a coppery color</p>
<p class="Normal"> 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).</p>
<p class="Normal"> The VPython demo program <span class="attribute">colorsliders.py</span> 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. </p>
<p class="Normal"> Visual only accepts RGB color descriptions, but
there are functions for converting color triples between RGB and HSV:</p>
<div>
<p class="program">c = (1,1,0)<br />
c2 = color.rgb_to_hsv(c) # convert RGB to HSV<br />
print hsv # (0.16667, 1, 1)<br />
c3 = color.hsv_to_rgb(c2) # convert back to RGB<br />
print c3 # (1, 1, 0)</p>
<p class="Normal"> Another example: <b>sphere(radius=2, color=hsv_to_rgb(
(0.5,1,0.8) ) </b></p>
<h1 class="Heading-1 style1"><font color="#0000A0">Opacity</font></h1>
<p class="Normal">You can make most objects be transparent by specifying a value from
0-1 inclusive for the attribute "opacity". For example, <span class="attribute"><strong>box(color=color.red,
opacity=0.8)</strong></span> is slightly transparent. An opacity value of 0 means totally
transparent,
and 1 means totally opaque. Currently curve, convex, faces, points, and helix objects
do not allow transparency. </p>
<p class="Normal">You may see incorrect rendering any time there is
a translucent object (opacity
< 1.0) which is not convex (e.g. ring), or two translucent objects
which overlap on the screen and also in their depth extents (distances
from the camera to the nearest and farthest planes perpendicular to
scene.forward which intersect the object). The objects need not
actually overlap in 3D space to have problems. The incorrect rendering
will usually have the effect of making the more distant object disappear
(fail to show through the nearer object). Accurate rendering of ad hoc
scenes with translucency is difficult and expensive, and we did not
want to wait for a perfect solution before introducing this useful enhancement.</p>
</div>
</div>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td height="16" colspan="4"></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
|