-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclaude-3.5-sonnet.py
71 lines (58 loc) · 1.95 KB
/
claude-3.5-sonnet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#anthropic/claude-3.5-sonnet
import turtle
import random
def draw_tree(t, branch_len, angle, min_length=5):
"""
Recursively draws a tree using turtle graphics
Args:
t: turtle object
branch_len: length of the current branch
angle: base angle for branching
min_length: minimum branch length to stop recursion
"""
# Save the current state
t.width(max(1, branch_len/10)) # Branch thickness proportional to length
# Draw the branch
t.forward(branch_len)
# Only create sub-branches if branch is long enough
if branch_len > min_length:
# Right sub-branch
t.right(angle + random.randint(-15, 15))
# Save position and heading
pos = t.position()
heading = t.heading()
# Recursively draw right sub-branch
draw_tree(t, branch_len * random.uniform(0.6, 0.8), angle * 0.9)
# Return to saved position and heading
t.penup()
t.setposition(pos)
t.setheading(heading)
t.pendown()
# Left sub-branch
t.left(angle + random.randint(-15, 15))
draw_tree(t, branch_len * random.uniform(0.6, 0.8), angle * 0.9)
# Return to start of current branch
t.penup()
t.setposition(pos)
t.setheading(heading)
t.pendown()
def main():
# Set up the screen
screen = turtle.Screen()
screen.bgcolor("white")
screen.title("Recursive Tree")
# Create and configure the turtle
t = turtle.Turtle()
t.speed(0) # Fastest speed
t.color("brown")
t.left(90) # Point turtle upward
t.penup()
t.setposition(0, -200) # Start at bottom of screen
t.pendown()
# Draw the tree
draw_tree(t, 100, 30)
# Hide the turtle and display the result
t.hideturtle()
screen.mainloop()
if __name__ == "__main__":
main()