Skip to content

Commit

Permalink
Merge pull request #17 from ben9583/0.7.0
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
ben9583 authored Nov 25, 2022
2 parents 64fde30 + 503468e commit 9ab23bb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 49 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.6.0"
version = "0.7.0"
authors = ["Ben Plate <bplate9583@gmail.com>"]
edition = "2018"
description = "Physics simulator written in Rust WASM for use in Solar Sim website"
Expand Down
16 changes: 8 additions & 8 deletions website-src/cookiePolicy.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
<body>
<div style="max-width: 960px">
<h1>Cookie Policy</h1>
<p>Last updated: 24 June 2022</p>
<p>Last updated: 25 November 2022</p>
<p>
In order to provide a better user experience, this website uses cookies to save data across browsing sessions.
Your use of this website does <b>not</b> imply an acceptance of these cookies and you must manually accept them by checking the box at the top of the landing page.
In doing so, you agree to the complete use of cookies by this website according to this policy as permitted by law.
In order to provide a better user experience, this service (Solar Sim) uses cookies to save data across browsing sessions.
Your use of this service does <b>not</b> imply an acceptance of these cookies and you must manually accept them by checking the box at the top of the landing page.
In doing so, you agree to the complete use of cookies by this service according to this policy as permitted by law.
</p>
<p>
Although this website uses cookies, it does not track personal data that can be used for identification.
The website also does not use any third-party cookies, including tracking technologies such as Google Analytics.
Your cookies will not be sold or provided to any other third parties except where required by law.
This service does not use cookies that can be used to identify you personally.
However, the website this is hosted on may have a different cookie policy that you should review and accept separately.
Your cookies from this service will not be sold or provided to any other third parties except where required by law.
</p>
<p>
Should you choose not to accept the use of cookies, you will still be able to use this website with the understanding that some functionality may be limited.
</p>
<p>
A list of all cookies used and their purpose can be found below:
A list of all cookies used by this service and their purposes can be found below:
</p>
<table>
<thead>
Expand Down
48 changes: 21 additions & 27 deletions website-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<body>
<div id="cookieNotice">
<input type="checkbox" id="cookieAcceptance" /><span style="color:white">This website optionally uses cookies. A comprehensive policy can be viewed <a href="cookiePolicy.html">here</a> (updated 24 June 2022). By checking this box, you give permission for using these cookies; you can revoke permissions at any time by unchecking this box.</span>
<input type="checkbox" id="cookieAcceptance" /><span style="color:white">This website optionally uses cookies. A comprehensive policy can be viewed <a href="cookiePolicy.html">here</a> (updated 25 November 2022). By checking this box, you give permission for using these cookies; you can revoke permissions at any time by unchecking this box.</span>
<script>
if(document.cookie.length > 0) document.getElementById("cookieAcceptance").checked = true;

Expand All @@ -24,12 +24,6 @@
</div>
<button id="toggle">Pause</button>
<button id="reset">Reset</button>
<input type="checkbox" id="debug" /><span style="color:white">Enable Debug (May need to enable precise timers in browser)</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 All @@ -41,17 +35,21 @@
<label for="dropAdderButton">Drop Adder (click and drag in canvas)</label><br />

<div id="dropAdder" style="display:none">
<input id="dropName" type="text" placeholder="Name" />
<input id="dropMass" type="number" placeholder="Mass" />
<input id="dropRadius" type="number" placeholder="Radius" />
<span>Click to drop at mouse, drag to give velocity</span>
<!-- <input id="dropName" type="text" placeholder="Name" /> -->
<input type="radio" id="dropSizeSmall" name="dropSize" value="small" />
<label for="dropSizeSmall">Small</label>
<input type="radio" id="dropSizeMedium" name="dropSize" value="medium" checked="checked" />
<label for="dropSizeMedium">Medium</label>
<input type="radio" id="dropSizeLarge" name="dropSize" value="large" />
<label for="dropSizeLarge">Large</label>
<span style="position:relative;left:10px">Click to drop at mouse, drag to give velocity</span>
</div>

<input type="radio" id="preciseAdderButton" name="adderMethod" value="preciseAdderButton" />
<label for="preciseAdderButton">Precise Adder (type in position and velocity)</label><br />

<div id="preciseAdder" style="display:none">
<input id="preciseName" type="text" placeholder="Name" />
<!-- <input id="preciseName" type="text" placeholder="Name" /> -->
<input id="preciseMass" type="number" placeholder="Mass" />
<input id="preciseRadius" type="number" placeholder="Radius" />
<input id="precisePositionX" type="number" placeholder="Position: X" />
Expand All @@ -69,21 +67,8 @@
<button id="loadButton">Load</button>
<button id="clearButton">Clear</button>
<span id="saveMessage"></span><br />
<div style="margin-top:5px"><span>Saves list: </span><button id="showSavesList">Show</button></div>
<p id="savesList" style="display:none"></p>
<script>
document.getElementById("showSavesList").addEventListener("click", function() {
let savesList = document.getElementById("savesList");
let savesListButton = document.getElementById("showSavesList");
if (savesList.style.display == "none") {
savesList.style.display = "block";
savesListButton.innerHTML = "Hide";
} else {
savesList.style.display = "none";
savesListButton.innerHTML = "Show";
}
});
</script>
<div style="margin-top:5px"><span>Saves list: </span></div>
<p id="savesList"></p>
</div>

<div style="color:white;">
Expand All @@ -101,6 +86,7 @@
<label for="noneTrailQuality">None</label><br />
</div>
</div>

<div style="float:left;padding-right:25px;margin-top:5px">
<p style="margin-top:5px;margin-bottom:5px;">Simulation Accuracy:</p>
<div>
Expand All @@ -112,7 +98,15 @@
<label for="lowSimAccuracy">Low</label><br />
</div>
</div>

<div style="clear:left;height:25px"></div>

<input type="checkbox" id="debug" /><span style="color:white">Enable Debug (May need to enable precise timers in browser)</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>

<script src="./bootstrap.js"></script>
Expand Down
53 changes: 42 additions & 11 deletions website-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,27 @@ let trails = [
[],
]

let dropSizeMaps = {
"small": {
mass: 1,
radius: 4
},
"medium": {
mass: 1e10,
radius: 10
},
"large": {
mass: 5e12,
radius: 32
}
}

for(let i = 0; i < bodies.length; i++) {
let body = bodies[i];
SolarSim.add_body(body.mass, body.position[0], body.position[1], body.velocity[0], body.velocity[1]);
}

function addBody(name, mass, radius, positionX, positionY, velocityX, velocityY) {
if(isNaN(mass) || isNaN(radius) || isNaN(positionX) || isNaN(positionY) || isNaN(velocityX) || isNaN(velocityY) || !(isFinite(mass) && isFinite(radius) && isFinite(positionX) && isFinite(positionY) && isFinite(velocityX) && isFinite(velocityY)) || Math.abs(radius) < 0.01)
return;

function randomColor() {
let red = Math.floor(Math.random() * 256).toString(16);
let green = Math.floor(Math.random() * 256).toString(16);
let blue = Math.floor(Math.random() * 256).toString(16);
Expand All @@ -91,13 +103,20 @@ function addBody(name, mass, radius, positionX, positionY, velocityX, velocityY)
if(green.length == 1) green = "0" + green;
if(blue.length == 1) blue = "0" + blue;

return "#" + red + green + blue;
}

function addBody(name, mass, radius, positionX, positionY, velocityX, velocityY) {
if(isNaN(mass) || isNaN(radius) || isNaN(positionX) || isNaN(positionY) || isNaN(velocityX) || isNaN(velocityY) || !(isFinite(mass) && isFinite(radius) && isFinite(positionX) && isFinite(positionY) && isFinite(velocityX) && isFinite(velocityY)) || Math.abs(radius) < 0.01)
return;

bodies.push({
name: name,
mass: mass,
radius: radius,
position: [positionX, positionY],
velocity: [velocityX, velocityY],
color: "#" + red + green + blue,
color: randomColor(),
});

trails.push([]);
Expand Down Expand Up @@ -137,6 +156,18 @@ preciseAdderButton.addEventListener("click", () => {
dropAdderEnabled = false;
})

const dropSizeSmallElem = document.getElementById("dropSizeSmall");
const dropSizeMediumElem = document.getElementById("dropSizeMedium");
const dropSizeLargeElem = document.getElementById("dropSizeLarge");

let selectedDropSize = "medium";

dropSizeSmallElem.addEventListener("click", (elem, e) => selectedDropSize = "small");
dropSizeMediumElem.addEventListener("click", (elem, e) => selectedDropSize = "medium");
dropSizeLargeElem.addEventListener("click", (elem, e) => selectedDropSize = "large");

dropSizeSmallElem.checked ? selectedDropSize = "small" : dropSizeMediumElem.checked ? selectedDropSize = "medium" : selectedDropSize = "large";

const highTrailQualityElem = document.getElementById("highTrailQuality");
const mediumTrailQualityElem = document.getElementById("mediumTrailQuality");
const lowTrailQualityElem = document.getElementById("lowTrailQuality");
Expand Down Expand Up @@ -196,11 +227,10 @@ canvas3.addEventListener("mouseup", (elem, e) => {
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 name = randomColor();

addBody(name, mass, radius, clickedX, clickedY, distX, distY);
addBody(name, dropSizeMaps[selectedDropSize].mass, dropSizeMaps[selectedDropSize].radius, clickedX, clickedY, distX, distY);

step(false);
}
Expand All @@ -212,7 +242,7 @@ canvas3.addEventListener("mousemove", (elem, e) => {
if(mouseInCanvas) {
ctx3.clearRect(0, 0, WIDTH, HEIGHT);

const radius = parseFloat(document.getElementById("dropRadius").value);
const radius = dropSizeMaps[selectedDropSize].radius;
if(!(isNaN(radius) || !isFinite(radius) || radius < 0.01)) {
ctx3.beginPath();

Expand Down Expand Up @@ -358,7 +388,8 @@ resetButton.addEventListener("click", (elem, e) => {
const spawnButton = document.getElementById("preciseSpawn");

spawnButton.addEventListener("click", (elem, e) => {
const name = document.getElementById("preciseName").value;
// const name = document.getElementById("preciseName").value;
const name = randomColor();
const mass = parseFloat(document.getElementById("preciseMass").value);
const radius = parseFloat(document.getElementById("preciseRadius").value);
const positionX = parseFloat(document.getElementById("precisePositionX").value);
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.6.0",
"version": "0.7.0",
"description": "Creates the Solar Sim website.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9ab23bb

Please sign in to comment.