Python Paintbrush: Galaxy Animation ✨✨- Turtle's Technicolor Dream with electro4u

20 Jul 2023 Balmiki Mandal 0 Python

Eye-Catching: Hypnotic Multi-Color Turtle Spiral - Dive into Python Animation ✨

Breakdown of the code, along with visuals to illustrate its effects:

import turtle #importing the turtle modules
turtle.bgcolor("black") #setting the background color to black
squary = turtle.Turtle() #creatting a turtle names as squary
squary.speed(0) #setting drawing speed to fastest (0)
squary.pencolor("gold") #setting the color of the line that the turtle will draw to gold
colors = ["red", "orange", "yellow", "blue"] # creatting a list of color

for i in range(400): #Starting a loop that will run through 400 times
    squary.color(colors[i % len(colors)]) #cycle through colors
    squary.forward(i) #moving the turtle forward by a distance of i pixel
    squary.left(91 + i / 50)

turtle.done() #keeps the window open untill closed manually

1. Importing the Turtle Module:

  • import turtle brings in the turtle graphics library, a tool for creating simple graphics in Python.

2. Setting the Stage:

  • turtle.bgcolor("black") sets the background color of the drawing canvas to black, like a dark night sky.

3. Creating the Turtle Artist:

  • squary = turtle.Turtle() creates a turtle object named "squary," who will act as the artist, drawing lines on the canvas.
  • squary.speed(0) sets squary's drawing speed to the fastest setting (0), so you'll see the artwork unfold quickly.
  • squary.pencolor("gold") sets the color of squary's pen to gold, adding a touch of brilliance to the drawing.

4. Preparing a Palette of Colors:

  • colors = ["red", "orange", "yellow", "blue"] creates a list of colors that squary will use to paint the spiral.

5. The Spiral Dance Begins:

  • for i in range(400): starts a loop that will repeat 400 times, guiding squary's movements.
    • squary.color(colors[i % len(colors)]) picks a color from the list for each step, ensuring a vibrant blend.
    • squary.forward(i) moves squary forward by a distance of 'i' pixels, creating longer lines as the spiral grows.
    • squary.left(91 + i / 50) turns squary to the left, forming the spiral's curves. The angle of turn gradually increases, adding a dynamic twist.

6. Admiring the Masterpiece:

  • turtle.done() keeps the window open, allowing you to appreciate the final spiral masterpiece until you manually close it.

The Result:

 

As the code runs, you'll witness a mesmerizing spiral emerge on the screen, painted in a radiant symphony of colors against the black backdrop. The golden lines trace a path of ever-increasing length, turning and twisting with graceful precision to form a captivating pattern that draws the eye inward.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.