Stalactite Generator


Carrying on from the last post I have coded another generator in Python, using this idea to simulate the outcome of a natural process by generating stalactites in 2D. The original idea for creating a design process rather than designing an object itself came from seeing them in caves on Grand Cayman, as they are created by a controlled process over hundreds of thousands of years, so I thought it made sense to try to recreate this process myself.

Here are some of the outcome images from the program:

Here’s my code written for Python 2.7, using the idea that a stalactite is essentially an inverted histogram.

import numpy as np
import matplotlib.pyplot as plt
from Tkinter import *

class Application(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)

    def create_widgets(self):
        self.button = Button(self, text = "GENERATE", font = "Helvetica 39", command=self.generator)
        self.button.grid(row=0, column=0, sticky=W)

    def generator(self):
        mu, sigma = 100, 5
        x = mu + sigma * np.random.randn(4000)

        n, bins, patches = plt.hist(x, 50, normed=1, facecolor='black')

        plt.axis([0, 200, 0, 0.09])

root = Tk()
app = Application(root)


Flag Design Algorithm


Learning how to program using Python opened up new methods of designing to me. I became interested in writing a process to design something, rather than just designing it, because of the possibilities this method offered.

To explore this idea in a simplistic form, I wrote a program that randomly generated a flag using Python and Matplotlib for the graphical output. It creates a 3×2 canvas of a random colour, then two lines with a random colour, thickness and direction are displayed on top of it.


The issue with that is, a lot of the time you then get plots that look like this, which obviously isn’t a great design. So a method was needed to filter out the bad flag designs. I needed to find a mathematical method of distinguishing them from each other.


Some of the best flag designs use the golden ratio spiral, so I thought it would make sense to make use of this also. So for each flag the program creates, the intersection of the lines into the coordinates of the golden ratio is outputted. So you can then pick out the better designs such as the ones below which have 8-9 intersections.


I tried to base this program around the 5 basic rules of flag design, these are:

  1. Simplicity     –     The program only uses 3 features
  2. Meaningful symbolism      –     The program only allows for symbolism retrospectively, it’s impossible to randomly generate symbolism
  3. 2-3 colours     –     The program only allows for 3 colours to be used maximum
  4. No lettering or seals     –     Nope
  5. Distinctive     –     Definitely, as these designs are generated from a random process

My original idea was that once these flags were ordered in terms of their golden ratio intersections, they would mutate and be optimised leading to designs with more intersections using a survival of the fittest style evolutionary algorithm. But this did not totally make sense for this program as the solution is trivial (but I may try this with later projects).

The program also does not take into account the thickness and colour of lines in designs when they are assessed, and these are factors in what makes a good flag design. But defining these things could take away from this being a truly random process.

The highest number of intersections in a design that this program has outputted is 10, which is this design, which I think could pass for a genuine flag design.