代码1:
划一个简单的x及y轴,标出原点O及坐标为(100,100)的A点。
import turtle turtle.goto(0,0) turtle.dot(20,"yellow") turtle.write("O", font=('Arial', 10, 'normal')) turtle.forward(300) turtle.forward(-600) turtle.goto(0,0) turtle.left(90) turtle.forward(300) turtle.forward(-600) turtle.penup() turtle.goto(100,100) turtle.dot(10,"red") turtle.write("A", font=('Arial', 10, 'normal')) turtle.pendown() turtle.circle(20) turtle.mainloop()
代码2:划出一个五角星。线框为黄色,填充色为红色。5角星的144度是有一个关系算法:144*5=720=360*2
import turtle turtle.pensize(5) turtle.pencolor("yellow") turtle.fillcolor("red") turtle.backward(200) turtle.begin_fill() for _ in range(5): turtle.forward(400) turtle.right(144) turtle.end_fill()
课后作业:
1.复制上述代码,在Python环境下运行。
2.读懂上述代码。