Jump to content

Sierpinski triangle/Graphical: Difference between revisions

→‎{{header|evaldraw}}: add sierpinski solution
(→‎{{header|evaldraw}}: add sierpinski solution)
Line 1,187:
END PROGRAM
</syntaxhighlight>
 
=={{header|Evaldraw}}==
 
This makes use of sleep(millis); and refresh(); in the middle of a function to do the slow animation of triangles.
 
<syntaxhighlight lang="c">
static calls=100;
() {
setcol(255,255,255);
if (numframes==0) {
cls(0);
calls = 0;
sierpinski(xres/2,yres*0.1,xres*.8,xres*.8);
}
moveto(0,0); printf("%g recursions", calls);
}
sierpinski(x,y,w,h) {
calls++;
triangle(x,y,w,h);
if(w < 10 || h < 10) return;
sleep(1); refresh();
halfH = h/2;
halfW = w/2;
sierpinski(x,y,halfW,halfH); // left
sierpinski(x+halfW/2,y+halfH,halfW,halfH);
sierpinski(x-halfW/2,y+halfH,halfW,halfH);
}
triangle(x,y,w,h) {
moveto(x,y);
lineto(x+w/2, y+h);
lineto(x-w/2, y+h);
lineto(x,y);
}</syntaxhighlight>
 
=={{header|Factor}}==
63

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.