Madrid

5 days in the fantastic city of Madrid, credits to my girlfriend for tolerating me standing around taking all these photos or long metro journeys purely to take these pictures.

Advertisements

Stalactite Generator

DSC02319

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)
        self.grid()
        self.create_widgets()

    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])
        plt.axis('off')
        plt.gca().invert_yaxis()
        plt.show()

root = Tk()
root.title("STALACTITE GENERATOR")
root.geometry("332x105")
app = Application(root)

root.mainloop()