:::{video} ../img/balls-and-their-admirers.webm
:figwidth: 400px
:align: right
:caption: Most balls follow each other and become one. 🟣🟡 go their own way. <!--by having selected each other and not any of others -->
:::

# Balls and their admirers

Let’s build a graphical simulation with lots of moving balls where they randomly follow each other, because they like or admire each other.

Because the balls follow each other, at some point they should end up at the same position.

:::{note}
For this problem you need [`raylib`](raylib).
:::

<br>
<br>
<br>

## Warmup

:::{activity} How do we simulate moving shapes?
:label: how-do-we-simulate-moving-shapes
The motion is generated by drawing many *frame*s per second. In our code we describe the position of each shape. So if a shape moves horizontally with a velocity of `x`, then its position in the next frame becomes `posx += x`. Moreover each shape can have further properties like color and rotation etc.

1. Come up with at least two different data structures to implement the state of 100 shapes.
1. What are the trade-offs of these data structures?

```{dropdown} Hint
Could arrays or scalar (single value) variables help?
```
:::
<!--
trade-offs
-->

## Requirements

1. A ball has a two-dimensional position (`posx` and `posy`), a velocity (`velx` and `vely`), a radius (`radius`), a color (`Color color`, where `Color` is defined by `raylib`) and a pointer to another leading ball (`follows`).

   Select meaningful types for these properties.
1. Each ball starts at a random position, with a random velocity, random color and a random ball to follow. A ball should not follow itself.
1. Use the template and only fill the missing parts.
1. Include a flowchart.
1. Do not include `raylib` library in your repository.
1. Record a 5-10s video of your simulation.

Optional:
1. Create an `union` `Shape` which can represent both circles and rectangles (`DrawRectangle()`). Each function must be modified to cater for this, so above requirement does not apply. Each circle should follow a rectangle

## Template

:::{literalinclude} ../code-prj/balls-and-their-admirers/masked/main.c
:language: c
:::