aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJaro Camphuijsen <jjecamphuijsen@gmail.com>2015-10-16 10:16:30 +0200
committerJaro Camphuijsen <jjecamphuijsen@gmail.com>2015-10-16 10:16:30 +0200
commitfd42c5438ed015ab159c75809a75049706667594 (patch)
tree7d42a6e97dc98adc0db3de90209582dfa8829059
parent640ebd3d0a6e446d39138e375787e7e84101ab9a (diff)
more systems
-rw-r--r--index.html4
-rw-r--r--style.css4
-rw-r--r--sunsistemo.es6.js22
-rw-r--r--systems.es6.js41
4 files changed, 46 insertions, 25 deletions
diff --git a/index.html b/index.html
index f51b3d3..b17ed57 100644
--- a/index.html
+++ b/index.html
@@ -5,9 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sunsistemo - N-body simulator</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
- <script src="http://d3js.org/d3.v3.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r72/three.min.js"></script>
- <script src="https://cdn.rawgit.com/mrdoob/three.js/89aff65e75546eddc96db06e25b5774875fc9b27/examples/js/controls/OrbitControls.js"></script>
+ <script src="https://rawgit.com/mrdoob/three.js/89aff65e75546eddc96db06e25b5774875fc9b27/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stats.js/r14/Stats.min.js"></script>
</head>
<body>
diff --git a/style.css b/style.css
index c2a631f..854d77b 100644
--- a/style.css
+++ b/style.css
@@ -37,4 +37,8 @@ html, body {
text{
font-family: "Trebuchet MS", Helvetica, sans-serif ;
+}
+#stats{
+ right: 0;
+ z-index: 10;
} \ No newline at end of file
diff --git a/sunsistemo.es6.js b/sunsistemo.es6.js
index 3af63ca..de2a35a 100644
--- a/sunsistemo.es6.js
+++ b/sunsistemo.es6.js
@@ -7,7 +7,7 @@ import * as calc from "./calc.es6.js";
let bodyTexture = true;
let numBodies = 1;
-let sphereP = 32;
+let sphereP = 16;
let sunOn;
var steps;
@@ -27,22 +27,23 @@ let menuList = [
{"label":"Two Bodies", "function": systems.gen2Bodies, "args": [true]},
{"label":"Three Bodies", "function": systems.gen3Bodies, "args": [true]},
{"label":"Random Bodies", "function": systems.genBodies, "args": [200, true, false]},
- {"label":"Angular Momentum", "function": systems.genBodiesRot, "args": [200, true, true]},
+ {"label":"Angular Momentum", "function": systems.genBodiesRot, "args": [200, true, true, false]},
+ {"label":"Angular with Bounce", "function": systems.genBodiesRot, "args": [200, true, true, true]},
{"label":"Solar System", "function": systems.genSolarSystem, "args": [true] }
];
-var steps;
gui(menuList);
simulate(menuList[0].function, [0, true, false]);
function gui(buttonList) {
let buttonHeight = 50
+ let buttonWidth = 200
let body = d3.select("body")
let menuDiv = body.selectAll("#gui")
menuDiv.style()
let menuSvg = menuDiv.append("svg")
- .attr("width", 200 + "px")
+ .attr("width", buttonWidth + 50 + "px")
.attr("height", buttonHeight * menuList.length + 20 + "px")
.attr("class", "menuSvg");
@@ -60,7 +61,7 @@ function gui(buttonList) {
buttons.append("rect")
.style("fill", "#aaa")
.style("opacity",".5")
- .attr("width", (150))
+ .attr("width", (buttonWidth))
.attr("height", buttonHeight - 3)
.attr("rx", 5)
.attr("ry", 5);
@@ -95,6 +96,8 @@ function gui(buttonList) {
function clearSimulation() {
let simDiv = document.getElementById("sim");
while (simDiv.firstChild) simDiv.removeChild(simDiv.firstChild);
+ let statDiv = d3.select("#stat").remove();
+
}
function simulate(sysFunc, args){
system = sysFunc(...args);
@@ -132,7 +135,7 @@ function init() {
// spheres
let spheres = [];
for (let b of bodies) {
- let geometry = new THREE.SphereGeometry(b.rad, sphereP, sphereP);
+ let geometry = new THREE.SphereGeometry(b.rad, system.sphereP, sphereP);
let material = new THREE.MeshPhongMaterial();
material.map = b.getTexture();
material.bumpMap = b.getBumpMap();
@@ -162,6 +165,11 @@ function init() {
sprite.scale.set(glowRadius, glowRadius, 1.0);
sun.add(sprite);
}
+ else {
+ // sunlight
+ let light = new THREE.HemisphereLight(0xfcd440, 2);
+
+ }
// overall light
let ambient = new THREE.AmbientLight(0x404040);
@@ -174,7 +182,7 @@ function init() {
// stats
stats = new Stats();
stats.domElement.style.position = 'absolute';
- stats.domElement.style.left = '0px';
+ stats.domElement.style.right = '0px';
stats.domElement.style.top = '0px';
document.body.appendChild(stats.domElement);
diff --git a/systems.es6.js b/systems.es6.js
index b5b5e36..df34d9e 100644
--- a/systems.es6.js
+++ b/systems.es6.js
@@ -164,12 +164,13 @@ export function genSolarSystem(sunOn) {
// stepsize: 10000. * (60 * 60 * 24),
stepsize: 10,
stepsPerFrame: 1,
- // scalePosition: vec => vec.multiplyScalar(1E-08),
- scalePosition: vec => vec.setLength(Math.pow(vec.length(), 1/6)),
+ scalePosition: vec => vec.multiplyScalar(1E-08),
+ // scalePosition: vec => vec.setLength(Math.pow(vec.length(), 1/6)),
// scalePosition: vec => vec.setLength(Math.log(vec.length)/Math.log(1.4)),
camera: {x: 0, y: 0, z: 1300},
collisions: false,
- sunOn: sunOn
+ sunOn: sunOn,
+ sphereP: 32
};
}
export function gen2Bodies(sunOn) {
@@ -180,30 +181,34 @@ export function gen2Bodies(sunOn) {
return {
bodies: bodies,
- stepsize: 0.001,
+ stepsize: 0.0003,
camera: {x: 0, y: 0, z: 400},
collisions: false,
- sunOn: sunOn
+ sunOn: sunOn,
+ sphereP: 32
+
};
}
export function gen3Bodies(sunOn) {
let rot = () => Math.random() / 30;
- let s1 = new Body(1E19, new Vec3(0, 0, 0), new Vec3(0, 2, 0), 8, "mercury", new Vec3(0, 0, rot()));
+ let s1 = new Body(1E19, new Vec3(0, 0, 0), new Vec3(0, 0, 0), 8, "mercury", new Vec3(0, 0, rot()));
let s2 = new Body(1E18, new Vec3(200, 0, 0), new Vec3(0, 900, 0), 8, "venus", new Vec3(0, 0, rot()));
let s3 = new Body(1E18, new Vec3(-200, 0, 0), new Vec3(0, -900, 0), 8, "earth", new Vec3(0, 0, rot()));
let bodies = [s1, s2, s3];
return {
bodies: bodies,
- stepsize: 0.0005,
+ stepsize: 0.0003,
camera: {x: 0, y: 0, z: 400},
collisions: false,
- sunOn: sunOn
+ sunOn: sunOn,
+ sphereP: 32
+
};
}
-export function genBodies(n, bodyTexture, sunOn) {
+export function genBodies(n, bodyTexture, sunOn, collisions) {
if (!bodyTexture){allTextures = [];}
let bodies = [];
@@ -221,12 +226,14 @@ export function genBodies(n, bodyTexture, sunOn) {
bodies: bodies,
stepsize: 0.001,
camera: {x: 0, y: 0, z: 400},
- collisions: true,
- sunOn: sunOn
+ collisions: collisions,
+ sunOn: sunOn,
+ sphereP: 16
+
};
}
-export function genBodiesRot(n, bodyTexture, sunOn) {
+export function genBodiesRot(n, bodyTexture, sunOn, collisions) {
if (!bodyTexture){allTextures = [];}
let bodies = [];
@@ -239,16 +246,18 @@ export function genBodiesRot(n, bodyTexture, sunOn) {
let velVec = new Vec3(0,0,0);
let rot = () => Math.random() / 30;
let rotation = new Vec3(0, rot(), 0);
- velVec.crossVectors(posVec, angMomVec).multiplyScalar(Math.random());
+ velVec.crossVectors(posVec, angMomVec).multiplyScalar(Math.random() + .1);
bodies.push(new Body(1E14, posVec, velVec, 8, getRandomFromList(planets), rotation));
}
return {
bodies: bodies,
- stepsize: 0.001,
+ stepsize: 0.0005,
camera: {x: 0, y: 0, z: 400},
- collisions: true,
- sunOn: sunOn
+ collisions: collisions,
+ sunOn: sunOn,
+ sphereP: 16
+
};
}