Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyneu committed Aug 1, 2020
1 parent a052ec9 commit 0e13522
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 5 deletions.
2 changes: 2 additions & 0 deletions js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import m4 from './simulation/m4.js';
import { numberOfStarsInAllRingsOneGalaxy, totalNumberOfBodies }
from './simulation/initial_conditions.js';


// Adjust the size of the drawing region (canvas) based on the size of
// the web browser window
function fitToContainer(drawData){
Expand Down Expand Up @@ -190,6 +191,7 @@ export function loadColors(drawData, initialParams) {
gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
}


/**
* Load star star sizes into the GPU buffer
*
Expand Down
1 change: 1 addition & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {init as initUserInput} from './user_input.js';
import * as showFps from './show_fps.js';
import { updateCameraDistance } from './zoom.js';


/**
* Calculate positions of stars at the next time stamp and redraw the
* stars on screen. This function is called at each frame of the animation,
Expand Down
3 changes: 0 additions & 3 deletions js/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import m4 from './simulation/m4.js';
import * as simulation from './simulation.js';




/**
* Return initial parameters of the simulation, they can't be changed without
* restart (except for masses)
Expand All @@ -30,7 +28,6 @@ export function getInitialParameters() {
}



/**
* Return parameters that can change during the simulation.
*
Expand Down
1 change: 1 addition & 0 deletions js/refresh_rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function measure(measurements) {
return Math.round(1000 / medium);
}


/**
* Stores time of the animation frame. The method is called multiple time
* for each animation frame until the number of `tries` is exceeded.
Expand Down
6 changes: 6 additions & 0 deletions js/rotate_on_touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import m4 from './simulation/m4.js';


function startMoving(state, e) {
state.moving = true;
state.lastPosition = [e.pageX, e.pageY];
if (state.didStartRotating) state.didStartRotating();
}


function startTouching(state, e) {
if (e.targetTouches.length === 2) {
// Touching with two fingers.
Expand All @@ -19,6 +21,7 @@ function startTouching(state, e) {
if (e.targetTouches.length === 1) startMoving(state, e.targetTouches[0]);
}


function move(state, currentParams, e) {
if (!state.moving) return;
if (!state.lastPosition) return;
Expand All @@ -43,6 +46,7 @@ function move(state, currentParams, e) {
state.lastPosition = [e.pageX, e.pageY];
}


function touchMove(state, currentParams, e) {
if (e.targetTouches.length === 2) {
// Touching with two fingers.
Expand All @@ -56,11 +60,13 @@ function touchMove(state, currentParams, e) {
}
}


function stopMoving(state) {
state.moving = false;
if (state.didStopRotating) state.didStopRotating();
}


/**
* Start detecting rotation of the scene.
*
Expand Down
17 changes: 17 additions & 0 deletions js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function readFloat(str) {
return parsed;
}


/**
* Parse comma separated values into an array of floats.
*
Expand All @@ -24,6 +25,7 @@ export function readArrayOfFloats(str) {
return readArrayOfNumbers(str, parseFloat);
}


/**
* Parse comma separated values into an array of integers.
*
Expand All @@ -34,6 +36,7 @@ export function readArrayOfInts(str) {
return readArrayOfNumbers(str, parseInt);
}


/**
* Parse comma separated values into an array of integers.
*
Expand All @@ -52,6 +55,7 @@ export function readArrayOfNumbers(str, parseFn) {
return parsed;
}


/**
* Rounds a float number of given number of decimal places
* Source: https://stackoverflow.com/a/56632526/297131
Expand All @@ -61,10 +65,12 @@ export function roundN(value, digits) {
return (Math.round(value * tenToN)) / tenToN;
}


export function roundFloat(decimalPlaces) {
return (value) => roundN(value, decimalPlaces);
}


export function roundArray(decimalPlaces) {
return (arr) => arr.map((a) => roundN(a, decimalPlaces));
}
Expand Down Expand Up @@ -93,6 +99,7 @@ let sharedInitialParams = {
}
};


// The keys are names of current parameters that can be shared.
// The values are functions for parsing string value from URL.
// The values are:
Expand All @@ -113,6 +120,7 @@ let sharedCurrentParams = {
}
};


/**
* Returns the full URL to the simulation for sharing containing
* all the selected parameters
Expand All @@ -123,6 +131,7 @@ export function getShareURL(initialParams, currentParams) {
return `${urlStart}?${urlParams}`;
}


/**
* Returns the last part of the URL containing the parameters
*/
Expand All @@ -146,6 +155,7 @@ export function filterInitialParams(initialParams) {
return filterParams(sharedInitialParams, initialParams);
}


/**
* Keeps only permitted current parameters that will be used for sharing.
*
Expand All @@ -156,6 +166,7 @@ export function filterCurrentParams(currentParams) {
return filterParams(sharedCurrentParams, currentParams);
}


/**
* Keeps only parameters permitted for sharing.
*
Expand All @@ -176,6 +187,7 @@ function filterParams(sharedParams, allParams) {
return filtered;
}


export function prepareParamsForSharing(params, sharedParams) {
let result = {};

Expand All @@ -195,10 +207,12 @@ export function prepareParamsForSharing(params, sharedParams) {
return result;
}


function getCurrentUrlWithoutParameters() {
return location.protocol + '//' + location.host + location.pathname;
}


/**
* Get the initial parameters from the URL string.
*
Expand All @@ -209,6 +223,7 @@ export function getSharedInitialParameters(defaultParams) {
return getSharedInitialParametersFromUrl(location.search, defaultParams);
}


/**
* Get the initial parameters from the URL string.
*
Expand All @@ -221,6 +236,7 @@ export function getSharedInitialParametersFromUrl(urlParams, defaultParams) {
return getParametersFromUrl(urlParams, defaultParams, sharedInitialParams);
}


/**
* Get the current parameters from the URL string.
*
Expand All @@ -231,6 +247,7 @@ export function getSharedCurrentParameters(defaultParams) {
return getSharedCurrentParametersFromUrl(location.search, defaultParams);
}


/**
* Get the current parameters from the URL string.
*
Expand Down
1 change: 1 addition & 0 deletions js/show_fps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Shows current FPS (frames per second) to check the performance of the system


export function init() {
var state = {
// The time stamp of the previous frame
Expand Down
15 changes: 14 additions & 1 deletion js/simulation.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Get positions of stars from the physics simulation
// Calculate positions of stars using the physics simulation

import * as trajectories from './trajectories.js';
import * as init from './simulation/initial_conditions.js';
import getAccelerations from './simulation/acceleration.js';
import integrateOneStep from './simulation/integrator.js';


/**
* Calculate initial positions of stars
*/
export function setInitial(initialParams, currentParams) {
var { positions, velocities } = init.allPositionsAndVelocities(initialParams);

Expand All @@ -19,6 +23,10 @@ export function setInitial(initialParams, currentParams) {
currentParams.velocities = velocities;
}


/**
* Evolves the simulation by given number of seconds (fastForwardSeconds).
*/
function fastForward(initialParams, currentParams) {
var timeSteps = Math.round(Math.abs(currentParams.fastForwardSeconds *
currentParams.screenRefreshRateFPS));
Expand All @@ -38,6 +46,10 @@ function fastForward(initialParams, currentParams) {
}
}


/**
* Evolves the simulation by one time step.
*/
export function update(initialParams, currentParams) {
if (currentParams.rotating) return;

Expand All @@ -59,6 +71,7 @@ export function update(initialParams, currentParams) {
trajectories.update(currentParams.trajectoriesState, currentParams.positions);
}


/**
* Calculate the time step given the screen refresh rate.
* The point of this is to make the speed of the simulation independent
Expand Down
8 changes: 8 additions & 0 deletions js/sliders.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import SickSlider from './sick_slider.js';


function didChangeTimeStep(currentParams) {
return function(value, position) {
currentParams.timeStep = value;
};
}


function didChangeRings(initialParams, currentParams, galaxyIndex, onRestart) {
return function(value, position) {
initialParams.numberOfRings[galaxyIndex] = value;
Expand All @@ -22,6 +24,7 @@ function didChangeRings(initialParams, currentParams, galaxyIndex, onRestart) {
};
}


function didChangeMass(initialParams, currentParams, galaxyIndex, onRestart) {
return function(value, position) {
initialParams.masses[galaxyIndex] = value;
Expand All @@ -36,6 +39,7 @@ function didChangeMass(initialParams, currentParams, galaxyIndex, onRestart) {
};
}


function didChangeDistance(initialParams, currentParams, onRestart) {
return function(value, position) {
initialParams.minimalGalaxySeparation = value;
Expand All @@ -50,6 +54,7 @@ function didChangeDistance(initialParams, currentParams, onRestart) {
};
}


function didChangeEccentricity(initialParams, currentParams, onRestart) {
return function(value, position) {
initialParams.eccentricity = value;
Expand All @@ -64,6 +69,7 @@ function didChangeEccentricity(initialParams, currentParams, onRestart) {
};
}


function didChangeAngle(initialParams, currentParams, galaxyIndex, onRestart) {
return function(value, position) {
initialParams.galaxyInclinationAnglesDegree[galaxyIndex] = value;
Expand All @@ -78,6 +84,7 @@ function didChangeAngle(initialParams, currentParams, galaxyIndex, onRestart) {
};
}


function didChangeRingSeparation(initialParams, currentParams, onRestart) {
return function(value, position) {
initialParams.ringSeparation = value;
Expand All @@ -92,6 +99,7 @@ function didChangeRingSeparation(initialParams, currentParams, onRestart) {
};
}


export function setupSlider(initialParams, currentParams, onRestart) {
SickSlider(".TwoGalaxies-sliderTimeStep", {
label: 'Time step: ',
Expand Down
1 change: 1 addition & 0 deletions js/trajectories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Store the trajectories of the two galaxy cores


/**
* Store initial trajectories
*
Expand Down
3 changes: 2 additions & 1 deletion js/user_input.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Taking input from the user: buttons clicks, zoom, rotation.
// Taking input from the user: buttons clicks, zoom, rotation

import * as rotate from './rotate_on_touch.js';
import * as zoom from './zoom.js';
import * as sliders from './sliders.js';
import * as buttons from './buttons.js';


export function init(drawData, initialParams, currentParams, onRestart) {
sliders.setupSlider(initialParams, currentParams, onRestart);
buttons.init(initialParams, currentParams);
Expand Down
Loading

0 comments on commit 0e13522

Please sign in to comment.