Draw a Dragon Curve
Python 2/3, 169 167 150 111 98 78 Bytes
Note that the import is not included in the byte count, according to the challenge specs.
Thanks to @AlexHall for saving 39(!) bytes and @nedla2004 for another 13
from turtle import*
o=[90]
for z in o*9:o+=[90]+[-x for x in o[::-1]]
fd(5)
for i in o:rt(i);fd(5)
Starts by generating a list or right (90) and left (-90) turns, then goes through the list and moves the turtle.
Generated Output:
EDIT: If this is too boring too watch, add speed(0)
right before the first fd(5)
. It will run the same, except the turtle will move much faster.
Logo, 43 bytes
for[i 1 512][fd 9 lt :i/(bitand :i -:i)*90]
Try with interpreter at http://www.calormen.com/jslogo/#
This uses the same principle as my previous ASCII art answer and the formula on at wikipedia except I reversed the direction to match the image in the question:
First, express n in the form
k*(2^m)
where k is an odd number. The direction of the nth turn is determined by k mod 4 i.e. the remainder left when k is divided by 4. If k mod 4 is 1 then the nth turn isRL; if k mod 4 is 3 then the nth turn isLR
bitand :i -:i
finds the least significant bit of i
. We divide i
by this to shitft i
right the required amount, giving the required odd number k
. There is no need to distinguish between left and right turns; we just turn left by k*90
degrees and rely on the fact that rotation is a modulo 360 operaton to perform the modulo for us.
Output
use ht
to hide turtle if required.
Output (modified)
The following shows how the curve is a single strand.
bk 6 for[i 1 512][fd 6 rt :i/(bitand :i -:i)%4*45-90 fd 3 rt :i/(bitand :i -:i)%4*45-90]
x86, MSDOS, 16 bytes
I wrote this a while ago, to my knowledge the smallest routine for producing a dragon fractal. It uses no real iterations, rather plots every contained discrete pixel inside the fractal directly, showing the final image. It's included with many other tiny productions in this pack. The 16 byte version was the end of my effort to get the dragon fractal as small as possible, starting 2014 with this 32 byte production.
Hex
14 10 19 CA D1 FA 10 DE 01 D1 CD 10 B4 0C EB F0
Code
S:
adc al,0x10
sbb dx,cx
sar dx,0x01
adc dh,bl
add cx,dx
int 0x10
mov ah,0x0C
jmp short S