Skip to content

nomankarim8/Turtle-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 

Repository files navigation

logo

Turtle Graphics Colorful Pattern

This Python script uses the turtle graphics library to create a colorful, intricate pattern. The colors are generated using the colorsys module to convert HSV colors to RGB.

Requirements

  • Python 3.x
  • turtle module (usually included with Python's standard library)
  • colorsys module (part of Python's standard library)

Installation

No external packages are required to run this script as it only uses Python's standard library.

Usage

To run the script, simply execute it with Python:

python turtle_pattern.py

Code Explanation

The script initializes the turtle graphics and sets the background color to black. It then uses nested loops to draw circles with varying radii and colors. The colorsys.hsv_to_rgb function is used to convert HSV color values to RGB, creating a smooth transition of colors.

from turtle import *
import colorsys

speed(0)
bgcolor("black")
h = 0

for i in range(16):
    for j in range(18):
        c = colorsys.hsv_to_rgb(h, 1, 1)
        color(c)
        h += 0.005
        rt(90)
        circle(150 - j * 6, 90)
        lt(90)
        circle(150 - j * 6, 90)
        rt(180)
    circle(40, 24)

done()

Detailed Steps

  1. Setup

    • speed(0): Set the turtle's speed to the fastest.
    • bgcolor("black"): Set the background color to black.
  2. Drawing Loop

    • Outer loop runs 16 times.
    • Inner loop runs 18 times for each iteration of the outer loop.
    • colorsys.hsv_to_rgb(h, 1, 1): Convert HSV to RGB to get the color.
    • Adjust h to create a gradient effect.
    • Draw two quarter circles with decreasing radii, adjusting direction to create the pattern.
    • Move the turtle to start the next segment of the pattern.
  3. Completion

    • done(): Signal that the drawing is complete.

License

This project is licensed under the MIT License.


Releases

No releases published

Packages

No packages published

Languages