…is always light

Tag Archives: fractals

I came up last sleepless night with a fractal of my own. There are two versions of it. The first version has the following rules:

  • Build a circle with radius of r
  • Draw inside the previous circle a circle of radius of / 2
  • Draw circles below, above and sides of the previous circle, the radius of these smaller circles being / 4

Choose for a new circle the circle that’s radius is r / 2. Repeat the previous steps ad infinitum.

Unfortunately on WordPress.com I can’t add the JavaScript-code where you could change the amount of iterations, so let’s just settle for pictures.

fraktaali 1


This kind of fractal might be invented already, but I haven’t seen one ever before.

Version 2 of this fractal:

fraktaali 2

The previous has a bit more complicated rules.

I made two color version of the previous too:

oma fraktaali jatko värill1

The second one:

oma fraktaali jatko värill2

Last night I was a bit playing with these fractal images in JavaScript, below is one more picture:

jatkokehitys fraktaali kikkailu

Perhaps this fractal of mine has at least some value of curiosity.

I try to find the time sometime in September to come back to this topic.

Back to the world of fractals…

One of the famous fractals is the Koch curve, described by Helge von Koch in the early 1900s.

The basic idea of this fractal is as follows:

  1. Take an equliteral triangle, build another triangle in the middle of each side of the shape, the new triangle having a base length of 1/3 of the length of the side.
  2. Repeat ad infinitum.

Turtle graphics are very handy in the implementation. The needed functions or methods are Forward: Draw a line in given amount of units forwards to the current drawing angle. The second is Turn: Turns the drawing angle in given amount of degrees.

With recursion we are now ready to go to build a snowflake based on the Koch curve.

Below is two videos of my implemantation:

..and the same with more iterations:


Based on book ”Sacred Geometry – the Designs of Creation”

As sacred geometry has started to fascinate me more and more I decided to share some more thoughts from the book mentioned above.

As a reminder sacred geometry is some kind of mystique, not mainstream mathematics.

The writer of the book tells, that he is fascinated by the study of consciousness and the root of awareness and existence itself through geometry.

Popular highlight from the e-book:
”Like water is to the fish at the bottom of an ocean, we are immersed in an ocean of love, bliss and consciousness but never really appreciative of it because of its constancy and ubiquitousness.”

The fractals are defined in the book so that they are patterns that repeat themselves infinitely on smaller and smaller scales without end. Something similar defines our consciousness and the true nature of our reality.

It says it the book, that we are each in our own way a tiny reflection of a vaster, more complete image of life, but nevertheless a complete ”oneness” unto itself that contain all the information of the universe in the form of fractals.

Wherever one goes, one walks into and interacts with “fractals of God” that expand and retract and disappear into the distance as we more away. This same effect is no different than a fractal hologram which our very consciousness is emanating in all directions.

Furthermore, the writer of the book writes, that in sense, the edge of the universe may only be a finite number of meters a way, but we never reach it because of infinity of fractals.

”Everything is contained within one’s self in the form of a fractal hologram.”

The writer describes a YOU-niverse, where you are always center of everything that exists and your consciousness radiates from the center (single) point of origin. You are the YOU-niverse and this universe which is you, is never really infinite in size, but information embedded within it (in the form of fractals) is unending, giving the illusion that it is also infinite in size.


Image courtesy of blackzheep at FreeDigitalPhotos.net

The chapter about the subject in the book ends with the following beautiful thought: ”May the beauty of your heart be reflected in the universe that surrounds you!”


Free e-book on geometry:

Sacred Geometry e-books

Many, many years ago I came up with an idea about a fractal that would be based on right triangles and squares. People that had less mathematical experience than I, didn’t take me seriously, when I told about my idea. They thought that this was just some kind of nonsense.

I didn’t visualize my idea and forgot the whole thing… Later, after many years when I started to read e-books about fractals, I found sophisticated ideas how to make nice colored Pythagorean fractal trees. I think I’ve been dealing with wrong people in the past… 🙂

This article discusses only about simplest possible Pythagorean fractal tree, most symmetrical version of it.

