/***********************************************************
dragon.c -- ドラゴンカーブ
***********************************************************/

#N88BASIC

Dim xpen, ypen, zoom, cx, cy /* ペンの現在位置 */
zoom =50
cx = 320
cy = 200
Sub move(x, y) /* ペンアップで移動 */
xpen = x *zoom
ypen = y *zoom
End Sub

Sub move_rel(dx, dy) /* 同上 (相対座標) */
xpen += dx *zoom
ypen += dy *zoom
End Sub

Sub draw(x, y) /* ペンダウンで移動 */
Line(cx+xpen, cy-ypen)-(cx+x*zoom,cy- y*zoom)
xpen = x *zoom
ypen = y *zoom
End Sub

Sub draw_rel(dx, dy) /* 同上 (相対座標) */
Line(cx+xpen, cy-ypen)-(cx+(xpen + dx*zoom), cy-(ypen + dy*zoom))
xpen += dx *zoom
ypen += dy *zoom
End Sub


Sub dragon(i As Long, dx, dy, sign As Long)
If i = 0 Then
draw_rel(dx, dy)
Else
dragon(i-1, (dx-sign*dy)/2, (dy+sign*dx)/2, 1)
dragon(i-1, (dx+sign*dy)/2, (dy-sign*dx)/2, -1)
End If
End Sub

Sub main()
Dim order As Long

Input "位数 = ";order
move(1, 2)
dragon(order, 2, 0, 1)
End Sub

main()