Giter Site home page Giter Site logo

openpsimu / thephysicshub Goto Github PK

View Code? Open in Web Editor NEW
122.0 14.0 22.0 6.25 MB

The Physics Hub is an open source physics simulations project that is being developed by physics students worldwide and aims to deliver clear and easy to understand physics simulations free for everyone!

Home Page: https://physicsub-198fbf007acd.herokuapp.com/

License: GNU General Public License v3.0

JavaScript 92.40% CSS 0.81% Python 0.14% EJS 6.65%
simulations physics

thephysicshub's Introduction

The Physics Hub

The Physics Hub is a website built by physics enthusiasts from a range of backgrounds, serving as a place to view high school/undergraduate university-level physics simulations. The simulations are currently written using the javascript library p5.js. Everybody is welcome to contribute, no matter whether you're a beginner or an expert.

Project Setup

The website is based on ExpressJS. The Node Package Manager (npm) will thus install most of the dependencies for you.

  1. Install NodeJS

  2. In a terminal, run npm install to automatically install the necessary node modules

Instructions to add simulations to the website

To simplify the process of adding simulations, we wrote a python script that automates the grunt work. 0. Run npm install in terminal

  1. If any p5.dom elements are being used, add <element>.parent("simwrapper") in your js file (including the main canvas).

  2. Add your simulation file (p5 code) to /public/javascripts/

  3. Add your simulationdata in JSON to /routes/parameters/simulationdata.js

  4. Run python addSimulation.py in a terminal, type in a urlName and a routerName

Naming convention: the urlName should match the name of your simulation file (e.g. single_pendulum)! The routerName must be written in camelCase (e.g. singlePendulumRouter)!

Forking simulations over a single page

Instead of setting up the whole site, there exists an easier way, building over a single HTML page and .js, if one wishes to only build a new simulation forking existing ones.

  1. For simplicity, you may download the source HTML directly from, for example, view-source:https://physicshub.herokuapp.com/simulations/simplePendulum

  2. Download most of the javascript and css from this github ThePhysicsHub/public/... **Caution: Linking to github directly would not work as it is not a CDN (i.e. protected)

  3. If the simulation does not show up locally, you may change the css and the js source link from relative to direct. i.e.

<script src="file:///X:/[some long path]/public/javascripts/libraries/p5.gui.js"></script>

  1. You may wish to change the links in sim.css if formats do not show up fully.

  2. If you have the physics knowledge but not so much in javascript or programming, one can attempt to fork on the simulation simplePendulum.js. It is well documented and it is possible to start simulating something very simple just by imitating the formats.

Adding a simulation's theory section

To give those interested in the simulations on this webpage further insight into the physics and mathematics involved in the observed phenomena, we're aiming to add a theory section to each simulation.

To add a theory section for a simulation, open a new .ejs file in /routes/parameters, and write the HTML displaying your explanations in there. For displaying maths formulas, make use of the package mathjax.

When your theory section is finished, reference it in /routes/parameters by adding a new attribute to the corresponding simulation JSON object using the getFile() method ("explanation": getFile("<yourTheorySectionsName.ejs>") ).

Design template for simulations

This portion provides a general template for the UI to be followed with some flexibility based on the simulation's specifics.

The UI is meant to be clean, with minimal interactive elements visible on startup. The suggested tools to be used for creating input/sliders/buttons are either the p5.gui library or Pedro's custom-built dropdownFunctions.js file.

The UI should look something as given below, with the parameter options available to the right, and the simulation window to the left, following a minimal grey-scale theme.

The general layering of canvas is as follows:

  • bgCanvas: The overall container canvas, holding all other layers, and the dropdown menu on the right.
  • simCanvas: The simulation window on the left, occupying all of bgCanvas except what is occupied by the dropdown menu.
  • plotCanvas: The plotting window inside simCanvas, it can occupy any position and size depending on the simulation. This layer must have a visibility toggle in the menu. Specific to the simulation, simCanvas and plotCanvas can be resized as the user toggles the visibility. Plotting can be done using grafica.js or a custom lightweight plotter if any.
  • Other layers: Further layers can be added over the above mentioned, as per necessity. For instance, the static grid in the image was on a separate buffer, gridCanvas.

