<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.physicsbook.gatech.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Maiusername</id>
	<title>Physics Book - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.physicsbook.gatech.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Maiusername"/>
	<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/Special:Contributions/Maiusername"/>
	<updated>2026-04-30T21:08:43Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.7</generator>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_basics&amp;diff=32521</id>
		<title>VPython basics</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_basics&amp;diff=32521"/>
		<updated>2018-11-26T01:34:24Z</updated>

		<summary type="html">&lt;p&gt;Maiusername: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Mai Vo Fall 2018&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This is a beginning overview to vPython with some basic syntax and functions. &lt;br /&gt;
&lt;br /&gt;
==Installation or Online Use==&lt;br /&gt;
&lt;br /&gt;
Python can be rather difficult to install. However, you can use an online version in order to do all code online. &lt;br /&gt;
===Online/ Glowscript===&lt;br /&gt;
1. Go to [http://www.glowscript.org/]&lt;br /&gt;
&lt;br /&gt;
2. Log into a Google account.&lt;br /&gt;
&lt;br /&gt;
3. Click here in &amp;quot;You are signed in as [account name you select]  and your programs are here.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. Click the blue Create New Program.&lt;br /&gt;
&lt;br /&gt;
===Computer Installation===&lt;br /&gt;
&lt;br /&gt;
To install VPython simply follow the instructions in the links given below. After the installation is completed just open the VIDLE for Python (usually there is a shortcut created on your desktop) and start typing your code.&lt;br /&gt;
&lt;br /&gt;
===Windows===&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_windows.html here]&lt;br /&gt;
&lt;br /&gt;
===OSX===&lt;br /&gt;
&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_mac.html here]&lt;br /&gt;
&lt;br /&gt;
===Linux===&lt;br /&gt;
&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_linux.html here]&lt;br /&gt;
&lt;br /&gt;
==Getting started with Python==&lt;br /&gt;
Introduction to basic Python use&lt;br /&gt;
&lt;br /&gt;
The first two lines of your program should be:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
::from __future__ import division&lt;br /&gt;
::from visual import *&amp;lt;/code&amp;gt;&lt;br /&gt;
The first line enables float division, so 3 / 2 = 1.5 (not 1) and the second line enables graphics module to plot your 3D simulation. &lt;br /&gt;
&lt;br /&gt;
When you reach the point where graphing is needed, you will need this line of code below the ones above:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
::from visual.graph import *&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
A variable is the name given to a chosen value. Variables can be manipulated, changed, or renamed within vPython. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Assigning Variables&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = 5 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This assigns the variable x the number 5. &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039;&#039;&#039; The equal sign does not mean equal. Think of it more as an assignment.&lt;br /&gt;
&lt;br /&gt;
Python allows allows you to redefine variables&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
y = 0&lt;br /&gt;
&lt;br /&gt;
x = y &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, we have taken the original x and assigned it the value from the variable y making the value of x equal to 0. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Increasing a Variable&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you want x to increase by one after a certain line of code, to keep variables to a minimum. Python allows you do to so. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = 2&lt;br /&gt;
&lt;br /&gt;
x = x + 1 &lt;br /&gt;
&lt;br /&gt;
x += 1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, we have taken the original value of x and added one to it. If you call x again, its value will now be 3. The third method performs the exact same action as the second method. It just contains different syntax. This will be helpful in loops.&lt;br /&gt;
&lt;br /&gt;
===Creating VPython Objects===&lt;br /&gt;
In VPython you can create an object with certain attributes (e.g. radius, position). You can store the information about that object in a variable. This way you can access a certain object using a variable it is stored in.&lt;br /&gt;
&#039;&#039;&#039;Here are examples of some objects you can create and how to define them&#039;&#039;&#039;&lt;br /&gt;
*[http://vpython.org/contents/docs/sphere.html Sphere]&lt;br /&gt;
[[File:Sphere.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; variableName = ball( pos=vector(x_coordinate, y_coordinate, z_coordinate), radius = radius_measure, color = color.blue) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;&#039;&#039; There are different colors you can assign some of which are red, blue, magenta, cyan, yellow, and more. &lt;br /&gt;
[[File:Arrow1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;myArrow = arrow(pos=vector(x_coordinate,y_coordinate,z_coordinate), axis=vector(x1_coordinate,y1_coordinate,z1_coordinate), color = color.color_of_the_arrow)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The axis refers to the more so thickness of the arrow. When coding, you can multiply this vector by a scalar value. &lt;br /&gt;
&lt;br /&gt;
*[http://vpython.org/contents/docs/vector.html Vector]&lt;br /&gt;
&amp;lt;code&amp;gt;myVector = vector(x_coordinate,y_coordinate,z_coordinate)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Outside of objects, you can just create a vector numbers to be used later, such as making the force or velocity vector. &lt;br /&gt;
*[http://vpython.org/contents/docs/trail.html Trail]&lt;br /&gt;
[[File:Trail1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can leave a path behind a moving object simply by specifying &amp;lt;code&amp;gt;make_trail=True&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ball.make_trail = True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each time you change (object).pos, this new position is added to a curve, thereby leaving a trail behind the moving sphere. This works with arrow, box, cone, cylinder, ellipsoid, pyramid, ring, and sphere.&lt;br /&gt;
&lt;br /&gt;
===Manipulating VPython values===&lt;br /&gt;
*Accessing attributes of the variable&lt;br /&gt;
To access the attribute of a given variable just use the syntax &amp;lt;code&amp;gt;object.attribute&amp;lt;/code&amp;gt; (e.g. to access the position of the ball variable, you should do &amp;lt;code&amp;gt;ball.pos&amp;lt;/code&amp;gt;)&lt;br /&gt;
*Updating variable&lt;br /&gt;
To update a variable (such as time, speed, force or the position of the object) you should do &amp;lt;code&amp;gt;variable = variable + updateIncrement&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running VPython code===&lt;br /&gt;
To run VPython code simply press F5. While running your code you will see the visual module and a shell (a place where all print out information is displayed) &lt;br /&gt;
===Loops===&lt;br /&gt;
There are two types of loops that can be used in Python: [https://wiki.python.org/moin/ForLoop for loop] and [https://wiki.python.org/moin/WhileLoop while loop]. Loops repeat the actions within them until a certain pre-determined point is reached. &lt;br /&gt;
&lt;br /&gt;
In this course, only while loops are used, so you will not need to worry about for loops.&lt;br /&gt;
&lt;br /&gt;
*While loops &lt;br /&gt;
The body of a while loop is executed, while a certain condition is true. &#039;&#039;&#039;All the statements within the while loop are indented.&#039;&#039;&#039; While loop is equivalent to integration, because it manually breaks down the physical process into small parts and adds them up (see [[Iterative_Prediction | Iterative Prediction]] as a good example of the physical application of a while loop). While loop has the following structure:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
:while (condition):&lt;br /&gt;
::the body of the while loop&lt;br /&gt;
::updating the loop&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure that the while loop is followed by a colon: (:), or else your program will issue an error.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
while t &amp;lt; 60:&lt;br /&gt;
  distance = distance + velocity * deltat&lt;br /&gt;
  t = t + deltat&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;To animate, put &#039;&#039;&#039;rate(integerNumber)&#039;&#039;&#039;. The higher the rate, the faster the animation. A good number to pick is &#039;&#039;&#039;rate(200)&#039;&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; &#039;&#039;All variables called within the while loop should be created first outside the original loop as it makes it a little easier to troubleshoot at times.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
Comments in the code have no impact on the code execution, because they are just ignored by the computer. Comments in VPython start with a pound sign (#) and end when a line ends. It is a good practice to place some useful information (like an explanation to a certain step) in the comments, so other people will find it easier to understand your code. For example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = x + 1 # incrementing x variable&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Useful built-in functions===&lt;br /&gt;
====Printing out information====&lt;br /&gt;
*&amp;lt;code&amp;gt;print(value, variable)&amp;lt;/code&amp;gt;&lt;br /&gt;
Prints out the given value in the programming shell. An example is as follows&lt;br /&gt;
&amp;lt;nowiki&amp;gt;print(&amp;quot;x =&amp;quot;, x)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The program will print x = and then the value of x from the code you have in the form of: (assuming x equals 5)&lt;br /&gt;
x = 5&lt;br /&gt;
Or&lt;br /&gt;
&amp;lt;nowiki&amp;gt;print(&amp;quot;200&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will just print the number 200.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The print function is useful in checking your math while coding!!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====Math====&lt;br /&gt;
Raises x to the y-th power.&lt;br /&gt;
*&amp;lt;code&amp;gt;x ** y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes normal addition&lt;br /&gt;
*&amp;lt;code&amp;gt;x + y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes normal subtraction&lt;br /&gt;
*&amp;lt;code&amp;gt;x - y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes multiplications&lt;br /&gt;
*&amp;lt;code&amp;gt;x * y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes divisions&lt;br /&gt;
*&amp;lt;code&amp;gt;x / y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes the remainder between two values&lt;br /&gt;
*&amp;lt;code&amp;gt;x % y&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note: You cannot multiply two vectors!! You can, however, multiply a vector by a scalar. &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Vectors===&lt;br /&gt;
Calculates the cross product of two vectors&lt;br /&gt;
*&amp;lt;code&amp;gt;cross(vectorA, vectorB)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the magnitude of the vector&lt;br /&gt;
*&amp;lt;code&amp;gt;mag(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the unit vector of the vector&lt;br /&gt;
*&amp;lt;code&amp;gt;norm(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the dot product of two vectors&lt;br /&gt;
*&amp;lt;code&amp;gt;dot(vector_1, vector_2)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The structure of VPython program==&lt;br /&gt;
VPython reads linearly meaning that it reads down the lines as you type. Therefore, the following give you a good idea of how to begin your coding in terms for this class and physics in general. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Copy the&#039;&#039;&#039; from__future import division     /    from visual import*&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Create and declare all variables.&#039;&#039;&#039; This includes any constants and any initial conditions. It&#039;s important to create your initial conditions before any loops. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Create objects.&#039;&#039;&#039; In VPython, you are creating 3D objects that will most likely move. Characteristics of the objects are most likely going to be updated; therefore, they need to be initialized. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Initialize a while loop.&#039;&#039;&#039; Once you have all your variables, write the condition of your while loop (condition being what you are working towards). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Begin updating the necessary variables and characteristics of objects.&#039;&#039;&#039; This will include things such as velocity, force, momentum, object positions, and etc. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Print any necessary pieces of data after the while loop or during, if needed.&lt;br /&gt;
&lt;br /&gt;
This program uses a simple algorithm that produces an approximate motion of Earth around the Sun. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from __future__ import division&lt;br /&gt;
from visual import *&lt;br /&gt;
&lt;br /&gt;
r=5.0&lt;br /&gt;
theta=0.0&lt;br /&gt;
dtheta=0.01&lt;br /&gt;
sun=sphere(color=color.yellow)&lt;br /&gt;
earth=sphere(pos=(r,0,0),color=color.blue)&lt;br /&gt;
t = 0&lt;br /&gt;
while t &amp;lt; 60:&lt;br /&gt;
    rate(20)&lt;br /&gt;
    theta=theta+dtheta&lt;br /&gt;
    x=r*cos(theta)&lt;br /&gt;
    y=r*sin(theta)&lt;br /&gt;
    earth.pos=(x,y,0)&lt;br /&gt;
    t = t + 0.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
[[File:Earth_Sun.jpg]]&lt;br /&gt;
&lt;br /&gt;
https://trinket.io/embed/glowscript/c8bd5fcfea&lt;br /&gt;
&lt;br /&gt;
Here is a longer, animated example if you follow the link above. It&#039;s a Glowscript trinket of a 3D spring. &lt;br /&gt;
&lt;br /&gt;
===Debugging techniques===&lt;br /&gt;
Unfortunately, sometimes programs do not work in a way we intended them to work. Here are some tips to fixing your code. &lt;br /&gt;
#If you get an error try to see what the error is. The most common errors are with syntax and include forgetting a parentheses, using the wrong punctuation in coding lines, &lt;br /&gt;
#Make sure you are updating the variable on which your while loop is based upon. This could cause an infinite while loop if you never approach a terminating condition. &lt;br /&gt;
#Double check math. Check for imaginary number or dividing by zero. &lt;br /&gt;
#Make sure you have correct indentation everywhere. Remember that the code in the while loop needs to be indented. Python is space-dependent. If an indentation is off, then your whole code will be off.&lt;br /&gt;
#Put plenty of &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements, so you can know what is going on throughout the code. Usually, put these after you are changing the values of variables. &lt;br /&gt;
#Check your mathematical expressions for the order of precedence (e.g. &amp;lt;code&amp;gt;x / (y * z)&amp;lt;/code&amp;gt; is &#039;&#039;&#039;not&#039;&#039;&#039; equivalent to &amp;lt;code&amp;gt;x / y * z&amp;lt;/code&amp;gt;). Try to fix by adding parenthesis on what needs to be done first. &lt;br /&gt;
#It&#039;s always a good idea to perhaps do coding in parts and check through the parts as you write the code to ensure not too many errors when approaching the end of coding. &lt;br /&gt;
# Always feel free to ask your TA for help! &lt;br /&gt;
For further information on debugging see [[VPython_Common_Errors_and_Troubleshooting | VPython Common Errors and Troubleshooting]].&lt;br /&gt;
&lt;br /&gt;
==Studying for Exams==&lt;br /&gt;
Most exam questions will be based on coding similar to labs or coding having to deal with concepts that you&#039;ve already covered in physics. One good way to prepare is to solve the problems with a set number of variables, then looking back and writing down the variables that change. Finally, create the objects and write the needed characteristics of these objects. &lt;br /&gt;
The exam questions will not be perfectly similar to a lab or any previous question; however, if you practice coding outside of the lab, create other simulations, and understand how the basic syntax of VPython, things should turn out well. &lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
&lt;br /&gt;
How is this topic connected to something that you are interested in?&lt;br /&gt;
&lt;br /&gt;
I enjoy coding and believe coding to be helpful in trying to visualize physics and the mathematics behind it, especially through vPython. &lt;br /&gt;
&lt;br /&gt;
How is it connected to your major?&lt;br /&gt;
&lt;br /&gt;
I&#039;m a Computer Science major and am currently learning Python in another class. It&#039;s very rewarding to see your code be applied in a way that allows you or others to visualize data.&lt;br /&gt;
 &lt;br /&gt;
Is there an interesting industrial application?&lt;br /&gt;
&lt;br /&gt;
VPython could be used to simulate different scenarios that can occur virtually.&lt;br /&gt;
&lt;br /&gt;
==History of Python==&lt;br /&gt;
&lt;br /&gt;
VPython was created by a man named Guido van Rossum. He graduated in 1982 with a master&#039;s degree in mathematics and computer science from the University of Amsterdam. &lt;br /&gt;
Originally, the program was released in 1989The first open source version was released in 1991 and van Rossum had the following goals in mind: 1. It should be easy and intuitive, 2. It should be open sourced, which means anyone can contribute to its development on the language, 3. It should be easily understood like a language and suitable to be used for multiple purposes. &lt;br /&gt;
He has been recognized by ACM in 2006 as a Distinguished Engineer. Sources:  [4] [http://www.computerhistory.org/fellowawards/hall/guido-van-rossum/]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
===General Overview of VPython===&lt;br /&gt;
[[VPython]]&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
[http://vpython.org/ The official VPython website with the links to YouTube tutorials]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/doc.html Documentation]&lt;br /&gt;
&lt;br /&gt;
[https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!forum/vpython-users VPython User forum]&lt;br /&gt;
&lt;br /&gt;
[https://www.computer.org/csdl/mags/co/2015/03/mco2015030008.pdf]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
This section contains the the references you used while writing this page&lt;br /&gt;
&lt;br /&gt;
1. [http://openbookproject.net/thinkcs/python/english3e/index.html Python tutorial]&lt;br /&gt;
&lt;br /&gt;
2. [http://vpython.wikidot.com/ VPython Wiki Site]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.glowscript.org/ GlowScript]&lt;br /&gt;
&lt;br /&gt;
4. Information on van Rossum [http://www.computerhistory.org/fellowawards/hall/guido-van-rossum/] &lt;br /&gt;
&lt;br /&gt;
5. More information of python development [https://www.computer.org/csdl/mags/co/2015/03/mco2015030008.pdf]&lt;br /&gt;
&lt;br /&gt;
[[Category:VPython]]&lt;/div&gt;</summary>
		<author><name>Maiusername</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_basics&amp;diff=32520</id>
		<title>VPython basics</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_basics&amp;diff=32520"/>
		<updated>2018-11-26T00:49:07Z</updated>

		<summary type="html">&lt;p&gt;Maiusername: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Mai Vo Fall 2018&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This is a beginning overview to vPython with some basic syntax and functions. &lt;br /&gt;
&lt;br /&gt;
==Installation or Online Use==&lt;br /&gt;
&lt;br /&gt;
Python can be rather difficult to install. However, you can use an online version in order to do all code online. &lt;br /&gt;
===Online/ Glowscript===&lt;br /&gt;
1. Go to [http://www.glowscript.org/]&lt;br /&gt;
&lt;br /&gt;
2. Log into a Google account.&lt;br /&gt;
&lt;br /&gt;
3. Click here in &amp;quot;You are signed in as [account name you select]  and your programs are here.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. Click the blue Create New Program.&lt;br /&gt;
&lt;br /&gt;
To install VPython simply follow the instructions in the links given below. After the installation is completed just open the VIDLE for Python (usually there is a shortcut created on your desktop) and start typing your code.&lt;br /&gt;
&lt;br /&gt;
===Windows===&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_windows.html here]&lt;br /&gt;
&lt;br /&gt;
===OSX===&lt;br /&gt;
&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_mac.html here]&lt;br /&gt;
&lt;br /&gt;
===Linux===&lt;br /&gt;
&lt;br /&gt;
Install VPython [http://vpython.org/contents/download_linux.html here]&lt;br /&gt;
&lt;br /&gt;
==Getting started with Python==&lt;br /&gt;
Introduction to basic Python use&lt;br /&gt;
&lt;br /&gt;
The first two lines of your program should be:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
::from __future__ import division&lt;br /&gt;
::from visual import *&amp;lt;/code&amp;gt;&lt;br /&gt;
The first line enables float division, so 3 / 2 = 1.5 (not 1) and the second line enables graphics module to plot your 3D simulation. &lt;br /&gt;
===Variables===&lt;br /&gt;
A variable is the name given to a chosen value. Variables can be manipulated, changed, or renamed within vPython. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Assigning Variables&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = 5 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This assigns the variable x the number 5. &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039;&#039;&#039; The equal sign does not mean equal. Think of it more as labeling. &lt;br /&gt;
&lt;br /&gt;
Python allows allows you to redefine variables&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
y = 0&lt;br /&gt;
&lt;br /&gt;
x = y &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, we have taken the original x and assigned it the value from the variable y making the value of x equal to 0. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Increasing a Variable&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you want x to increase by one after a certain line of code, to keep variables to a minimum. Python allows you do to so. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = 2&lt;br /&gt;
&lt;br /&gt;
x = x + 1 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, we have taken the original value of x and added one to it. If you call x again, its value will now be 3. This will be helpful in loops.&lt;br /&gt;
&lt;br /&gt;
===Creating VPython Objects===&lt;br /&gt;
In VPython you can create an object with certain attributes (e.g. radius, position). You can store the information about that object in a variable. This way you can access a certain object using a variable it is stored in.&lt;br /&gt;
&#039;&#039;&#039;Here are examples of some objects you can create and how to define them&#039;&#039;&#039;&lt;br /&gt;
*[http://vpython.org/contents/docs/sphere.html Sphere]&lt;br /&gt;
[[File:Sphere.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; variableName = ball( pos=vector(x_coordinate, y_coordinate, z_coordinate), radius = radius_measure, color = color.blue) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;&#039;&#039; There are different colors you can assign some of which are red, blue, magenta, cyan, yellow, and more. &lt;br /&gt;
[[File:Arrow1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;myArrow = arrow(pos=vector(x_coordinate,y_coordinate,z_coordinate), axis=vector(x1_coordinate,y1_coordinate,z1_coordinate), color = color.color_of_the_arrow)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The axis refers to the more so thickness of the arrow. When coding, you can multiply this vector by a scalar value. &lt;br /&gt;
&lt;br /&gt;
*[http://vpython.org/contents/docs/vector.html Vector]&lt;br /&gt;
&amp;lt;code&amp;gt;myVector = vector(x_coordinate,y_coordinate,z_coordinate)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Outside of objects, you can just create a vector numbers to be used later, such as making the force or velocity vector. &lt;br /&gt;
*[http://vpython.org/contents/docs/trail.html Trail]&lt;br /&gt;
[[File:Trail1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can leave a path behind a moving object simply by specifying &amp;lt;code&amp;gt;make_trail=True&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ball.make_trail = True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each time you change (object).pos, this new position is added to a curve, thereby leaving a trail behind the moving sphere. This works with arrow, box, cone, cylinder, ellipsoid, pyramid, ring, and sphere.&lt;br /&gt;
&lt;br /&gt;
===Manipulating VPython values===&lt;br /&gt;
*Accessing attributes of the variable&lt;br /&gt;
To access the attribute of a given variable just use the syntax &amp;lt;code&amp;gt;object.attribute&amp;lt;/code&amp;gt; (e.g. to access the position of the ball variable, you should do &amp;lt;code&amp;gt;ball.pos&amp;lt;/code&amp;gt;)&lt;br /&gt;
*Updating variable&lt;br /&gt;
To update a variable (such as time, speed, force or the position of the object) you should do &amp;lt;code&amp;gt;variable = variable + updateIncrement&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running VPython code===&lt;br /&gt;
To run VPython code simply press F5. While running your code you will see the visual module and a shell (a place where all print out information is displayed) &lt;br /&gt;
===Loops===&lt;br /&gt;
There are two types of loops that can be use in Python: [https://wiki.python.org/moin/ForLoop for loop] and [https://wiki.python.org/moin/WhileLoop while loop]. Loops repeat the actions within them until a certain pre-determined point is reached. &lt;br /&gt;
*While loops &lt;br /&gt;
The body of a while loop is executed, while a certain condition is true. &#039;&#039;&#039;All the statements within the while loop are indented.&#039;&#039;&#039; While loop is equivalent to integration, because it manually breaks down the physical process into small parts and adds them up (see [[Iterative_Prediction | Iterative Prediction]] as a good example of the physical application of a while loop). While loop has the following structure:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
:while (condition)&lt;br /&gt;
::the body of the while loop&lt;br /&gt;
::updating the loop&amp;lt;/code&amp;gt;&lt;br /&gt;
For example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
while (t &amp;lt; 60)&lt;br /&gt;
  distance = distance + velocity * deltat&lt;br /&gt;
  t = t + deltat&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;To animate, put &#039;&#039;&#039;rate(integerNumber)&#039;&#039;&#039;. The higher the rate, the faster the animation. A good number to pick is &#039;&#039;&#039;rate(200)&#039;&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; &#039;&#039;All variables called within the while loop should be created first outside the original loop as it makes it a little easier to troubleshoot at times.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Comments===&lt;br /&gt;
Comments in the code have no impact on the code execution, because they are just ignored by the computer. Comments in VPython start with a pound sign (#) and end when a line ends. It is a good practice to place some useful information (like an explanation to a certain step) in the comments, so other people will find it easier to understand your code. For example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
x = x + 1 # incrementing x variable&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Useful built-in functions===&lt;br /&gt;
====Printing out information====&lt;br /&gt;
*&amp;lt;code&amp;gt;print(value, variable)&amp;lt;/code&amp;gt;&lt;br /&gt;
Prints out the given value in the programming shell. An example is as follows&lt;br /&gt;
&amp;lt;nowiki&amp;gt;print(&amp;quot;x =&amp;quot;, x)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The program will print x = and then the value of x from the code you have.&lt;br /&gt;
Or&lt;br /&gt;
&amp;lt;nowiki&amp;gt;print(&amp;quot;200&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will just print the number 200.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The print function is useful in checking your math while coding!!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
====Math====&lt;br /&gt;
*&amp;lt;code&amp;gt;x**y&amp;lt;/code&amp;gt;&lt;br /&gt;
Raises x to the y-th power.&lt;br /&gt;
*&amp;lt;code&amp;gt;x+y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes normal addition&lt;br /&gt;
*&amp;lt;code&amp;gt;x-y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes normal subtraction&lt;br /&gt;
*&amp;lt;code&amp;gt;x*y&amp;lt;/code&amp;gt;&lt;br /&gt;
Computes multiplications &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note: You cannot multiply two vectors!! You can, however, multiply a vector by a scalar. &lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Vectors===&lt;br /&gt;
*&amp;lt;code&amp;gt;cross(vectorA, vectorB)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the cross product of two vectors&lt;br /&gt;
*&amp;lt;code&amp;gt;mag(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the magnitude of the vector&lt;br /&gt;
*&amp;lt;code&amp;gt;norm(vector)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the unit vector of the vector&lt;br /&gt;
*&amp;lt;code&amp;gt;dot(vector_1, vector_2)&amp;lt;/code&amp;gt;&lt;br /&gt;
Calculates the dot product of two vectors&lt;br /&gt;
&lt;br /&gt;
==The structure of VPython program==&lt;br /&gt;
VPython reads linearly meaning that it reads down the lines as you type. Therefore, the following give you a good idea of how to begin your coding in terms for this class and physics in general. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Copy the&#039;&#039;&#039; from__future import division     /    from visual import*&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Create and declare all variables.&#039;&#039;&#039; This includes any constants and any initial conditions. It&#039;s important to create your initial conditions before any loops. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Create objects.&#039;&#039;&#039; In VPython, you are creating 3D objects that will most likely move. Characteristics of the objects are most likely going to be updated; therefore, they need to be initialized. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Initialize a while loop.&#039;&#039;&#039; Once you have all your variables, write the condition of your while loop (condition being what you are working towards). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Begin updating the necessary variables and characteristics of objects.&#039;&#039;&#039; This will include things such as velocity, force, momentum, object positions, and etc. &lt;br /&gt;
&lt;br /&gt;
This program uses a simple algorithm that produces an approximate motion of Earth around the Sun. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from __future__ import division&lt;br /&gt;
from visual import *&lt;br /&gt;
&lt;br /&gt;
r=5.0&lt;br /&gt;
theta=0.0&lt;br /&gt;
dtheta=0.01&lt;br /&gt;
sun=sphere(color=color.yellow)&lt;br /&gt;
earth=sphere(pos=(r,0,0),color=color.blue)&lt;br /&gt;
t = 0&lt;br /&gt;
while (t &amp;lt; 60):&lt;br /&gt;
    rate(20)&lt;br /&gt;
    theta=theta+dtheta&lt;br /&gt;
    x=r*cos(theta)&lt;br /&gt;
    y=r*sin(theta)&lt;br /&gt;
    earth.pos=(x,y,0)&lt;br /&gt;
    t = t + 0.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
[[File:Earth_Sun.jpg]]&lt;br /&gt;
&lt;br /&gt;
https://trinket.io/embed/glowscript/c8bd5fcfea&lt;br /&gt;
&lt;br /&gt;
Here is a longer, animated example if you follow the link above. It&#039;s a Glowscript trinket of a 3D spring. &lt;br /&gt;
&lt;br /&gt;
===Debugging techniques===&lt;br /&gt;
Unfortunately, sometimes programs do not work in a way we intended them to work. Here are some tips to fixing your code. &lt;br /&gt;
#If you get an error try to see what the error is. The most common errors are with syntax and include forgetting a parentheses, using the wrong punctuation in coding lines, &lt;br /&gt;
#Make sure you are updating the variable on which your while loop is based upon. This could cause an infinite while loop if you never approach a terminating condition. &lt;br /&gt;
#Double check math. Check for imaginary number or dividing by zero. &lt;br /&gt;
#Make sure you have correct indentation everywhere. Remember that the code in the while loop needs to be indented. &lt;br /&gt;
#Put plenty of &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; statements, so you can know what is going on throughout the code. Usually, put these after you are changing the values of variables. &lt;br /&gt;
#Check your mathematical expressions for the order of precedence (e.g. &amp;lt;code&amp;gt;x / (y * z)&amp;lt;/code&amp;gt; is &#039;&#039;&#039;not&#039;&#039;&#039; equivalent to &amp;lt;code&amp;gt;x / y * z&amp;lt;/code&amp;gt;). Try to fix by adding parenthesis on what needs to be done first. &lt;br /&gt;
#It&#039;s always a good idea to perhaps do coding in parts and check through the parts as you write the code to ensure not too many errors when approaching the end of coding. &lt;br /&gt;
# Always feel free to ask your TA for help! &lt;br /&gt;
For further information on debugging see [[VPython_Common_Errors_and_Troubleshooting | VPython Common Errors and Troubleshooting]].&lt;br /&gt;
&lt;br /&gt;
==Studying for Exams==&lt;br /&gt;
Most exam questions will be based on coding similar to labs or coding having to deal with concepts that you&#039;ve already covered in physics. One good way to prepare is to solve the problems with a set number of variables, then looking back and writing down the variables that change. Finally, create the objects and write the needed characteristics of these objects. &lt;br /&gt;
The exam questions will not be perfectly similar to a lab or any previous question; however, if you practice coding outside of the lab, create other simulations, and understand how the basic syntax of VPython, things should turn out well. &lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
&lt;br /&gt;
How is this topic connected to something that you are interested in?&lt;br /&gt;
&lt;br /&gt;
I enjoy coding and believe coding to be helpful in trying to visualize physics and the mathematics behind it, especially through vPython. &lt;br /&gt;
&lt;br /&gt;
How is it connected to your major?&lt;br /&gt;
&lt;br /&gt;
I am a Computer Engineering major, and I have learned two other programming languages previously and still have two more at least to learn. &lt;br /&gt;
 &lt;br /&gt;
Is there an interesting industrial application?&lt;br /&gt;
&lt;br /&gt;
Every simulation starting from interaction of molecules can be modeled in VPython to get the general idea of the process.&lt;br /&gt;
&lt;br /&gt;
==History of Python==&lt;br /&gt;
&lt;br /&gt;
VPython was created by a man named Guido van Rossum. He graduated in 1982 with a master&#039;s degree in mathematics and computer science from the University of Amsterdam. &lt;br /&gt;
Originally, the program was released in 1989The first open source version was released in 1991 and van Rossum had the following goals in mind: 1. It should be easy and intuitive, 2. It should be open sourced, which means anyone can contribute to its development on the language, 3. It should be easily understood like a language and suitable to be used for multiple purposes. &lt;br /&gt;
He has been recognized by ACM in 2006 as a Distinguished Engineer. Sources:  [4] [http://www.computerhistory.org/fellowawards/hall/guido-van-rossum/]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
===General Overview of VPython===&lt;br /&gt;
[[VPython]]&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
[http://vpython.org/ The official VPython website with the links to YouTube tutorials]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/doc.html Documentation]&lt;br /&gt;
&lt;br /&gt;
[https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!forum/vpython-users VPython User forum]&lt;br /&gt;
&lt;br /&gt;
[https://www.computer.org/csdl/mags/co/2015/03/mco2015030008.pdf]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
This section contains the the references you used while writing this page&lt;br /&gt;
&lt;br /&gt;
1. [http://openbookproject.net/thinkcs/python/english3e/index.html Python tutorial]&lt;br /&gt;
&lt;br /&gt;
2. [http://vpython.wikidot.com/ VPython Wiki Site]&lt;br /&gt;
&lt;br /&gt;
3. [http://www.glowscript.org/ GlowScript]&lt;br /&gt;
&lt;br /&gt;
4. Information on van Rossum [http://www.computerhistory.org/fellowawards/hall/guido-van-rossum/] &lt;br /&gt;
&lt;br /&gt;
5. More information of python development [https://www.computer.org/csdl/mags/co/2015/03/mco2015030008.pdf]&lt;br /&gt;
&lt;br /&gt;
[[Category:VPython]]&lt;/div&gt;</summary>
		<author><name>Maiusername</name></author>
	</entry>
</feed>