# The Dragon Curve

Give the animation of the curve time to cycle!

This is an interesting structure/curve, where each iteration takes you into more, spacefilling detail. Colouring adds to the effect.

Interestingly it can be drawn by totally different methods.

## Method 1- using turtle graphics

```    nomainwin
mainwin 50 20

WindowHeight =620
WindowWidth  =690

open "Dragon Curve by command string" for graphics_nsb as #a

#a, "trapclose [quit]"

#a "down"

Turn\$ ="R"
Pace  =300
s     = 16
j     =  0
n     =  1

[again]
print Turn\$

#a "cls ; goto 230 420 ; north ; down ; fill black ; turn -"; 45 *j

for i =1 to len( Turn\$)
v =255 *i /len( Turn\$)
#a "color "; v; " 120 "; 255 -v
#a "go "; Pace
if mid\$(  Turn\$, i, 1) ="R" then #a "turn 90" else #a "turn -90"
next i

#a "color 255 120 0"
#a "go "; Pace
#a "flush"

FlippedTurn\$ =""
for i =len( Turn\$) to 1 step -1
if mid\$( Turn\$, i, 1) ="R" then FlippedTurn\$ =FlippedTurn\$ +"L" else FlippedTurn\$ =FlippedTurn\$ +"R"
next i

Turn\$ =Turn\$ +"R" +FlippedTurn\$

Pace  =max( Pace /1.41, 1)
j     =j +1

scan

timer 1000, [j]
wait
[j]
timer 0

#a "flush"
#a "getbmp drawing 1 1 620 590"
bmpsave "drawing", "dragon"; str\$( n); ".bmp"
n =n +1

if len( Turn\$) <40000 then goto [again]

wait

[quit]
close #a
end
```

## Using an IFS ( iterative system)

```    nomainwin

global pi: pi =4 *atn( 1)
WindowHeight =850
WindowWidth  =1320

open "Dragon Curve" for graphics_nsb as #a
print #a, "trapclose quit"
#a "down ; fill darkblue ; color 0 0 200"

K =1 /2^0.5
x1=0.7
y1 =0.3
for k =1 to 1e5
if rnd( 1) <=0.5 then
x2 =K *( c45  *x1 -s45 *y1)
y2 =K *( s45  *x1 +c45 *y1)
else
x2 =K *( c135 *x1 -s135 *y1) +1
y2 =K *( s135 *x1 +c135 *y1)
end if

print #a, "set "; str\$( int( 450 +700 *x2)); " "; str\$( int( 500 -650 *y2))
x1 =x2
y1 =y2
R =int(  256 *rnd( 1))
if k mod 100 =0 then print #a, "color "; str\$( R); " 0 "; str\$( 255 -R)
next k
wait

sub quit h\$
close #a
end
end sub