Posted: 11:51pm 03 Aug 2020 |
|
|
|
Turtle meets Dragon
This is perhaps my favorite fractal line drawing. Especially neat is the way they fit together. In this code, the red and green dragons are identical, just rotated 180 degrees. And they fit together perfectly.
It does look though that rounding errors are creeping into play here. The start point is fixed but the end point should also always end up the same. But if you watch closely between different orders, particularly the higher ones, the end point moves quite a lot. As a result, the green and red dragons must be the same order or they won't line up at all.
Orders higher than 19 don't work because the draw distance becomes less than 1 so nothing beyond a single dot gets drawn.
cls turtle reset text 100,500,"Dragon Curve - a Fractal","CT" do print @(0,520) "Order: (1-19)" input "0 to quit: "; dord loop until dord >= 0 and dord < 20
do if dord = 0 then end
dord = dord - 1 dist = MM.HRES/2/(sqr(2)^dord)
cls turtle reset text 80, 0,"Dragon Curve","CT",2 text 80,20,"Order:" + str$(dord+1), "CT",2 turtle pen up ' no line yet turtle move MM.HRES * .25, MM.VRES * .55 turtle pen down
turtle heading 90 - (dord MOD 8) * 45 turtle pen colour rgb(red) DrawDragon(dord,1)
turtle heading 270 - (dord MOD 8) * 45 turtle pen colour rgb(green) DrawDragon(dord,1)
do print @(0,520) "Order: (1-19)" input "0 to quit: "; dord loop until dord >= 0 and dord < 20
loop
sub DrawDragon(ord, sig) if ord = 0 then turtle forward dist else DrawDragon(ord-1, 1) turtle turn right 90 * sig DrawDragon(ord-1, -1) endif end sub
|