Stash WIP wall detect.

master
Ben Burlingham 8 years ago
parent 368843e44c
commit 545c632300
  1. 12
      index.html
  2. 25
      js/animation3.js
  3. 25
      js/bundle.js

@ -3,13 +3,23 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/style.css">
<!-- <script src='/core/js/ui.js'></script> --> <script src='/core/js/ui.js'></script>
</head> </head>
<body> <body>
<h1>Dust</h1> <h1>Dust</h1>
<h2>Studying AI movement along arcs with RxJs</h2> <h2>Studying AI movement along arcs with RxJs</h2>
<hr> <hr>
<div class="controls">
Restart
Change direction
Change animation speed
Show movement circle
Show vision grid
Show touching points
Start / stop
</div>
<div class="particles"></div> <div class="particles"></div>
The ultimate goal is to simulate particles that move in swarms and calculate their The ultimate goal is to simulate particles that move in swarms and calculate their

@ -55,15 +55,18 @@ function move(store) {
const avgX = xs / intersections.length; const avgX = xs / intersections.length;
const avgY = ys / intersections.length; const avgY = ys / intersections.length;
const v = (t90 + Math.atan((particleY - avgY) / (particleX - avgX))) % t90; const v = Math.atan((particleY - avgY) / (particleX - avgX));
// console.warn(Math.round(v * 180 / Math.PI))
const modifier = Math.max(Math.round(v * 180 / Math.PI), 20); const modifier = Math.max(Math.round(v * 180 / Math.PI), 20);
arc = modifyArc(arc, modifier); arc = modifyArc(arc, 20);
// } else if (Math.random() < 0.005) {
// console.warn('changing direction')
// clockwise = !clockwise;
// arc = changeDirection(arc);
} else { } else {
if (Math.random() < 0.005) { arc = modifyArc(arc, 300);
console.warn('changing direction')
}
arc = modifyArc(arc, Math.random() * 100 + 100);
} }
particleX = arc.x + arc.r * Math.cos(arc.t); particleX = arc.x + arc.r * Math.cos(arc.t);
@ -71,6 +74,7 @@ function move(store) {
store.set({ store.set({
arc, arc,
clockwise,
particleX, particleX,
particleY, particleY,
}); });
@ -92,10 +96,11 @@ function modifyArc(arc, newRadius) {
} }
function changeDirection(arc) { function changeDirection(arc) {
// clockwise = !clockwise; arc.t = (arc.t + Math.PI) % t360;
// theta = (theta + Math.PI) % t360; arc.x -= (2 * arc.r) * Math.cos(arc.t);
// circleX -= (radius + radius0) * Math.cos(theta); arc.y += (2 * arc.r) * Math.sin(arc.t);
// circleY += (radius + radius0) * Math.sin(theta);
return arc;
} }
function detectWall(store) { function detectWall(store) {

@ -6426,15 +6426,18 @@ function move(store) {
var avgX = xs / intersections.length; var avgX = xs / intersections.length;
var avgY = ys / intersections.length; var avgY = ys / intersections.length;
var v = (t90 + Math.atan((particleY - avgY) / (particleX - avgX))) % t90; var v = Math.atan((particleY - avgY) / (particleX - avgX));
// console.warn(Math.round(v * 180 / Math.PI))
var modifier = Math.max(Math.round(v * 180 / Math.PI), 20); var modifier = Math.max(Math.round(v * 180 / Math.PI), 20);
arc = modifyArc(arc, modifier); arc = modifyArc(arc, 20);
// } else if (Math.random() < 0.005) {
// console.warn('changing direction')
// clockwise = !clockwise;
// arc = changeDirection(arc);
} else { } else {
if (Math.random() < 0.005) { arc = modifyArc(arc, 300);
console.warn('changing direction');
}
arc = modifyArc(arc, Math.random() * 100 + 100);
} }
particleX = arc.x + arc.r * Math.cos(arc.t); particleX = arc.x + arc.r * Math.cos(arc.t);
@ -6442,6 +6445,7 @@ function move(store) {
store.set({ store.set({
arc: arc, arc: arc,
clockwise: clockwise,
particleX: particleX, particleX: particleX,
particleY: particleY particleY: particleY
}); });
@ -6463,10 +6467,11 @@ function modifyArc(arc, newRadius) {
} }
function changeDirection(arc) { function changeDirection(arc) {
// clockwise = !clockwise; arc.t = (arc.t + Math.PI) % t360;
// theta = (theta + Math.PI) % t360; arc.x -= 2 * arc.r * Math.cos(arc.t);
// circleX -= (radius + radius0) * Math.cos(theta); arc.y += 2 * arc.r * Math.sin(arc.t);
// circleY += (radius + radius0) * Math.sin(theta);
return arc;
} }
function detectWall(store) { function detectWall(store) {

Loading…
Cancel
Save