Skip to content

Commit

Permalink
Merge pull request #15 from ben9583/0.5.1
Browse files Browse the repository at this point in the history
Release 0.5.1
  • Loading branch information
ben9583 authored Jun 24, 2022
2 parents c3aeb36 + 06ce50c commit d57bc20
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "solar-sim"
version = "0.5.0"
version = "0.5.1"
authors = ["Ben Plate <bplate9583@gmail.com>"]
edition = "2018"
description = "Physics simulator written in Rust WASM for use in Solar Sim website"
Expand Down
25 changes: 12 additions & 13 deletions website-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<body>
<button id="toggle">Pause</button>
<button id="reset">Reset</button>
<input type="checkbox" id="debug" /><span style="color:white">Enable Debug (slightly lowers performance)</span>
<div id="debugSection" style="color:white;display:inline;margin-left:10px">
<span style="margin-right:10px"># of bodies: <span id="numBodies">6</span></span>
<span style="margin-right:10px">Simulation tick time: <span id="simTickTime">10</span><span>μs</span></span>
<span style="margin-right:10px">Draw tick time: <span id="drawTickTime">10</span><span>μs</span></span>
</div>
<div id="canvasContainer">
<canvas width="1280" height="720" id="trails"></canvas>
<canvas width="1280" height="720" id="scene"></canvas>
Expand Down Expand Up @@ -42,9 +48,9 @@
</div>

<div style="color:white;">
<p style="margin-bottom:0">Settings:</p>
<div style="float:left;padding-right:25px">
<p>Trail quality:</p>
<p style="margin-bottom:0;margin-top:25px">Settings:</p>
<div style="float:left;padding-right:25px;margin-top:5px">
<p style="margin-top:5px;margin-bottom:5px;">Trail quality:</p>
<div>
<input type="radio" id="highTrailQuality" name="trailQuality" value="high" checked="checked"/>
<label for="highTrailQuality">High</label><br />
Expand All @@ -56,8 +62,8 @@
<label for="noneTrailQuality">None</label><br />
</div>
</div>
<div style="color:white;float:left;padding-right:25px">
<p>Simulation Accuracy:</p>
<div style="float:left;padding-right:25px;margin-top:5px">
<p style="margin-top:5px;margin-bottom:5px;">Simulation Accuracy:</p>
<div>
<input type="radio" id="highSimAccuracy" name="simAccuracy" value="high" />
<label for="highSimAccuracy">High</label><br />
Expand All @@ -67,14 +73,7 @@
<label for="lowSimAccuracy">Low</label><br />
</div>
</div>
<div style="clear:left;height:50px"></div>

<input type="checkbox" id="debug" /><span style="color:white">Enable Debug (slightly lowers performance)</span>
<div id="debugSection" style="color:white">
<p># of bodies: <span id="numBodies">6</span></p>
<p>Simulation tick time: <span id="simTickTime">10</span><span>μs</span></p>
<p>Draw tick time: <span id="drawTickTime">10</span><span>μs</span></p>
</div>
<div style="clear:left;height:25px"></div>
</div>

<script src="./bootstrap.js"></script>
Expand Down
44 changes: 27 additions & 17 deletions website-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ let trails = [

for(let i = 0; i < bodies.length; i++) {
let body = bodies[i];

SolarSim.add_body(body.mass, body.position[0], body.position[1], body.initialVelocity[0], body.initialVelocity[1]);
}

Expand Down Expand Up @@ -168,33 +167,41 @@ function getMousePos(canvas, evt) {
}

canvas3.addEventListener("mouseenter", () => {
mouseInCanvas = true;
if(dropAdderEnabled) {
mouseInCanvas = true;
}
});
canvas3.addEventListener("mouseleave", () => {
mouseInCanvas = false;
ctx3.clearRect(0, 0, WIDTH, HEIGHT);
if(dropAdderEnabled) {
mouseInCanvas = false;
ctx3.clearRect(0, 0, WIDTH, HEIGHT);
}
});
canvas3.addEventListener("mousedown", (elem, e) => {
mouseClicking = true;
let pos = getMousePos(canvas3, elem);
if(dropAdderEnabled) {
mouseClicking = true;
let pos = getMousePos(canvas3, elem);

clickedX = pos.x;
clickedY = pos.y;
clickedX = pos.x;
clickedY = pos.y;
}
});
canvas3.addEventListener("mouseup", (elem, e) => {
mouseClicking = false;
let pos = getMousePos(canvas3, elem);
if(dropAdderEnabled) {
mouseClicking = false;
let pos = getMousePos(canvas3, elem);

let distX = (clickedX - pos.x) / 25;
let distY = (clickedY - pos.y) / 25;
let distX = (clickedX - pos.x) / 25;
let distY = (clickedY - pos.y) / 25;

const name = document.getElementById("dropName").value;
const mass = parseFloat(document.getElementById("dropMass").value);
const radius = parseFloat(document.getElementById("dropRadius").value);
const name = document.getElementById("dropName").value;
const mass = parseFloat(document.getElementById("dropMass").value);
const radius = parseFloat(document.getElementById("dropRadius").value);

addBody(name, mass, radius, clickedX, clickedY, distX, distY);
addBody(name, mass, radius, clickedX, clickedY, distX, distY);

step(false);
step(false);
}
});
canvas3.addEventListener("mousemove", (elem, e) => {
if(dropAdderEnabled) {
Expand Down Expand Up @@ -277,6 +284,9 @@ function step(simulate) {
let inBounds = (newPositions[i * 2] >= 0 && newPositions[i * 2] < WIDTH && newPositions[i * 2 + 1] >= 0 && newPositions[i * 2 + 1] < HEIGHT);
let inSimBounds = (newPositions[i * 2] >= -WIDTH && newPositions[i * 2] < 2 * WIDTH && newPositions[i * 2 + 1] >= -HEIGHT && newPositions[i * 2 + 1] < 2 * HEIGHT)

body.position[0] = newPositions[i * 2];
body.position[1] = newPositions[i * 2 + 1];

if(!inSimBounds) {
ctx2.fillStyle = "black";
for(let j = 0; j < trails[i].length; j++) {
Expand Down
2 changes: 1 addition & 1 deletion website-src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website-src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solar-sim-app",
"version": "0.5.0",
"version": "0.5.1",
"description": "Creates the Solar Sim website.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d57bc20

Please sign in to comment.