Sierpinski triangle/Graphical: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 1,632: | Line 1,632: | ||
Recursive Sierpinski triangle |
Recursive Sierpinski triangle |
||
<lang Processing> |
<lang Processing> |
||
PVector [] coord = {new PVector(0, 0), new PVector(150, 300), new PVector(300, 0)}; |
|||
int depth = 8; // recursion depth |
|||
color c = color(192); |
|||
PVector startPoint; |
|||
// Sierpinski triangle vertices |
|||
PVector [] coord = { |
|||
⚫ | |||
new PVector(150, 300), |
|||
new PVector(300, 0) |
|||
}; |
|||
void setup() |
void setup() |
||
Line 1,647: | Line 1,638: | ||
size(400,400); |
size(400,400); |
||
background(32); |
background(32); |
||
⚫ | |||
// random start point |
|||
startPoint = new PVector(150, 150); |
|||
sierpinski(startPoint, depth); |
|||
noLoop(); |
noLoop(); |
||
} |
} |
||
⚫ | |||
void draw(){} |
|||
⚫ | |||
{ |
{ |
||
if ( |
if (cDepth == 0) { |
||
set(50+int( |
set(50+int(cPoint.x), (height-50)-int(cPoint.y), color(192)); |
||
return; |
return; |
||
} |
} |
||
for (int v=0; v<3; v++) { |
|||
PVector temp = currentPoint.get(); |
|||
sierpinski(new PVector((cPoint.x+coord[v].x)/2, (cPoint.y+coord[v].y)/2), cDepth-1); |
|||
currentPoint.set((currentPoint.x+sVertice.x)/2, (currentPoint.y+sVertice.y)/2); |
|||
sierpinski(currentPoint, currentDepth-1); |
|||
currentPoint = temp.get(); |
|||
} |
} |
||
} |
} |