






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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)
1 / 10
This page cannot be seen from the preview
Don't miss anything!







import turtle as tur screen = tur.Screen() screen = tur.Screen() screen.setup(width=5600 , height=4800)
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)
tur.speed(0) tur.width(6) screen.bgcolor("black")
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()