Coder Social home page Coder Social logo

oscsim's Introduction

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

oscsim's People

Contributors

lbirkert avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.