ITERATIVE DESIGN (II)_##3rd round##____ STAGE 3 (CONSTRUCTION)

INDEX

I have followed a couple of tutorials to make some of the most famous fractal shapes.

THE SIERPINSKI TRIANGLE

It is one of the most famous fractal figures, the name was coined by the Polish mathematician in 1915. Although he only described it, since the triangle had been used from long before. It can be found in Italian cathedrals from the XIII century. It is a triangle which is filled with three triangles, forming thus, a white inverted triangle in the middle. Each triangle in the main triangle can be filled with the same pattern. It can be done infinitely.  (Westein, 2015)

IMAGE

sierpinski#

CODE::


void setup(){
size(640,600);
}

void draw(){
background(255);
drawCircle(width/2, height/2, 300);
}

void drawCircle(float x, float y, float d){
stroke(0);
noFill();
ellipse(x, y, d, d);
if (d > 2){
drawCircle(x+d/2, y, d/2);
drawCircle(x-d/2, y, d/2);
drawCircle(x, y+d/2, d/2);
}
}

THE KOCH LINE

The Koch line was first described by Koch in 1905. Is is built from an equilateral triangle, or from a line. It is cut in thirds, and the one in the middle is removed. Then another equilateral triangle is drawn where the third has been removed. In the case of the line, two lines with the same size of the one which has been removed are added, forming a kind of triangle without base. The process is repeated which each new line of the drawing.  (Westein, 2015)

IMAGE::

koch_line#

CODE::

ArrayList <KochLine> lines;

void setup(){
size(800, 400);
background(255);
lines = new ArrayList<KochLine>();
PVector start = new PVector(0, height-50);
PVector end = new PVector(width, height-50);
lines.add(new KochLine(start, end));
}

void keyPressed(){
if (key == 'b'){
generate();
}
}

void draw(){
background(255);
for(KochLine l : lines){
l.display();
}
saveFrame("koch_line#.png");
}

void generate(){
ArrayList next = new ArrayList<KochLine>();
for (KochLine l : lines) {
PVector a = l.kochA();
PVector b = l.kochB();
PVector c = l.kochC();
PVector d = l.kochD();
PVector e = l.kochE();

next.add(new KochLine(a, b));
next.add(new KochLine(b, c));
next.add(new KochLine(c, d));
next.add(new KochLine(d, e));
}
lines = next;
}


class KochLine {
PVector start;
PVector end;

KochLine(PVector a, PVector b) {
start = a.get();
end = b.get();
}

void display() {
stroke(0);
line(start.x, start.y, end.x, end.y);
}

PVector kochA() {
return start.get();
}
PVector kochB() {
PVector v = PVector.sub(end, start);
v.div(3);
v.add(start);
return v;
}

PVector kochC() {
PVector a = start.get();

PVector v = PVector.sub(end, start);
v.div(3);
a.add(v);

v.rotate(-radians(60));
a.add(v);

return a;
}

PVector kochD() {
PVector v = PVector.sub(end, start);
v.mult(2/3.0);
v.add(start);
return v;
}

PVector kochE() {
return end.get();
}
}

REFERENCES::

Shiffman, D., 2013. 8.2 Fractal Recursion (The Nature of Code) [online] Vimeo. Available on:http://vimeo.com/64424402

Shiffman, D., 2013. 8.3 Recursion with ArrayList of Objects (The Nature of Code). [online] Vimeo. Available on: http://vimeo.com/64424401

Weisstein, Eric W. Sierpiński SieveMathWorld— [online] Available on: http://mathworld.wolfram.com/SierpinskiSieve.html

Weisstein, Eric W. Koch Snowflake. MathWorld— [online] Available on: http://mathworld.wolfram.com/KochSnowflake.html

INDEX

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s