VPython Reference: Difference between revisions
Jump to navigation
Jump to search
(8 intermediate revisions by the same user not shown) | |||
Line 25: | Line 25: | ||
t += deltat</nowiki> | t += deltat</nowiki> | ||
== VPython Animation | == VPython Animation and Drawing Reference == | ||
=== Sphere === | === Sphere === | ||
Line 169: | Line 169: | ||
| color | | color | ||
| Color of the object | | Color of the object | ||
|} | |||
=== Label === | |||
[http://vpython.org/contents/docs/label.html Source] | |||
==== Example ==== | |||
lbl = label(pos=(1,2,3), text='Information', color=color.cyan) | |||
==== Parameters ==== | |||
{| class="wikitable" | |||
|- | |||
! Parameter | |||
! Type | |||
! Description | |||
|- | |||
| pos | |||
| vector | |||
| Position of the label in the world | |||
|- | |||
| xoffset | |||
| number | |||
| The x component of the line (offset from the pos) | |||
|- | |||
| yoffset | |||
| number | |||
| The y component of the line (offset from the pos) | |||
|- | |||
| color | |||
| color | |||
| Color of the text | |||
|- | |||
| text | |||
| string | |||
| The text to be displayed (line breaks are \n) | |||
|- | |||
| font | |||
| string | |||
| Name of the font to be used | |||
|- | |||
| height | |||
| number | |||
| Height of the font in pixels (default: 13 pixels) | |||
|- | |||
| background | |||
| color | |||
| Color of the background | |||
|- | |||
| opacity | |||
| number | |||
| Opacity of the background of the box | |||
|- | |||
| border | |||
| number | |||
| Distance in pixels from the text to the text box (default: 5 pixels) | |||
|- | |||
| box | |||
| boolean | |||
| Whether or not to draw the box (default: true) | |||
|- | |||
| line | |||
| boolean | |||
| Whether or not to draw the box to the position (default: true) | |||
|- | |||
| linecolor | |||
| color | |||
| Color of the line and box | |||
|- | |||
| space | |||
| number | |||
| Radius in pixels of a sphere around pos where the line is not shown | |||
|} | |} | ||
Line 306: | Line 375: | ||
==Connectedness== | ==Connectedness== | ||
* How is this topic connected to something that you are interested in? | |||
I like to compile useful data into compact pages. This way, time can be saved by not having to search for simple information that may not be memorized. | ** I like to compile useful data into compact pages. This way, time can be saved by not having to search for simple information that may not be memorized. | ||
* How is it connected to your major? | |||
** I'm a Computer Science major so I am used to programming languages and how the need for docs are. Also, Computer Science is partly about making things more efficient. This page makes looking up common information about VPython more efficient. | |||
I'm a Computer Science major so I am used to programming languages and how the need for docs are. Also, Computer Science is partly about making things more efficient. This page makes looking up common information about VPython more efficient. | * Is there an interesting industrial application? | ||
** In the real world, references are time savers. Businesses welcome work that save production time. | |||
In the real world, references are time savers. Businesses welcome work that save production time | |||
== See also == | == See also == | ||
Line 324: | Line 387: | ||
[[VPython Objects]] | [[VPython Objects]] | ||
[[VPython Animation]] | |||
== References == | == References == |
Latest revision as of 20:22, 5 December 2015
Created by Shuyang Chen
VPython reference page for drawing functions and constants. This page compiles common usages into one page for quick reference. This page assumes that the student knows the basics of creating the objects and just needs a reference page for them.
For detailed and more descriptive pages about objects and how to use them, see VPython 3D Objects and VPython Objects
VPython Template
from __future__ import division from visual import * ## Constants ## Initialization ## Loop t = 0 deltat = 1e-10 end = 10 while t < end: rate(1000) ## Loop Code t += deltat
VPython Animation and Drawing Reference
Sphere
Example
ball = sphere(pos=(1,2,3), radius=0.4, color=color.blue)
Parameters
Parameter | Type | Description |
---|---|---|
pos | vector | Position of the object |
color | color | Color of the object |
radius | number | Radius of the sphere |
opacity | number | Opacity of the object |
make_trail | boolean | Whether or not to leave behind a trail |
Box
Example
cube = box(pos=(1,2,3), length=4, height=5, width=6, color=color.green)
Parameters
Parameter | Type | Description |
---|---|---|
pos | vector | Position of the object |
color | color | Color of the object |
length | number | Length of the box |
height | number | Height of the box |
width | number | Width of the box |
axis | vector | Direction the box is facing (facing side is height x width) |
opacity | number | Opacity of the object |
make_trail | boolean | Whether or not to leave behind a trail |
Arrow
Example
arr = arrow(pos=(1,2,3), axis=(4,5,6), color=color.red)
Parameters
Parameter | Type | Description |
---|---|---|
pos | vector | Position of the object |
axis | vector | Direction the arrow is pointing at |
color | color | Color of the object |
opacity | number | Opacity of the object |
shaftwidth | number | Width of the shaft (default: 0.1*(length of arrow)) |
headwidth | number | Width of the head (default: 2*shaftwidth) |
headlength | number | Length of the head (default: 3*shaftwidth) |
make_trail | boolean | Whether or not to leave behind a trail |
Curve
Example
trail = curve(color=color.orange) trail.append(pos=(1,2,3)) trail.append(pos=(4,5,6))
Parameters
Parameter | Type | Description |
---|---|---|
pos | vector array | Positions of the trail |
color | color | Color of the object |
Label
Example
lbl = label(pos=(1,2,3), text='Information', color=color.cyan)
Parameters
Parameter | Type | Description |
---|---|---|
pos | vector | Position of the label in the world |
xoffset | number | The x component of the line (offset from the pos) |
yoffset | number | The y component of the line (offset from the pos) |
color | color | Color of the text |
text | string | The text to be displayed (line breaks are \n) |
font | string | Name of the font to be used |
height | number | Height of the font in pixels (default: 13 pixels) |
background | color | Color of the background |
opacity | number | Opacity of the background of the box |
border | number | Distance in pixels from the text to the text box (default: 5 pixels) |
box | boolean | Whether or not to draw the box (default: true) |
line | boolean | Whether or not to draw the box to the position (default: true) |
linecolor | color | Color of the line and box |
space | number | Radius in pixels of a sphere around pos where the line is not shown |
Color
Example
c = color.red
Basic Colors
Name | Vector | Color |
---|---|---|
Red | (1,0,0) | color.red |
Yellow | (1,1,0) | color.yellow |
Green | (0,1,0) | color.green |
Orange | (1,0.5,0) | color.orange |
Blue | (0,0,1) | color.blue |
Cyan | (0,1,1) | color.cyan |
Magenta | (1,0,1) | color.magenta |
White | (1,1,1) | color.white |
Black | (0,0,0) | color.black |
VPython Common Constants
Constant | Common Variable Name | Approximate Value | Code |
---|---|---|---|
Speed of light | c | 299792458.0 | c = 299792458.0 |
Gravitational Constant | G | 6.67408e-11 | G = 6.67408e-11 |
Electron Mass | m_e | 9.10938356e-31 | m_e = 9.10938356e-31 |
Proton Mass | m_p | 1.6726219e-27 | m_p = 1.6726219e-27 |
Neutron Mass | m_n | 1.674927471e-27 | m_n = 1.674927471e-27 |
Electric Constant | oofpez | 8.9875517873681764e9 | oofpez = 8.9875517873681764e9 |
Permitivity of Free Space | e0 | 8.854187817e-12 | e0 = 8.854187817e-12 |
Magnetic Constant | km | 1e-7 | km = 1e-7 |
Vacuum Permeability | mu_0 | 1.2566370614e-6 | mu_0 = 1.2566370614e-6 |
Proton Charge | e | 1.602176565e-19 | e = 1.602176565e-19 |
Electron Volt | eV | 1.602176565e-19 | eV = 1.602176565e-19 |
Avogadro's Number | N_A | 6.0221409e23 | N_A = 6.0221409e23 |
Proton Radius | R_p | 0.8775e-15 | R_p = 0.8775e-15 |
E to ionize air | E_ionize | 3e6 | E_ionize = 3e6 |
Earth's Magnetic Field | B_Earth | 2e-5 | B_Earth = 2e-5 |
Connectedness
- How is this topic connected to something that you are interested in?
- I like to compile useful data into compact pages. This way, time can be saved by not having to search for simple information that may not be memorized.
- How is it connected to your major?
- I'm a Computer Science major so I am used to programming languages and how the need for docs are. Also, Computer Science is partly about making things more efficient. This page makes looking up common information about VPython more efficient.
- Is there an interesting industrial application?
- In the real world, references are time savers. Businesses welcome work that save production time.