Turtle Graphics Art with HSV Color Conversion in Python, Essays (high school) of Computer science

A python code snippet that uses the turtle graphics library to create colorful, geometric art. It includes a custom hsv to rgb color conversion function, which allows for dynamic color manipulation. The code sets up the screen, defines the drawing loop, and generates a series of circles with varying colors and positions to create an interesting visual pattern. This example can be used to teach programming concepts, color theory, and basic geometry in a creative and engaging way. The code is well-commented, making it easy to understand and modify for different artistic effects. The use of loops and functions demonstrates fundamental programming principles, while the visual output provides immediate feedback and encourages experimentation. Suitable for high school students learning introductory programming and computer graphics.

Typology: Essays (high school)

2025/2026

Uploaded on 10/27/2025

avery-capes
avery-capes 🇨🇦

2 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
import turtle as tur
screen = tur.Screen()
screen = tur.Screen()
screen.setup(width=5600 , height=4800)
# Custom HSV to RGB function (returns values in 0–255) this is also the regualar rgb
values so dont mess with it
def hsv_to_rgb(h, s, v):
h = float(h)
s = float(s)
v = float(v)
h60 = h * 6
h60f = int(h60)
f = h60 - h60f
p = v * (1 - s)
q = v * (1 - f * s)
t = v * (1 - (1 - f) * s)
if h60f == 0:
r, g, b = v, t, p
elif h60f == 1:
r, g, b = q, v, p
elif h60f == 2:
r, g, b = p, v, t
elif h60f == 3:
r, g, b = p, q, v
elif h60f == 4:
r, g, b = t, p, v
elif h60f == 5:
r, g, b = v, p, q
else:
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Turtle Graphics Art with HSV Color Conversion in Python and more Essays (high school) Computer science in PDF only on Docsity!

import turtle as tur screen = tur.Screen() screen = tur.Screen() screen.setup(width=5600 , height=4800)

Custom HSV to RGB function (returns values in 0–255) this is also the regualar rgb

values so dont mess with it def hsv_to_rgb(h, s, v): h = float(h) s = float(s) v = float(v) h60 = h * 6 h60f = int(h60) f = h60 - h60f p = v * (1 - s) q = v * (1 - f * s) t = v * (1 - (1 - f) * s) if h60f == 0: r, g, b = v, t, p elif h60f == 1: r, g, b = q, v, p elif h60f == 2: r, g, b = p, v, t elif h60f == 3: r, g, b = p, q, v elif h60f == 4: r, g, b = t, p, v elif h60f == 5: r, g, b = v, p, q else:

r, g, b = 0, 0, 0 return int(r * 255), int(g * 255), int(b * 255)

Turtle setup (0 is the fastest and width 2-7 is good)

tur.speed(0) tur.width(6) screen.bgcolor("black")

Drawing loop (j in rang(25 or 50) for i ing range( has to be 15 to work)

for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(750,0) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color)

tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(0,-750) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(1500,0) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90)

tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(-1500,0) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(0,1500) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90)

tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(-2250,0) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(0,2250) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90)

tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(0,-2250) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(2250,2250) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90)

tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.penup() tur.goto(-2250,-2250) tur.pendown() for j in range(50): for i in range(15): color = hsv_to_rgb(i / 15, j / 25, 1) tur.color(color) tur.right(90) tur.circle(200 - j * 4, 90) tur.left(90) tur.circle(200 - j * 4, 90) tur.left(180) tur.circle(50, 24) tur.hideturtle() tur.done()