Create Colorful Patterns with Python's Turtle Graphics

codepythonic
0

 Create Colorful Patterns with Python's Turtle Graphics



import turtle
import colorsys


t = turtle.Turtle()
s = turtle.Screen()
s.bgcolor('black')
t.speed(0)
n = 70
h = 0


def draw_pattern(turtle, num_sides, side_length):
    angle = 360 / num_sides
    for _ in range(num_sides):
        turtle.forward(side_length)
        turtle.right(angle)


for i in range(360):
    c = colorsys.hsv_to_rgb(h, 1, 1)
    h += 1 / n
    t.color(c)
    t.left(1)
    t.forward(1)


    draw_pattern(t, 6, 50)  # Draw a hexagon pattern


turtle.done()


Tags:

Post a Comment

0Comments

Post a Comment (0)