I am using vscode. Only a simple turtle statement can show the graphic window effect. Why can't the graphics windows be displayed?
from turtle import *
def star(sidelength):
'''Draws a 5-pointed star of a
given sidelength'''
for i in range(5):
forward(sidelength)
right(144) #why this angle??
def starSpiral():
'''Draws a spiral of stars'''
length = 5
for i in range(60):
star(length)
right(5)
length += 5
After running, nothing came out.
According to the information you provided, I ran it on my computer and modified the code:
1.Draws a 5-pointed star of a given sidelength:
For drawing a five-pointed star with a given side length, we need to give it an input value:
import turtle
def star():
sidelength = int(input("Please input sidelength:"))
turtle.begin_fill()
i = 1
for i in range(5):
turtle.forward(sidelength)
turtle.right(144)
i += 1
turtle.end_fill()
star()
Run:
import turtle def starSpiral(): '''Draws a spiral of stars''' for i in range(60): turtle.forward(5*i) turtle.left(144) starSpiral()
run:
About "right(144) #why this angle?":
It means to turn 144 degrees to the right, because each angle of the five-pointed star is 36 degrees, so the angle we need to rotate when drawing is 180-36=144
degree.