基础语法
# 前进 50 单位
go(50)
# 转向 90 度
turn(90)
# 绿色线条
color("green")
# 设置线条宽度为10
width(10)
# 重置
reset()
# 隐藏乌龟
invisible()
# 显示乌龟
visible()
# 抬笔
pen_up()
# 落笔
pen_down()
# 清空
clear()
# for...in... 循环
for i in range(3):
pass
# 方法定义
def polygon(n):
...
学习代码:
lv1:
# 示例1
def lv1():
reset()
go(50)
turn(90)
go(200)
turn(-90)
go(50)
turn(-90)
color("green")
go(100)
color("white")
go(100)
width(10)
go(100)
turn(-90)
width(1)
go(100)
width(50)
go(100)
lv1()
lv2:
# 示例2
def lv2():
reset()
go(50)
turn(90)
invisible()
go(100)
visible()
turn(90)
pen_up()
go(100)
turn(90)
go(50)
pen_down()
go(50)
clear()
go(100)
lv2()
lv3:
def lv3():
reset()
for i in range(3):
go(100)
turn(360/3)
color("white")
for i in range(4):
go(100)
turn(360/4)
color("blue")
for i in range(5):
go(100)
turn(360/5)
turn(-90)
for i in range(40):
width(i)
go(4)
color("red")
width(3)
for i in range(36):
go(10)
turn(360/36)
lv3()
lv4:
# 示例4
def polygon(n):
for i in range(n):
go(50)
turn(360.0/n)
def circle():
polygon(36)
def lv4():
reset()
for i in range(36):
for i in range(36):
go(10)
turn(360/36)
turn(10)
clear()
polygon(5)
clear()
for i in range(3,10):
polygon(i)
clear()
for i in range(3,15):
polygon(i)
turn(30)
clear()
color_list=["red","green","blue","purple","orange","yellow"]
for i in color_list:
color(i)
circle()
turn(60)
lv4()
# 正方形
def square(width):
reset()
for i in range(4):
go(width)
turn(90)
square(100)
发表评论