Giter Site home page Giter Site logo

gravity-simulator's Introduction

2018 Refactor

I have set a goal to refactor this application in 2018-2019. I want this application to be highly usable on desktops, tablets, and mobile devices, with a user interface that adapts to the device but lets desktop users still be able to use the more complicated toolset.

The first issue to resolve is migrating to VueJS and a ES6 module system.

Goals for the refactor

  • new much improved Desktop/tablet/phone ui
  • touch input support
  • new logo
  • Dark/light theme
  • Webassembly barnes hutt algorithm implementation

How is the code structured?

I used the AMD module system to build the application, specifically I use require.js for a module loader

There are three seperate modules

js/gravity/spacetime.js

A module that stores all objects and performs calculations on those objects at a set speed and accuracy.

js/gravity/branes-hut.js

There's a separate branched called 'barnes-hut' which has an implementation of the barnes-hut algorithm. Supposed to be a plug and play thing where you can toggle it for greater speeds

js/gravity/new_render.js

The old gui and render modules have been scrapped for a new combined one that doesn't have the same annoying problem of shared state of things like the cursor or camera. Currently being worked on, sorry for any annoyance

gravity-simulator's People

Contributors

hermannbjorgvin avatar muhsinfatih avatar pluckerpluck avatar ricardofiorani avatar thecodewarrior 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

gravity-simulator's Issues

Custom Mass Zooming

So while I was playing around with this amazing tool, I noticed that whenever I tried created a relatively small custom mass while I was zoomed in (so I can easily make moon sized objects), the size that I come out with doesn't correspond to that of the zoom but rather to a size as if it wasn't zoomed at all. Can you fix this so that the output size corresponds to the zoom factor? There is also a bug relating to the disc generator and the auto orbit custom mass, where once you create a custom mass, the disc function no longer works. Also while you're at it could you add a setting to make it so centering on an object is less tedious (especially for when you have a large amount of objects)? And also an ability to edit the inner and outer radius of a disc? Not trying to sound demanding, but can you fix/add these?

Setting calculation speed high makes calculations imprecise

When you set the calculation speed high (10 or 100 or so), objects don't behave the same, instead they often fling out into space where they have previously rotated regularly. The cause is probably that the calculation speed setting doesn't actually set the time between steps, but instead takes larger steps at once. This make small imprecisions become very big.

Zero zoom is possible, crashes script

Steps to reproduce

  1. Load page.
  2. Reduce zoom until it reads zero.
  3. Crash.

Firefox specifically reports this error:

A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.

Script: http://hermann.is/gravity/js/gravity/modules/render.js:273

Expected behaviour

Form field does not allow setting zero zoom. Script enforces a minimum value on zoom, or else raises an error if given zero zoom.

Delete focused object

Would we be able to have the ability to remove the focused object or any other way to remove single objects? It would be extremely useful for both experimenting and, specifically, watching solar systems form from a raw disk (one without a central object)

Another feature request would be, in a similar vein, the ability to create disks without a central object, for the purpose of watching systems form from a cloud

License?

Thank you for interesting and educational project. What a License for using and changing your code? You didn't choose one.

Fix object collision so it complies with the conservation of energy

In the file js/gravity/modules/spacetime.js you can find a snippet of code that joins objects if they are close enough to eachother. This can be improved in various ways but one is to fix the wrong math that I used. When two objects join they don't work within the first law of thermodynamics, which is not optimal.

I'm not sure how to fix it in a way that also maintains the gravitational potential energy as well though

50 lines from 115 and 165 in spacetime.js

        // Find clustering objects and join them - unfinished
        // THIS IS CURRENTLY PHYSICALLY INNACCURATE, WILL FIX SOON
        for (var a = spacetime.length - 1; a >= 0; a--) {
            var objectA = spacetime[a];

            for (var b = spacetime.length - 1; b >= 0; b--) {
                if (a !== b) {
                    var objectB = spacetime[b];

                    if (
                        pythagoras(objectA, objectB) < getObjectRadius(objectA) + getObjectRadius(objectB)
                    ){
                        var camFocus = false;
                        if(objectB.cameraFocus === true || objectA.cameraFocus === true){
                            camFocus = true;
                        }

                        // Splice the objects from 
                        spacetime = _.without(spacetime, objectA);
                        spacetime = _.without(spacetime, objectB);

                        var newMass = objectA.mass + objectB.mass;
                        var massRatio = objectA.mass/newMass;

                        var newMomentum = getMomentum(objectA) + getMomentum(objectB);
                        var momentumRatio = newMomentum/getMomentum(objectA);

                        var newDensity = objectA.density*massRatio + objectB.density*(1-massRatio);

                        var newObject = {
                            cameraFocus: camFocus,
                            x: objectA.x*getMomentum(objectA)/newMomentum + objectB.x*getMomentum(objectB)/newMomentum, // Change later
                            y: objectA.y*getMomentum(objectA)/newMomentum + objectB.y*getMomentum(objectB)/newMomentum, // Change later
                            velX: objectA.velX*objectA.mass/newMass + objectB.velX*objectB.mass/newMass, // Change later
                            velY: objectA.velY*objectA.mass/newMass + objectB.velY*objectB.mass/newMass, // Change later
                            deltaX:0, // useless info
                            deltaY:0, // useless info
                            mass: newMass, 
                            density: newDensity,
                            path: []
                        };

                        // Give the new object the larger objects previous path, looks nicer
                        var newPath = objectA.mass >= objectB.mass ? objectA.path : objectB.path;
                        newObject.path = newPath;

                        spacetime.push(newObject);
                    };
                };
            };
        };

Some improvements sugestion

Hi @HermannBjorgvin ,

I believe this project has potential to be used in schools to teach the basic concepts of gravity.
It would be a very nice tool to be used by teachers around the world.

For this, it need some improvements:

  • Translation to more languages
  • We could use texture on the objects to look more like astronomical objects. The purpose of this is to make the UI to look more like a "game" to get interest of kids. These textures can be provided by some free to use video game assets website.
  • Make it usable in mobile/tablets. For this we could:
    • Make the menu visibility togglable by some button (to get more space)
    • Detect both events from mouse and from touch
  • Make it able to save and load (from cookies maybe ?) the created systems.
  • Would be nice if right clicking an object and it shows some info like it's mass and speed.
  • A Pause button (it just sets the calculation speed to 0)
  • The calculation speed should never be negative, since the we can not guarantee that the objects states will be the same.
  • When creating a new object, we could show a line to preview the direction that the object would take. It would help a lot to create systems.

All of these are just my opinion of improvements that would be nice, but it might take the project to a whole new direction that you may not like or don't want for it.
I'm likely to do most of these improvements in my free times, but I would like to know about what you think about this.

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.