Skip to main content

A physics rendering engine

Project description

phanim logo

PHysics ANIMations: a (quite bad) Physics render library

The project is still in the early stages of development, so larger simulation will be slow and features are very limited. Look at the example files to see what cool things you can already do!

Examples

A simple visualisation of the electric field can be found in examples/vectorField.py vector field

A simulation of a triple pendulum with the use of stiff springs can be found in examples/triplePendulum.py. The graphs on the right show the energy that each of the masses has. The yellow graph shows the total energy in the system. triple pendulum

Or just a simple double pendulum(looks better imo): double pendulum

Requirements

To install the requirements run the following command:

pip install -r requirements.txt

Installation

Clone the repository and put your own files in the base folder. Now simply:

from phanim import *

Usage

After importing you can create a phanim screen as follows:

myScreen = phanim.Screen()

This will use the device screen resolution. We can also change some of the screen parameters.

myScreen = phanim.Screen(fullscreen=False,resolution=(1920,1080))

Now we can create something to render on the screen. In this example we will create a simple grid, but the possibilities are endless.

grid = phanim.Grid(1,1,10,10) #This creates a grid with each line seperated by 1, and 10 lines to each side of the origin.

Now we can add some wait time and animate the grid being added to the screen by:

myScreen.wait(60) #This will add an empty animation for 60 frames or 1 seconds.
myScreen.play(Create(grid))

Now we can run the script and a window with a simple grid should show up.

myScreen.run()

We can also create different object. For example, a blue arrow, which points to the position of the cursor at all times. We can create the arrow by defining it like this:

arrow = phanim.Arrow(color=color.blue)

Now we will create an update function that will be called each frame and move the end of the arrow to the cursor.

def setArrow(screen):
  arrow.setDirection([0,0],screen.mousePos)

Then add this function to the updater list and run the script:

myScreen.addUpdater(setArrow)
myScreen.play(Create(arrow))
myScreen.run()

Make sure you only add the .run() command once at the very end of your script. We can also add some dotted lines to track the mouse position like this:

lines = DottedLine(),DottedLine()

def setLines(screen):
    lines[0].setEnds([screen.mousePos[0],0],screen.mousePos)
    lines[1].setEnds([0,screen.mousePos[1]],screen.mousePos)

myScreen.play(Create(lines[0]),Create(lines[1]))
myScreen.addUpdater(setLines)

After combining the update functions the final script will look like this:

from phanim import *

myScreen = Screen(fullscreen=True)

grid = Grid(1,1,10,10)
arrow =Arrow(color=color.blue)
lines = DottedLine(),DottedLine()

def update(screen):
  arrow.setDirection([0,0],screen.mousePos)
  lines[0].setEnds([screen.mousePos[0],0],screen.mousePos)
  lines[1].setEnds([0,screen.mousePos[1]],screen.mousePos)

myScreen.addUpdater(update)

myScreen.wait(60)
myScreen.play(Create(grid))
myScreen.play(Create(arrow))
myScreen.play(Create(lines[0]),Create(lines[1]))

myScreen.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phanim-1.0.0.tar.gz (19.9 kB view hashes)

Uploaded Source

Built Distribution

phanim-1.0.0-py3-none-any.whl (22.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page