Anonymous user
Sierpinski curve: Difference between revisions
m
→{{header|zkl}}: generalize
m (→{{header|zkl}}: added code) |
m (→{{header|zkl}}: generalize) |
||
Line 427:
Uses Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<lang zkl>
fcn sierpinskiCurve(order){
LSystem("F--XF--F--XF",Dictionary("X","XF+G+XF--F--XF+G+X"), order)
}
fcn LSystem(axiom,rules,order){ // Lindenmayer system
buf1,buf2 := Data(Void,
do(
buf1.pump(buf2.clear(),
t:=buf1; buf1=buf2; buf2=t; // swap buffers
}
buf1
}
fcn turtle(curve,angle,startAngle){
const D=10.0
dir:=startAngle;
img,color := PPM(800,800), 0x00ff00; // green on black
x,y := 15, img.h - x;
foreach c in (curve){
switch(c){
case("F","G"){ // draw forward
Line 451 ⟶ 452:
img.line(x,y, (x+=a.round()),(y+=b.round()), color)
}
case("+"){ dir=(dir +
case("-"){ dir=(dir -
}
}
|