Simple Python Turtle Graphic and Code: colorsys hsv 2

Описание к видео Simple Python Turtle Graphic and Code: colorsys hsv 2

A colorful image generated by twisted circles that slightly change in hue as they move about the center of graphic.

Feel free to copy the basic Python Turtle code that is given below. Don't hesitate to ask questions about the code if you have any. Enjoy! Please comment, like, or subscribe :)

Incidentally, for manually colorable graphics and variations, please visit my author site at https://www.amazon.com/author/basicpy...

import turtle
import colorsys #Module call to utilize the hue, saturation, value (hsv) coloring scheme
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
h = 0 #Initialization of hue h to 0 or red
screen.bgcolor("white") #Assignment of background color
t.pensize(4)
t.speed(9) #Changeable speed of drawing
long_radius = 90 #Changeable to a number close to 90; Radius of bigger round shape
short_radius = 20 #Changeable to a number close to 20; Radius of smaller round shape
number_of_twisted_circles = 36 #Changeable; Count of pairs of bigger and smaller round shapes
def twisted_circle(): #Procedure for drawing a pair of bigger and smaller round shapes
t.circle(-long_radius, 135) #From lines 13 to 17: Arcs and lines that compose a pair of round shapes
t.forward(long_radius + short_radius)
t.circle(short_radius, 270)
t.forward(long_radius + short_radius)
t.circle(-long_radius, 135)
t.left(90) #Python_Graphic start of drawing procedure
for i in range(number_of_twisted_circles): #Loop to draw the indicated number of twisted circles
c = colorsys.hsv_to_rgb(h, 1, 1) #Assignment of current hue, saturation, and value (hsv) numbers to c
t.color(c) #Assignment of current hsv to pencolor
twisted_circle() #Function call to draw a pair of bigger and smaller round shapes
t.left(360 / number_of_twisted_circles) #turtle rotation towards initial direction of drawing for the next twisted circle
h += 1.0 / number_of_twisted_circles #Adjustment of hue value for the next twisted circle
screen.exitonclick()

Комментарии

Информация по комментариям в разработке