2D Graphic Patterns
Site Map Feedback
Up Fern Mandelbrot Parity SeedHead

Algorithms to Generate Mysterious Patterns

This section demonstrates some curious patterns resulting from a few lines of code.
Most people find it fascinating that a simple line of code in a loop can result in complex patterns:

  void Ball(WORD x, WORD y, WORD Radius) {
    for(int u=-Radius; u<Radius; ++u) {
      for(int v=-Radius; v<Radius; ++v) {
        Bits[Width*(y+v)+(x+u)]+=0x010101*(Radius*Radius - u*u - v*v);
    } }
  }
  Ball(300,300,300);
The above code (used with CPixelBlock) gives the image below. This section is a collection of more these ideas, some of which are even useful!
Ball Fractal
Patterns like this are often discovered by chance by deliberately breaking code that was designed for other purposes. The original Ball function was this:
  void Ball(WORD x, WORD y, WORD Radius) {
    for(int u=-Radius; u<Radius; ++u) {
      for(int v=-Radius; v<Radius; ++v) {
        WORD R2=Radius*Radius;
        int w=(R2 - u*u - v*v)*255/R2;
        if(w>0) Bits[Width*(y+v)+(x+u)]+=0x010101*w;
    } }
  }
  Ball(100,100,25);
and it is more obvious why it was called 'Ball': Ball
Don't use the above code for anything sensible (it was just an example). Proper code to create such a ball would use the balls symetry in the same way that the Disc drawing routine does.