Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clumped schools of fish #2

Open
joesondow opened this issue Feb 17, 2017 · 0 comments
Open

Clumped schools of fish #2

joesondow opened this issue Feb 17, 2017 · 0 comments

Comments

@joesondow
Copy link
Owner

joesondow commented Feb 17, 2017

Sometimes, fish should prefer to swim near other fish.

Make a git branch for the school algorithm, in case it stinks.

Include original algorithm as an option for how to generate some tweets. There will be multiple algorithms, with one of the algorithms chosen randomly for each tweet.

Two variables to experiment with artistically:

  • Ratio of cell height to cell width.
  • Power to which you raise the inverse distance.

Ratio of cell height to cell width.

When calculating distances with Pythagorean Theorem, treat cells as if they're taller than they are wide. Experiment with ratios like 1.5:1, 2:1, 3:1, 4:1. That should make the proximity placement algorithm more likely to make fish clump into short wide ovals instead of circles. Real schools of fish are short wide ovals.

Power to which you raise the inverse distance.

The inverse of the distance between candidate cell and occupied cell is the base score for the candidate cell. Raise that score to a power of 2 or 3 or 4, or maybe even 2.75, to change how drastically different the probabilities are for close vs far cells. The variable is the exponent to which you raise the inverse of the distance.
d = distance
n = exponent
s = score
s = 1/(d^n)

Cells with higher scores are more likely to receive the next fish placement.

How to make actual schools of fish algorithmically. Fish prefer to be close to other fish. That's why they form schools. Imitate that behavior, but with enough randomness to be unpredictable and interesting.

  • Start with an XY coordinate system for sprite placement (visually tweak with occasional random small spaces at the end of the process).
  • Randomly choose a number of fish to be in the school, all of the same type.
  • Randomly place the first fish.
  • Iterate through the remaining fish, placing each one.
  • To place the next fish in the school:
    • Iterate through all empty cells. These are the candidate cells for the next fish placement. For each candidate cell:
    • Iterate through all fish already placed in the school. For each fish, calculate the distance between the fish and the candidate cell. Raise the distance to the variable power (see above) and invert it (1/x) and add that result to the candidate cell's score. The lesser the distance, the greater the proximity score.
    • When the proximity scores for all candidate cells are calculated, choose a random candidate cell in a way that gives weight for each cell equal to that cell's score.
    • Place a fish in the weighted-randomly-selected cell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant