A physics rendering engine
Project description
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
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.
Or just a simple double pendulum(looks better imo):
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file phanim-1.0.0.tar.gz
.
File metadata
- Download URL: phanim-1.0.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ea456d96a7d7c836e6520fab226f0744dfdcac48d5bb882277b0f7664dcc5b0 |
|
MD5 | 029ad3d8e636948ab77f083867fbe818 |
|
BLAKE2b-256 | 8f8067f73eb18106f413254646a7334b5432c2f54c496f43706b4b61b3aba615 |
File details
Details for the file phanim-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: phanim-1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f81cee33d0ab6c7b2f71dc40253acb25f24865265cb70bad6e8de366e71ed57 |
|
MD5 | c9d2e72fd75c4dfebf9d75a0d3083463 |
|
BLAKE2b-256 | 38f127eb7c0b052129500bf4b24807d97ebd3210d77d89ac7502a8d31debe628 |