Skip to content

A physics based simulation game about oscilating things.

License

Notifications You must be signed in to change notification settings

lbirkert/oscsim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oscsim

A physics based simulation game to play around with oscillating things written in Python.

view the demo


Quickstart

  1. (optional) setup python venv
$ python3 -m venv .venv

Please use .venv/bin/python3 as <path/to/python3> if you choose to go with this route!

  1. Install the required dependencies
$ <path/to/python3> -m pip install -r requirements.txt
  1. Launch the application
$ <path/to/python3> src/main.py

Hacking Guide

Adding your own springs

src/sim.py

class YourSpring(Spring):
    def __init__(self, stiffness: float = 10, **kwargs):
        super().__init__(**kwargs)
        self.stiffness = stiffness

    def magnitude(self, dist: float) -> float:
        # return the magnitude of the force, which the spring applies
        # if this is negative, the spring will push outwards instead of pull
        return math.exp(dist) / (dist ** 2) * self.stiffness

src/main.py

springs = [
    ("constant", ConstantSpring),
    ("proportional", HookesSpring),
    ("quadratic", QuadraticSpring),
    ("hyperbolic", HyperbolicSpring),
    # we can use the hyperbolic spring's icon for now
    ("hyperbolic", YourSpring),
]

Now you can try it out and see how it behaves.

Custom icons

Paste your_icon.png into imgs/.

src/main.py

springs = [
    ("constant", ConstantSpring),
    ("proportional", HookesSpring),
    ("quadratic", QuadraticSpring),
    ("hyperbolic", HyperbolicSpring),
    ("your_icon.png", YourSpring),
]

Controls

Adding anchors

Pro-Tip: disable gravity or pause the simulation (space key) for easier handling of anchors

Hold and drag from the anchor icon on the bottom right corner to spawn a new anchor at your cursor, which you can then drag around the scene.

Select at least two anchors and click on one of the spring icons in the bottom right corner to connect these anchors with the given spring type.

key function
space show/hide settings menu
space pause/resume simulation
right mouse button navigate around the scene
right mouse button select anchor
right mouse button move anchor
right mouse button end selection
shift extend selection
backspace delete selected
scroll wheel zoom in/out

© 2024 Lucas Birkert - All Rights Reserved

About

A physics based simulation game about oscilating things.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages