Answered # dragon curve algorithm

Gribouillis 1,313 vegaseat 1,720 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

Looking at the pictures here, the algorithm seems pretty straightforward, starting with a vector of 2 points A and B

```
def draw_dragon(A, B, depth):
if depth == 0:
draw segment A, B
else:
compute point C
draw_dragon(A, C, depth - 1)
draw_dragon(B, C, depth - 1)
```

point C is the 3rd vertex of the triangle in the generation 2 picture. The ordering of the vertices in the calls to draw_dragon takes care of the orientation.

*Edited 6 Years Ago by Gribouillis*: n/a

0

You can use the module turtle to show the formation of a dragon curve fractal ...

```
# yet another Dragon Curve program using module turtle
# this module ships and works with Python2 and Python3
import turtle
def initialize (color='blue'):
'''prepare to draw'''
turtle.clear()
# values for speed are 'fastest' (no delay), 'fast', (delay 5ms),
# default = 'normal' (delay 10ms), 'slow' (delay 15ms),
# 'slowest' (delay 20ms)
turtle.speed('slow')
# lift turtle pen to move without drawing
turtle.up()
# start at 120 units to the left of center
turtle.goto(-120, 0)
# initial heading 0 --> east
turtle.setheading(0)
# initial color of pen
turtle.color(color)
# turtle pen ready to draw
turtle.down()
def dragon_right(max_len, min_len):
'''draw lines favoring right'''
# optionally draw this part in red
turtle.color ('red')
if max_len <= min_len:
turtle.forward(max_len)
else :
max_len /= 2.0
#print(max_len) # test
dragon_right(max_len, min_len)
turtle.right(90)
dragon_left(max_len, min_len)
def dragon_left(max_len, min_len):
'''draw lines favoring left'''
# optionally draw this part in blue
turtle.color('blue')
if max_len <= min_len:
turtle.forward(max_len)
else :
max_len /= 2.0
#print(max_len) # test
dragon_right(max_len, min_len)
turtle.left(90)
dragon_left(max_len, min_len)
def dragon_curve(max_len, min_len, color):
initialize(color)
dragon_right(max_len, min_len)
if __name__ == '__main__' :
turtle.title("dragon curve fractal")
# experiment with max and min length
max_len = 4000
min_len = 30
dragon_curve(max_len, min_len, 'purple')
# show finished result until corner x is clicked
turtle.done()
```

This question has already been answered. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...