«
Python之Turtle模块
benojan 发布于
阅读:732
python
常用命令
窗体和画布
# 窗体大小
turtle.setup(宽, 高, x坐标=屏幕居中, y坐标=屏幕居中)
# 画布大小
turtle.screensize(宽, 高, 色)
turtle.screensize() # 默认:400 × 300
画笔
turtle.pensize(粗细) # 笔粗
turtle.width(粗细) # 笔粗
turtle.pencolor(色) # 笔色: white, yellow, magenta, cyan, blue, black
turtle.pencolor(R,G,B)
turtle.pencolor( (R,G,B) )
turtle.colormode(色型) # 色型: 1.0, 255
turtle.fillcolor(色) # 填色
turtle.color(笔色, 填色)
画笔动作
turtle.pendown() # 落笔
turtle.down() # 落笔
turtle.pd() # 落笔
turtle.penup() # 挈笔
turtle.up() # 挈笔
turtle.pu() # 挈笔
turtle.goto(x坐标, y坐标) # 移动
turtle.forward(距离) # 前进
turtle.fd(距离) # 前进
turtle.backward(距离) # 后退
turtle.bk(距离) # 后退
turtle.left(角度) # 左转
turtle.right(角度) # 右转
turtle.seth(角度) # 设置朝向
turtle.setheading(角度) # 设置朝向
turtle.begin_fill() # 开始上色
turtle.end_fill() # 结束上色
turtle.circle(半径, 角度=360) # 画弧线,半径>100,圆心在左侧,半径<100,圆心在右侧
全局
stamp() # 复制当前图形
turtle.write(文字, 字体=("字体名", 字号, "字形"))
turtle.showturtle() # 显示海龟
turtle.hideturtle() # 隐藏海龟
turtle.isvisible() # 检查海龟是否可见
turtle.clear() # 清除(只清除绘图)
turtle.reset() # 重置(恢复一切到初始)
turtle.undo() # 撤销动作
turtle.exitonclick() # 画完不关窗,点窗退出
turtle.done() # 中断绘制,关窗后继续绘制
颜色表
英文名 |
RGB整数表示色型 |
RGB小数表示色型 |
中文名 |
white |
255, 255, 255 |
1, 1, 1 |
白 |
yellow |
255, 255, 0 |
1, 1, 0 |
黄 |
magenta |
255, 0, 255 |
1, 0, 1 |
梅红 |
cyan |
0, 255, 255 |
0, 1, 1 |
青 |
blue |
0, 0, 255 |
0, 0, 1 |
蓝 |
black |
0, 0, 0 |
0, 0, 0 |
乌 |
seashell |
255, 245, 238 |
1, 0.96, 0.93 |
海贝 |
gold |
255, 215, 0 |
1, 0.84, 0 |
金 |
pink |
255, 192, 203 |
1, 0.75, 0.80 |
粉 |
brown |
165, 42, 42 |
0.65, 0.16, 0.16 |
棕/褐 |
purple |
160, 32, 240 |
0.63, 0.13, 0.94 |
紫 |
tomato |
255, 99, 71 |
1, 0.39, 0.28 |
番茄色 |
python turtle