我一直试图在蟒蛇中制造一颗星,但我不断得到的只是一些锯齿线。我的代码是:
import turtle
star = turtle.Turtle()
wn = turtle.Screen()
wn.setup(800, 600)
wn.tracer(0)
star.pensize(10)
star.hideturtle()
wn.bgcolo("green")
star.color(white)
def draw_stars(x, y, size):
star. goto(x, y)
star.forward(78)
star.left(144)
star.forward(78)
star.right(144)
star.forward(78)
我写了这个,但是当我运行这个程序并打开乌龟时,我看不到明星应该在哪里转角。
答案 0 :(得分:0)
import turtle
my_turtle = turtle.Turtle()
size = 200
for _ in range(5):
my_turtle.forward(size)
my_turtle.left(144)
或没有for
import turtle
my_turtle = turtle.Turtle()
size = 200
my_turtle.forward(size)
my_turtle.left(144)
my_turtle.forward(size)
my_turtle.left(144)
my_turtle.forward(size)
my_turtle.left(144)
my_turtle.forward(size)
my_turtle.left(144)
my_turtle.forward(size)
my_turtle.left(144)
答案 1 :(得分:0)
from turtle import *
hideturtle()
def draw_star(sidesize, points, alfacorner, color):
betacorner = 360/points+alfacorner
fillcolor(color)
begin_fill()
for x in range(points*2):
forward(sidesize)
if x % 2 == 0:
left(180-alfacorner)
else:
right(180-betacorner)
end_fill()
draw_star(70, 8, 90, 'grey')
draw_star(90, 5, 72, 'yellow')
draw_star(120, 5, 36, 'red')
draw_star(65, 6, 60, 'darkblue')
draw_star(80, 4, 45, 'darkviolet')
draw_star(80, 3, 30, 'greenyellow')
draw_star(80, 6, 0, 'black')