Today I stumbled upon a really cool wikipedia article which deals with a remarkable subject: quadtrees. As it says,
a quadtree is a tree data structure in which each internal node has four children.
Let me show you an example for you to visualize this:
Each node has four children
The implementation is fairly simple, and I wanted to go a bit further. That's when I found koalastothemax. It is a quadtree implementation applied to an image : basically, for each child, you have to compute its colour, which is the average of all the image's pixels colours inside it.
Here's the result:
Today I programmed a little contamination simulator. The idea came from a programming exercise a friend was trying to solve.
We have a set of particles (500 at the beginning), which have a state (healthy, infected or dead). Additionally, each particle has a lifetime, and can be "stressed" (I'll explain this shortly).
Each 0.2 seconds, a new generation is computed following these rules:
- infected particles lose some life over time and eventually die (after 14 generations);
- if there's healthy particles next to infected ones, they have a small chance of being contaminated AND they become "stressed";
- if a particle is "stressed", it teleports itself to another position in the screen (simulates plane trips, public transports, cars...);
- if a particle isn't "stressed", we apply a brownian movement to the particle.
You can pause the simulation by pressing the space key.
It's kinda like The Walking Dead with particles.