Skip to content

Commit

Permalink
13kJS release
Browse files Browse the repository at this point in the history
  • Loading branch information
lopis committed Sep 15, 2021
1 parent 79201bb commit aeea729
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Binary file added pic_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pic_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
image-rendering: crisp-edges;
image-rendering: optimizespeed;
background: #73b08a;
background-image: url('grass.png');
}

canvas {
Expand Down
30 changes: 15 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ const checkCollisions = (ant, otherAnts) => {

const updateDirection = (ant, chance, canvasCache) => {
if (canvasCache) {
if (ant.angleDelta > 0) {
const delta = Math.min(angleDeltaStep, ant.angleDelta)
ant.angle += delta
ant.angleDelta -= delta
} else if (ant.angleDelta < 0) {
const delta = Math.max(-angleDeltaStep, ant.angleDelta)
ant.angle += delta
ant.angleDelta -= delta
}
// if (ant.angleDelta > 0) {
// const delta = Math.min(angleDeltaStep, ant.angleDelta)
// ant.angle += delta
// ant.angleDelta -= delta
// } else if (ant.angleDelta < 0) {
// const delta = Math.max(-angleDeltaStep, ant.angleDelta)
// ant.angle += delta
// ant.angleDelta -= delta
// }

const front = getPixel(
ant.x + ant.dx * lookoutDistance,
Expand All @@ -183,22 +183,22 @@ const updateDirection = (ant, chance, canvasCache) => {
const turnChance = Math.random()

if (rightBlueness > leftBlueness && rightBlueness > turnChance) {
// ant.angle = ant.angle - lookoutAngle / 3
ant.angleDelta = -lookoutAngle / 3
ant.angle = ant.angle - lookoutAngle / 3
// ant.angleDelta = -lookoutAngle / 3
ant.dx = ant.speed * Math.cos(degToRad(ant.angle))
ant.dy = ant.speed * Math.sin(degToRad(ant.angle))
} else if (leftBlueness > rightBlueness && leftBlueness > turnChance) {
// ant.angle = ant.angle + lookoutAngle / 3
ant.angleDelta = lookoutAngle / 3
ant.angle = ant.angle + lookoutAngle / 3
// ant.angleDelta = lookoutAngle / 3
ant.dx = ant.speed * Math.cos(degToRad(ant.angle))
ant.dy = ant.speed * Math.sin(degToRad(ant.angle))
}
}

// Random change of direction
if (Math.random() < chance) {
// ant.angle = ant.angle + (Math.random() * change * 2 - change)
ant.angleDelta = Math.random() * change * 2 - change
ant.angle = ant.angle + (Math.random() * change * 2 - change)
// ant.angleDelta = Math.random() * change * 2 - change
ant.dx = ant.speed * Math.cos(degToRad(ant.angle))
ant.dy = ant.speed * Math.sin(degToRad(ant.angle))
}
Expand Down

0 comments on commit aeea729

Please sign in to comment.