Simple Python Turtle Graphic and Code colorsys hsv 1

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

A multi-colored disk created by a triangle whose third side is a) a bit longer than the first two, and b) directs the turtle a bit differently.

Feel free to copy the simple 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 be able to utilize hsv or hue, saturation, and value in coloring
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
x = 230 #The size of graphic; Side length of equilateral triangle
h = 0 #Initialization of hue to 0 or red
t.pensize(4)
t.speed(0) #Assignment of 0 to make drawing as fast as possible
counter = 0 #Initialization of triangle side counter to zero
t.penup() #Python_Graphic start of drawing procedure
t.goto(-275, -75) #Trail-less movement of turtle to the indicated point
t.forward(x) #Trail-less movement of turtle over x units to starting point of drawing
t.left(120) #Turtle rotation to initial direction of line drawing
t.pendown()
for i in range(120): #Loop to draw 120 triangles
for i in range(3): #Sub loop to draw 3 sides of a triangle
c = colorsys.hsv_to_rgb(h, 1, 1) #Assignment of c as color value, with hue h is changing, and s and v fixed to 1
t.color(c) #Assignment of color based on current value of c
counter += 1 #Change in counter value to identify whether triangle side is 1st, 2nd, or 3rd
if counter == 3: #Conditional statement asking if the triangle side to be drawn is the 3rd
counter = 0 #This line and next two: Instruction on how to draw the 3rd triangle side
t.forward(x + 2 * i)
t.left(123)
else: #Alternative action if counter is not equal to 3
t.forward(x)
t.left(120)
h += 1.000 / 120 #Change in value of hue
t.hideturtle()
screen.exitonclick()

Комментарии

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