Science and Computers I
Science and Computers I PHY 307
Popular in Course
Popular in Physics 2
This 2 page Class Notes was uploaded by Ms. Bryce Wisoky on Wednesday October 21, 2015. The Class Notes belongs to PHY 307 at Syracuse University taught by Jennifer Schwarz in Fall. Since its upload, it has received 26 views. For similar materials see /class/225624/phy-307-syracuse-university in Physics 2 at Syracuse University.
Reviews for Science and Computers I
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 10/21/15
Brief introduction to color in VPython MIXING COLORS Color on television screens and computer monitors is created by mixing different amounts of the 3 primary additive colors red green and blue Red is simply made by making the red pixels on the screen bright while keeping the green and blue dim Similarly it is easy to see how green and blue are made If you look at bright yellow on a monitor very closely with a magnifying glass e g you will see little red and green pixels fully lit Similarly magenta is blue and red and cyan is a mixture of green and blue More subtle shades are made from other mixtures of red R green G and blue B For example mixing maximum intensity red and half maximum intensity green and zero intensity blue gives a orange color VPython The visual library allows you to control the color of an object in several ways These methods are quite similar to controlling the position of an object in 3D space For example you can set the x attribute of an object to move it along the xaxis direction Or you can modify the whole three coordinates using the pos attribute So to move a cube named a to position x0 y1 z05 you could say ax 0 ay 1 az 05 or you could say ap0s 0 1 05 where the order is always x y z The three axes of color we will use are red green and blue To make an object orange you can say ared 1 agreen 05 ablue 0 or you could say ac010r 1 05 0 where the order is always R G B You will want to experiment with this say in a shell Just make a cube then set its red green blue and color attributes to different values between 0 dark and 1 maximum Python provides some de ned colors c010rblue is nothing but the three numbers 001 this is also called atuplet c010rgreen is 010 and c010rmagenta is l0l So when you say ac010r c010rmagenta this is equivalent to ac010r 1 0 1 For example try entering these statements one at a time in a shell from Visual import a b0x ared 0 agreen 0 ablue 0 ac010r 1 07 03 print c010rblue print c010rmagenta print c010rred print c010ryelow You can make the color dynamic same as the position Here is a program to move a box in space from x0 to x1 from Visual import a b0xc010rc010rgreen for count in range100 rate0 1 ax count 001 A simple modi cation just replacing ax with ared will not move it but instead change its color by mixing in more and more red from Visual import a b0xc010rc010rgreen for count in range100 rate0 1 ared count 001 You can use color to indicate parameter values For example you might indicate the temperature of a box using a parameter temperature from Visual import a b0xc010rc010rred temperature 1 for count in range100 rate10 temperature temperature 099 ac010r temperature 0 1 temperature If the temperature is high the color will be reddish As temperature decreases the red component will be small and the blue component will be high giving the box a bluish color