We start with a right triangle with two 45 degrees angles and one 90 degrees angle and visually speaking turn the triangle so that hypotenuse is at the bottom:

right triangle


Next we draw squares against the sides of the triangle so that the length of the side of the square is the length of the side of the triangle:

squares and triangle
Next we imagine new right triangles to the farthest side of the ”branch” squares and do the same process as earlier: We draw squares to all the sides of the triangles.

This process is continued infinitely and we have a fractal! …that looks like a tree.pytree

The length of the new hypotenuse c‘ = cos(45°) * c, where c is the length of the hypotenuse of previous iteration loop’s right triangle(s).

When generating the tree, I recommend using Java with JavaFX package or using JavaScript, because with those one can use the following methods:

  • beginPath
  • translate
  • rotate
  • save
  • restore

These methods make it quite easy to generate a fractal tree. When drawing the tree into screen, only the squares are drawn.

The e-book below discusses lots of fractal programming and has also an example codes in JavaScript generating these kinds of trees (also colored):

The Cantor’s set is somewhat fascinating fractal, when one gets to more familiar with it.

The basic idea is to handle real number interval [0,1]. This is divided to three parts of same width removing the middle part. The remaining parts are again divided to three parts of same width removing always the middle part. This is continued infinitely.

The Cantor’s set consists of the points that are left in this process.

In the language of the set theory the Cantor’s set can be expressed as follows:

Cantorin joukko

The union tells what doesn’t belong to the set.

I have used this formula to implement the Cantor’s set in my program. The idea is to examine the union interval and draw a pixel, when the point does belong to the set.

Below is a picture from the program’s output:

Cantor set


Here’s the Java program in full:

import java.awt.*;
import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.lang.Math;

public class Cantor {

