Showing posts with label Python Turtle. Show all posts
Showing posts with label Python Turtle. Show all posts

Saturday, 7 November 2026

Python Turtle — The Hypnotic Rainbow Vortex

 


Code:

import turtle import time import colorsys s = turtle.Screen() s.setup(750, 750) s.bgcolor("black") s.title("Rainbow Hypnotic Vortex") s.tracer(0) t = turtle.Turtle() t.hideturtle() t.speed(0) t.pensize(2) for i in range(180): t.pencolor(colorsys.hsv_to_rgb(i / 180, 1, 1)) t.penup() t.goto(0, 0) t.setheading(i * 7) t.pendown() length = 80 + i * 1.8 for _ in range(2): t.forward(length) t.circle(35 + i * 0.15, 90) s.update() time.sleep(0.025) turtle.done()













Explanation:

1. Import Libraries
import turtleimport timeimport colorsys

- turtle – draws the vortex pattern.
- time – adds animation delays.
- colorsys – generates rainbow colors using HSV color values.

2. Create the Screen
s = turtle.Screen()s.setup(750, 750)s.bgcolor("black")s.title("Rainbow Hypnotic Vortex")s.tracer(0)


- Creates a 750 × 750 graphics window.
- Sets the background to black.
- Adds the window title.
- tracer(0) disables automatic screen updates.

3. Configure the Turtle
t = turtle.Turtle()t.hideturtle()t.speed(0)t.pensize(2)
- Creates the drawing turtle.
- Hides the turtle cursor.
- Sets the fastest drawing speed.
- Sets the pen thickness to 2.

4. Create the Main Loop
for i in range(180):

Repeats the drawing process 180 times to create multiple rotating patterns.

5. Generate Rainbow Colors
t.pencolor(colorsys.hsv_to_rgb(i / 180, 1, 1))

- Converts HSV color values into RGB.
- i / 180 gradually changes the hue.
- 1 represents full saturation.
- 1 represents full brightness.
- Produces a continuous rainbow color effect.

6. Set the Drawing Position
t.penup()t.goto(0, 0)t.setheading(i * 7)t.pendown()

- Lifts the pen to avoid unwanted lines.
- Moves the turtle to the center.
- Rotates the direction by 7° on each iteration.
- Puts the pen down to start drawing.

7. Calculate the Pattern Length
length = 80 + i * 1.8

- Starts with a length of 80 units.
- Increases the length by 1.8 units per iteration.
- Creates progressively larger patterns.

8. Draw the Curved Vortex
for _ in range(2):    t.forward(length)    t.circle(35 + i * 0.15, 90)

- Repeats the drawing movement twice.
- forward(length) draws a straight line.
- circle() creates a curved arc.
- The circle radius gradually increases with i.
- Combines straight and curved movements to create the vortex effect.

9. Animate the Drawing
s.update()time.sleep(0.025)

- s.update() refreshes the screen manually.
- time.sleep(0.025) pauses for 0.025 seconds.
- Makes the drawing animation visible.

10. Finish the Program
turtle.done()



Keeps the Turtle graphics window open after the artwork is complete.




Output:
Image


Popular Posts

Categories

100 Python Programs for Beginner (119) AI (359) Android (25) AngularJS (1) API (2) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (359) Bootcamp (20) C (78) C# (12) C++ (83) cloud (1) Course (97) Coursera (307) Cybersecurity (37) data (10) Data Analysis (48) Data Analytics (31) data management (16) Data Science (443) Data Strucures (21) Deep Learning (228) Django (17) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Gadgets (1) Generative AI (80) Git (14) Google (55) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (417) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (36) Python (1405) Python Bug (1) Python Coding Challenge (1303) Python Library (29) Python Mathematics (24) Python Mistakes (51) Python Pattern Challenge (38) Python Quiz (685) Python Tips (115) Python Turtle (1) Questions (3) R (72) React (7) Scripting (3) security (5) Selenium Webdriver (4) Software (21) SQL (56) Udemy (24) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)