Sierpinski pentagon: Difference between revisions
Content added Content deleted
Line 1,065: | Line 1,065: | ||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
<lang java> |
<lang java> |
||
float s_angle, scale, margin = 25, total = 4; |
|||
Needs editing</lang> |
|||
float p_size = 700; |
|||
float radius = p_size/2-2*margin; |
|||
float side = radius * sin(PI/5)*2; |
|||
void setup() { |
|||
float temp = width/2; |
|||
size(590, 590); |
|||
background(0, 0, 200); |
|||
stroke(255); |
|||
s_angle = 72*PI/180; |
|||
scale = 1/(2+cos(s_angle)*2); |
|||
for (int i = 0; i < total; i++) { |
|||
background(0, 0, 200); |
|||
drawPentagon(width/2, (height-p_size)/2 + 3*margin, side, total); |
|||
} |
|||
} |
|||
void drawPentagon(float x, float y, float side, float depth) { |
|||
float angle = 3*s_angle; |
|||
if (depth == 0) { |
|||
for (int i = 0; i < 5; i++) { |
|||
float px = x; |
|||
float py = y; |
|||
x = x+cos(angle)*side; |
|||
y = y-sin(angle)*side; |
|||
line(x, y, px, py); |
|||
angle += s_angle; |
|||
} |
|||
} else { |
|||
side *= scale; |
|||
float distance = side+side*cos(s_angle)*2; |
|||
for (int j = 0; j < 5; j++) { |
|||
x = x+cos(angle)*distance; |
|||
y = y-sin(angle)*distance; |
|||
drawPentagon(x, y, side, depth-1); |
|||
angle += s_angle; |
|||
} |
|||
} |
|||
}</lang>'''The sketch can be run online''' :<BR> [https://www.openprocessing.org/sketch/955331 here.] |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |