> For the complete documentation index, see [llms.txt](https://www.isaacbowen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.isaacbowen.com/2024/11/26/with-regard-to-koipond.me.md).

# With regard to koipond.me

## Me

hey amigo! can you describe the behavior of the koi, based on [this code](https://github.com/lightward/koi-pond/blob/a525c7f5ed63e149a6259f8b74c96f2f72bebd3f/src/main.ts)? what are the rules for their movement? how would you represent it in words, being technically precise along the way?

## Claude

Let me analyze the movement behavior of these digital "koi" based on the code. While it's not explicitly called a koi simulation, I can see why you'd make that connection given the emergent behavior!

The simulation creates a beautiful swarm-like pattern where bodies move with fluid, fish-like motion. Here's a precise breakdown of their behavior rules:

**Basic Setup**

1. Bodies are arranged initially in a hexagonal pattern
2. One body becomes "active" (non-static) every 100ms/timeScale
3. Each body has a 180-degree field of view and can sense others within 500 units
4. There's a speed limit of 5 units per tick
5. Bodies deform based on speed - faster movement causes elongation (like real fish!)

**Movement Forces**

Each body's movement is governed by four main forces that combine to create the final motion:

1. Circular Current (getCurrentForce):
   * Bodies experience a force perpendicular to their direction to the center
   * Force increases with distance from center
   * Creates a base circular movement pattern
   * Scaled at 0.5x strength
2. Edge Avoidance (getEdgeRepulsionForce):
   * Bodies are repelled from canvas edges
   * Repulsion increases quadratically as they get closer to edges
   * Scaled at 5x strength, making it a strong influence
   * Prevents bodies from leaving the visible area
3. Social Behavior (getSocialForce):
   * Bodies look for gaps between their visible neighbors
   * Seeks gaps between 5° and 90°
   * Prefers gaps that are "clear" - no other bodies in the potential path
   * Scaled at 0.2x strength
   * Creates schooling-like behavior
4. Personal Space (getAntiSocialForce):
   * Repels from other nearby bodies within 50 units
   * Repulsion force increases quadratically with proximity
   * Scales with speed (faster moving bodies maintain larger personal space)
   * Scaled at 0.05x strength
   * Prevents collisions and maintains spacing

The visual representation includes:

* Bodies stretch along their direction of movement
* Faster movement causes more elongation (up to 80% longer)
* Width decreases with speed (up to 50% thinner)
* Creates a fluid, organic appearance

All these forces combine to create emergence - bodies naturally form flowing, organic patterns without explicit coordination. They maintain personal space while following the group, create natural-looking schooling behaviors, and respond smoothly to their environment.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.isaacbowen.com/2024/11/26/with-regard-to-koipond.me.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
