Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ant Foraging

A browser-based 2D ant-foraging simulation built with HTML5 Canvas and plain JavaScript. Ants leave the nest, search for food, pick it up, and carry it home while depositing pheromones on the return leg. Other ants can then bias their movement using those cues, so short-lived trails and collective path use emerge from simple local rules—without any central planner.

Preview

Screenshot 1 — nest, food patches, and pheromone trails:

Ant colony foraging simulation — overhead view with nest, food, and pheromone trails

Screenshot 2 — another run with dense trails and the stats bar:

Ant colony simulation — alternate run with dense trails and statistics bar

What this project is

  • Toy model of stigmergy: ants coordinate indirectly by modifying a shared scalar field (pheromone density on a grid) and reading it back while they move.
  • Interactive sandbox: reset the scene, place food by clicking the canvas, and tune sliders such as colony size, pheromone strength, decay (evaporation), and exploration-vs-trail bias to see how behavior changes.

What we explore

  • Emergent trails: thin, bright “roads” arise when many ants reinforce the same segments on the way back to the nest; they fade when deposition cannot keep up with decay.
  • Exploration vs exploitation: strong trails speed up finding known food but can discourage detours; weaker signals or faster decay keep the colony more exploratory.
  • Path reinforcement (“strengthen homing”): repeating successful return paths increases local pheromone, which visibly steers outbound and searching movement—illustrating how positive feedback loops shape group-level foraging geometry.
  • Parameter sensitivity: small changes in deposition rate or evaporation can switch the field between “clean almost empty” and “dense maze-like ribbons,” highlighting the coupling between memory (pheromone) and the physical motion rules.

Detailed rules aligned with the code (world size, finite state machine, grid sampling, deposition order, etc.) are documented in Chinese in 规律.md.

How to run

Open ant-foraging.html in a modern desktop or mobile browser (no build step).

If you cloned this repo locally, double-click the file or serve the folder with any static file server—the simulation is entirely client-side.

Live demo (GitHub Pages)

GitHub does not execute the Canvas app when you browse the Markdown or raw-file view—you need static hosting. After enabling Pages once, the simulation runs online at:

https://supuzz.github.io/Ant-Foraging/

(This repo ships index.html, which jumps straight to ant-foraging.html.)

Enable GitHub Pages (one-time)

  1. Open Settings → Pages on GitHub for this repository.
  2. Under Build and deployment, set Source to Deploy from a branch.
  3. Choose branch main, folder / (root), then Save.
  4. Wait about one minute; the site URL appears at the top of the Pages settings.

(Releases/ZIP archives are convenient for pinning a snapshot but do not solve “preview on GitHub” by themselves—you still host the HTML or open it locally.)

Repository

Upstream: https://github.com/SUPUZZ/Ant-Foraging

About

Ant Foraging is a browser-based 2D agent simulation built with HTML5 Canvas and vanilla JavaScript. Virtual ants operate with a lightweight finite-state style behavior: leaving the nest, searching, collecting food, and returning home while depositing pheromones onto a discrete field that decays over time.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages