# Category Archives: Python

# ROOT Histograms in Python

Facebook Twitter Google+ LinkedIn ROOT is a data analysis framework developed by CERN that is well-suited for the analysis of certain large scientific data sets such as particle collision events and astronomical data. One useful ROOT feature are the histograms. A simple program that histograms 100,000 Gaussian random numbers is shown here: It’s output is […]

# ROOT’s TLorentzVector Class in Python

Facebook Twitter Google+ LinkedIn ROOT is a data analysis framework developed by CERN that is well-suited for the analysis of certain large scientific data sets such as particle collision events and astronomical data. One useful part of ROOT is their TLorentzVector class—objects that store and can work with relativistic four-vectors such as the space-time 4-vector […]

# Barnsley Fern in Python

Facebook Twitter Google+ LinkedIn The Barnsley Fern is a beautiful fractal that can easily be generated in Python. If we zoom in on one branch, we see that the pattern is repeated: The python code follows.

# Prime Number Sieve in Python

Facebook Twitter Google+ LinkedIn This program computes all the prime numbers up to 10,000 using an efficient algorithm. Instead of checking if a number n is prime by dividing by all previous numbers, or even all previous primes, this program only divides by all previous primes less than or equal to the square root of […]

# Newton’s Cradle in Visual Python

Facebook Twitter Google+ LinkedIn This simple program shows an animation of a two-pendulum version of Newton’s cradle. One pendulum begins at some starting angle and the other pendulum is stationary. When the moving pendulum slams into the stationary one, its momentum is transferred to the other pendulum. If you want to include damping, you can […]

# Cannonball in Visual Python

Facebook Twitter Google+ LinkedIn Just a very basic example of projectile motion in Visual Python. The cannon fires when the mouse is clicked in the window.

# Simple Pendulum in Visual Python

Facebook Twitter Google+ LinkedIn Below is the code for a simple pendulum in visual python.

# Animated GIFs from Visual Python in Windows

Facebook Twitter Google+ LinkedIn One option for creating animated GIFs from your visual python program is add the pillow package that allows you to export images of your vpython window from within your program. You can then use GIMP to create an animation such as the one shown here. To use python’s image library, you […]

# Fancy Simple Pendulum in Visual Python

Facebook Twitter Google+ LinkedIn Here is the visual python code for a “fancy” pendulum exhibiting simple harmonic motion. Clicking anywhere in the window will reset the pendulum to that angle.