    private JFrame frame;
    private CantorPanel panel;
    public Cantor() {
        frame = new JFrame("The Cantor's Set");
    private void initialize() {
        panel = new CantorPanel();
    public static void main(String args[]) {
        new Cantor();
class CantorPanel extends JPanel {
    public CantorPanel() {
        setPreferredSize(new Dimension(1024,100));
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;

        drawCantor(g, 7);
    public void drawCantor(Graphics g, int maxIter) {
        int y = 17;
        for (int m = 1; m < maxIter + 1; m++) {

            for (int x = 0; x < 1024; x++) {
                if (belongsToSet(m,x) == true) g.drawOval(x,y,1,1);
            y = y + 10;
    public boolean belongsToSet(int m, double x) {

        double line = 1024;
        double x1,x2;

        for(int mm = 1; mm < m ; mm++) {
            for (int k = 0; k < (int)((Math.pow(3,(mm-1))) - 1 + 1); k++) {

                x1 = (3.0*k + 1) / Math.pow(3.0,mm);
                x2 = (3.0*k + 2) / Math.pow(3.0,mm);
                if ((x > x1 * line) && (x < x2 * line)) return false;

        return true;

Because of the calculation precision with “big” number of iterations drawing accuracy isn’t very good.

The program is free for personal and educational use.

On Georg Cantor

What is a fractal?

In short fractal is a shape that has certain special characteristics. Interesting in fractals is, that new characteristics can be found infinitely.


The mathematics related to fractals got birth in the 1600s by work of famous German mathematician Gottfried Willhelm Leibniz. The actual mathematics in fractals saw daylight in the 1800s , but proper research on fractals started after efficient enough computers, that wasn’t possible in the 1800s (at all).

When the researchers first generated one of the most famous fractals, the Mandelbrot set, they thought they had made a mistake, because the result was so surprising. This reflects the role of efficient computers in research on fractals. Fractals became popular in the 80’s.

Fractals in the Nature

Fractals may sound something that can be only found in mathematics, but in the nature there can be found shapes that are fractal-alike. Some examples of these are tree branches, clouds, lightnings, fern’s leafs and coast lines.

Fascinating in the fractals of the nature is, that there can be found infinities in the nature! At least paradoxes about how long something is. The famous example of this is the length of the coast line of Great Britain. Benoit Mandelbrot came into conclusion that the length of the coast line of Great Britain is in fact infinite. This is known as the coast line paradox.

Though one view to this paradox is, that the mathematical world and the empirical world (our every day world) are separate. In an old Finnish book (published in 1969), it says that, in the mathematical world is infinite amount of points, but our empirical world does not have infinite amount of points no matter what is the measured length.

Fascinating thing in fractals (in mathematical world) is, that length can be infinite, but area related to that length is still finite.

Where fractals can be used?

Fractals themselves are unbelievable psychedelic art at their best. But the fractals as art can represent whole landscapes. Because of the artistic nature of fractals, for example the movie industry in Hollywood has used fractals. Fractals can make the special effects more realistic. As an example of movie, where fractals have been used in the special effects, Star Wars episode III is a good example.

Fractals are also used in economics, social sciences and medical sciences. For example the AIDS virus has been modelled by fractal geometry.

It may sound surprising, but the brain has also fractal-alike characteristics. Some people even speculate that the mind of humans would be somehow infinite! In one book on chaos theory for example a psychologist suggested that human’s memory would be something where concept infinite could be assigned.

Fractals are used also in data compression.

Famous fractals

One of the most famous fractals is the Mandelbrot set and also the Julia set. The Mandelbrot set and Julia set are related to each other. The Sierpinski Gasket is also very famous fractal.

For some reason I’m fascinated by the Cantor’s set. The Cantor’s set is fractal that is constructed from the real number interval [0,1]. This interval is divided into three line segments that have the same length so that the middle segment in removed. The remaining segments are again divided to three segments of the same length and again the middle segments of the construction are removed. This is continued infinitely and the remaining points of segments belong to the Cantor set.

This was quite non-mathematical explanation of how the Cantor set is constructed, but I hope you got the idea. Georg Cantor was interested in, what happens, if this dividing and removing is continued infinitely.

Let the last fractal I mention be the L-Systems (Lindenmeyer system). L-Systems look like plants and have been used to simulate the growth and structures of plants. Aristid Lindenmeyer developed the L-systems in the year of 1968.

Amazon e-books on fractals

The Mandelbrot Set is one of the most famous fractals. This fractal carries the name of the French mathematician Benoit Mandelbrot (1924 – 2010). The first ones how implemented the Mandelbrot Set with computer where mathematicians Robert Brooks and Peter Matelski.

The mathematical definition of the Mandelbrot Set

The Mandelbrot Set is set M, where belong all the points c, to which zn is finite, when n approaches infinity, where

z0 = c

zn+1 = zn2 + c

The initial point is (0,0i). Here both z and c are complex numbers. The c is held constant and z is variable that’s value changes.

The Mandelbrot Set on the complex plane

The Mandelbrot Set is typically generated from rectangle on the complex plane from bottom left (-2.25 -1.5i) and upper right (0.75 + 1.5i). The zooming of the Mandelbrot Set is done by selecting different coordinates on this rectangle from somewhere on the border of the set. See the picture below:

The set M is the black area in the picture. The other colors represent the distance from the set. In a way when you’re looking other colors than black, you’re watching infinity.

The helpful proof

Fortunately there’s is mathematical proof, that says that is sufficient to test that is the absolute value of iterated point > 2. If the absolute value of iterated complex number is greater than 2, the iterated point is to divergence to infinity and does not belong to the set. Otherwise the point belongs to the set.

The idea of the generating the Mandelbrot Set

The recursive formula will be implemented by iterative way.

The Mandelbort set is generated to computer screen by taking each pixel point and by choosing that point as constant C (after converting this to correspond the complex plane point). When each iteration loop begins, z is first set to (0 + 0i). Next the formula z = z + c is iterated with checking if z is to divergence to infinity by calculating the absolute value of z. If the absolute value of z > 2, the point is to divergence to infinity and does not belong to the set. Otherwise the point belongs to set.

Imagine each pixel point as a point on the chosen complex plane rectangle.

Pixel’s width and height on the complex plane are calculated as follows:

dr = (maxR - minR) / SCREEN_WIDTH
di = (maxI - minI) / SCREEN_HEIGHT

Other thing to consider is the scale of the picture: The complex plane rectangle’s ratio must be scaled to same as screen area’s ratio.

This is calculated as follows:

The width of the rectangle wmaxR – minR
The height of the rectangle h = maxI – minI
Scaled width sW = h * (SCREEN_WIDTH / SCREEN_HEIGHT)
Difference of the scaled width and original width: diff = sW – w

Next we subtract half of the difference of the widths from the left side of the complex plane rectangle and add half of the difference of the widths to the right side of the complex plane rectangle:

minR = minR – diff / 2
maxR = maxR + diff / 2

Now the length of the complex plane rectangle is scaled to screen’s width. In practice SCREEN_WIDTH can refer in general to width of the screen’s pixel rectangle’s width.

Below is complete BlitzMax program that generates the Mandelbrot set and scales the complex plane rectangle to same ratio as the screen area’s ratio:

Const SCREEN_WIDTH:Int = 640
Const SCREEN_HEIGHT:Int = 480
Const MAX_ITER:Int = 32


 Global minR:Float = -2.25, maxR:Float = 0.75
 Global minI:Float = -1.5, maxI:Float = 1.5

 Global dr:Float, di:Float

 Local w:Float, h:Float, sW:Float, diff:Float
 Local shade:Int

 w = maxR - minR
 h = maxI - minI
 sW = h * (Float(SCREEN_WIDTH) / Float(SCREEN_HEIGHT))
 diff = sW - w

 minR = minR - diff / 2
 maxR = maxR + diff / 2

 dr = (maxR - minR) / SCREEN_WIDTH
 di = (maxI - minI) / SCREEN_HEIGHT

 For Local y:Int = 0 To SCREEN_HEIGHT - 1
  For Local x:Int = 0 To SCREEN_WIDTH - 1
   shade = mandelbrot(x,y)
   shade = 255 - Float(MAX_ITER - shade) / 32.0 * 255.0
   SetColor 0,0,shade
   Plot x,y


Function mandelbrot:Int(x,y)

 Local iterations:Int = 0

 Local cr:Float = minR + x * dr
 Local ci:Float = minI + y * di
 Local zr:Float = 0.0
 Local zi:Float = 0.0
 Local zr_temp:Float = 0.0
 Local zi_temp:Float = 0.0

 While (iterations < MAX_ITER)
  zr_temp = zr * zr - zi * zi + cr
  zi_temp = 2.0 * zr * zi + ci
  zr = zr_temp
  zi = zi_temp

  iterations = iterations + 1
  ' Below is same as sqrt(zr^2 + zi^2) > 2.0
  ' but faster
  If zr * zr + zi * zi > 4.0 Then Return iterations


 Return 0

End Function

With greater amount of iterations it may be the case, that a point that doesn’t diverge to infinity with lower amount of iterations, diverges to infinity with greater amount of iterations. Thus, with computers in fact every generated Mandelbrot set picture is some kind of approximation of the Mandelbrot set.

Shortly about the colors

If the point c belongs to the set, the pixel is usually colored black. The other colors are calculated from the iterations. Easiest way to calculate different shades from the iterations is the following:

shade = mandelbrot(x,y) ; The function returns the number of iterations
shade = 255 - (MAX_ITERATIONS - shade) / MAX_ITERATIONS * 255

This gives values 0…255 to variable shade.

Below is is picture from rectangle, that’s bottom left is (-0.22 – 0.70i) and upper right is (-0.21 – 0.69i) with different kind of coloring:


Here the maximum amount of iterations is 250. In this case the number of iterations has dramatic impact to the generated picture. How colorful can the infinity be!

Mandelbrot mountain

For curiosity below is a Mandelbrot mountain generated with Python program (also my own program):


The program uses the Mayavi extension, which makes it easy to do 3D visualization.

Amazon e-books on fractals

I recommend especially

If you’re interested in generating Mandelbrot or Julia set mountains, I recommend the e-book below: