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>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<!-- <script src='/core/js/ui.js'></script> -->
<script src='/core/js/ui.js'></script>
</head>
<body>
<h1>Dust</h1>
<h2>Studying AI movement along arcs with RxJs</h2>
<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>
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 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);
arc = modifyArc(arc, modifier);
arc = modifyArc(arc, 20);
// } else if (Math.random() < 0.005) {
// console.warn('changing direction')
// clockwise = !clockwise;
// arc = changeDirection(arc);
} else {
if (Math.random() < 0.005) {
console.warn('changing direction')
}
arc = modifyArc(arc, Math.random() * 100 + 100);
arc = modifyArc(arc, 300);
}
particleX = arc.x + arc.r * Math.cos(arc.t);
@ -71,6 +74,7 @@ function move(store) {
store.set({
arc,
clockwise,
particleX,
particleY,
});
@ -92,10 +96,11 @@ function modifyArc(arc, newRadius) {
}
function changeDirection(arc) {
// clockwise = !clockwise;
// theta = (theta + Math.PI) % t360;
// circleX -= (radius + radius0) * Math.cos(theta);
// circleY += (radius + radius0) * Math.sin(theta);
arc.t = (arc.t + Math.PI) % t360;
arc.x -= (2 * arc.r) * Math.cos(arc.t);
arc.y += (2 * arc.r) * Math.sin(arc.t);
return arc;
}
function detectWall(store) {

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

Loading…
Cancel
Save