The code given below is a sample to recreate the UI shown above. (it uses Pedro's dropdown file, the documentation for which can be found in the same file.)

let W = 1200  //width of bgCanvas
let H = 500  //height of bgCanvas
let Wsim = W * 0.69 
let Hsim = H
let Wplot = 0.25 * W
let Hplot = 0.875 * H 
let bgCanvas, simCanvas, plotCanvas;

function setup() {
  bgCanvas = createCanvas(W, H)
  
  simCanvas = createGraphics(Wsim, Hsim)
  
  plotCanvas = createGraphics(Wplot, Hplot)
  plotCanvas.background(20)
  plotCanvas.stroke(255)
  plotCanvas.strokeWeight(3)
  plotCanvas.noFill()
  plotCanvas.rect(0, 0, Wplot, Hplot)
  ...
}

 function draw(){
  //border of simCanvas
  simCanvas.clear()
  simCanvas.stroke(255)
  simCanvas.strokeWeight(2)
  simCanvas.noFill()
  simCanvas.rect(10, 10, Wsim - 20, Hsim - 20)
  
  //sim canvas
  image(simCanvas, 0, 0);
  
  //plot canvas toggle
  if (plotCheckbox.checked) {
    ...
    image(plotCanvas, Wsim - Wplot - 30, 30)
  }
  ...
} 

thephysicshub's People

Contributors

20akshay00 avatar advait-l avatar bonimart avatar brtymn avatar dependabot[bot] avatar jom9 avatar justusmattern avatar lofung avatar p479h avatar rusandris avatar sanjj1 avatar screeeech avatar sjcobb2022 avatar sudheer121 avatar xpolar avatar yardenshoham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thephysicshub's Issues

Orbital Trajectory Simulation

Electric Field Simulation

A simulation that shows orbital motion. May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The idea is pretty straightforward. Further ideas can be discussed here.

Theory Section For Collision

Theory Section For Collision Simulation

The theory section for the collision simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Coupled pendulum spinning out of control

Coupled pendulum simulation spinning out of control

With certain settings, the coupled pendulum simulation spins out of control instead of oscilating.
Settings:
Mass #1 0.2
Mass #2 10
Initial angle #1 -90
Initial angle #2 0
Pendulum length 0.2
Separation length 0.6
Spring rest length 0.6
Spring constant 5
g 9.8

Pendulum #1 spins around instead of oscillating

Type of issue

  • New Feature
  • Bug
  • Documentation

Planetary orbit and kepler laws simulation

Simulation of planetary orbits

Simple setup with two bodies, probably a very heavy centre and a lighter 'planet'. Not specifically pertaining to planets as in the solar system (such sims exist and are quite good too), but rather two abstract bodies, with the intention being the study of the influence of the central potential on the bodies.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Implementations

Can include options to change initial energy, angular momenta, etc to observe the type of orbits formed, when they close, how the parameters affect the equation of the conic section followed. Can also appeal to higher lvl audiences by display of the LRL vector.
Bonus:
Implement in 3D, allow user to change the central potential (1/r^n) say, for instance 1/r^3 exhibits precessing orbits which are interesting to demonstrate.

Specific emphasis on abstraction to a 2 body system, unlike the existing n body simulation, to let the kepler orbits take the central stage. Also highly recommend 3D simulation, along with ability to set the direction of angular momentum vector to see how it varies/does not vary through the motion. Theory can explain a brief newtonian approach to deriving the behaviour, along with references to the lagrangian approach to this to open up more detailed study of the system.

Issue From A Reddit User - Web Dev

Github and Patreon Logos

The comment by the redditor: Heads-up: you might want to tweak your markup on the https://physicshub.herokuapp.com/contribute page - I found that the logo images were being blocked by my ad blocker.

Realistically, the text for "GitHub" and "Patreon" could just as easily be linked - when I couldn't see the logos, I moused over the text and was bemused that neither word was hyperlinked. My $0.02 though...

Type of issue

  • New Feature
  • Bug
  • Documentation

Adding Light Theme to UI

Can we add a light theme to the website as some users are more comfortable with a light background ?

Doppler Effect

Doppler Effect

Simulation demonstartes the work of Doppler Effect.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

Theory Section For Single Pendulum

Theory Section For Single Pendulum Simulation

The theory section for the single pendulum simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Theory Section For Elastic Pendulum

Theory Section For Elastic Pendulum Simulation

The theory section for the elastic pendulum simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Theory Section For Force Table

Theory Section For Force Table Simulation

The theory section for the force table simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Wave on a string simulation

Wave on a string

Simulation involving propagation of transverse waves on ideal strings. It can demonstrate reflection off hard boundaries and open ends, as well as a junction of strings with different physical parameters (mass/length).

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

This could be done with finite differences and recursive matrix operations ( I believe mathjs offers sparse matrix methods).

New Sim Request: Force Table

Commonly used physics/engineering lab is a force table. A simulated version of this lab would be quite popular since they are ubiquitous in those two majors.

The general idea is to simulate the placement of weights on pulleys (adjustable along the circumference of a given circular table parallel to the ground) to reflect given forces, usually a set of 2-D forces acting on a common point (a small disc that the threads are attached too, that are not in equilibrium are presented and the user is expected to determine and set the equilibrant force required to bring the system into equilbrium.

Once that force is placed a pin to release the free floating disc is pulled and if the student has correctly placed the equilibrant force the disc stays stationary, if not then the disc proceeds to follow Newton's law and accelerates in the reaction force direction accordingly.

Single and Double Slit Diffraction Simulation

Single and Double Slit Diffraction Simulation

A simulation that shows the single and double slit diffraction. May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The idea is pretty straightforward. Further ideas can be discussed here.

Electric Field Simulation

Electric Field Simulation

A simulation that shows electric fields. May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The idea is pretty straightforward. Further ideas can be discussed here.

Projectile Motion Simulation

Short Descriptive Title

Please include the the issue here. If it is a bug, please write the steps to reproduce the bug.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

Implementing a projectile motion simulator. User can adjustable various settings.

Linearly increasing distributed load on a straight member simulation

Linearly increasing distributed load on a straight member simulation

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

Perhaps the person can select the intensity of the load, and the slope of the load, and the simulation can graph the free body diagram, the shear force diagram, and the bending moment diagram. Maybe even you could choose whether the beam was simply supported, or has a fixed support on one end, or on both ends. Point loads could also be considered for the same, as well as point moments.

Magnetic Field Simulation

Magnetic Field Simulation

A simulation that shows magnetic fields. May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The idea is pretty straightforward. Further ideas can be discussed here.

Ray Optics Simulation

User Friendly Ray Optics Simulation

A ray optics simulation that will possibly include mirrors and lenses. The simulation may also include some theory in it for fun.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The simulation needs to be as user friendly as possible. Other ray optics simulations are frustrating and hard to use.

2D sliding and static friction

Sliding and static friction in 2D

This simulation show how sliding and static friction affects a body moving on a surface.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

A 2D simulation which show how sliding and static friction works by having the user move a square on a flat

Photoelectric Effect Simulation

Photoelectric Effect Simulation

A simulation that shows the "Photoelectric Effect". May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

A simulation that proves the concept by showing the photoelectric effect on a metal surface.

Documentation for adding theory sections w/ Mathjax to the simulations

Documentation for theory sections

New contributors (writing the theory stuff) will require some instructions on how to add the content to the simulation pages, which is not available on the repo at the moment.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

Faraday's Law of Induction Simulation

Faraday's Law of Induction Simulation

A simulation that shows "Faraday's Law of Induction". May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The idea is pretty straightforward. Further ideas can be discussed here.

Theory Section For Coupled Pendulum

Theory Section For Coupled Pendulum Simulation

The theory section for the coupled pendulum simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Theory Section For The 2D Double Pendulum

Theory Section For Collision Simulation

The theory section for the 2d double pendulum simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Theory Section For N-Body

Theory Section For N-Body Simulation

The theory section for the n-body simulation is needed.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

The theory section needs to be written with university level physics.

Vectors Simulation

Vector Lab

As Vectors is the most fundamental concept in Physics So, there can be a lab for that where we can have some vectors set their magnitudes and see the resultant

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

I can work on it but I can't do it alone, I need someone's help.

Simulation Template

Simulation Template

A well documented simulation template to facilitate the simulation creating process.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

An improved version of what is already on README.md

Electrical Circuit Simulation

Electrical Circuit Simulation

An electrical circuit simulation is needed. May include some theory that will make the simulation more meaningful.

Type of issue

  • New Feature
  • Bug
  • Documentation

Possible Fixes / Implementations

Should include basic circuit elements and relevant graphs.

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.