Python的turtle模块用法及实例 六:魔法阵七:樱花树 八:小猪佩奇九:多来爱梦

目录

turtle:基本用法

一:画圆

二:奥运五环

三:美队盾牌

 四:繁星

 五:星空

 六:魔法阵

七:樱花树

 八:小猪佩奇

九:多来爱梦


 

turtle:基本用法

turtle.down() #移动时绘制图形,缺省时也为绘制

turtle.up() #移动时不绘制图形

turtle.pensize(width) #绘制图形时的宽度

turtle.color(colorstring) #绘制图形时的颜色

turtle.fillcolor(colorstring) #绘制图形的填充颜色

turtle.done() 停留在结束界面

turtle.hideturtle() 隐藏图标

turtle.showturtle() 显示图标

turtle.begin_fill() 开始填充

turtle.fillcolor(颜色) 填充颜色

turtle.end_fill() 结束填充

turtle.setheading() 改变笔头朝向

turtle.pencolor(colorstr)笔画颜色

turtle.pendown()(别名:turtle.pd(),turtle.down()):移动时绘制图形,缺省时也为绘制

 

运动命令:

turtle.forward(degree) #向前移动距离degree代表距离

turtle.backward(degree) #向后移动距离degree代表距离

turtle.right(degree) #向右移动多少度

turtle.left(degree) #向左移动多少度

turtle.goto(x,y) #将画笔移动到坐标为x,y的位置

turtle.stamp() #复制当前图形

turtle.speed(speed) #画笔绘制的速度范围[0,10]整数

turtle.clear() 清空turtle画的笔迹

turtle.reset() 清空窗口,重置turtle状态为起始状态

turtle.undo() (未测试)撤销上一个turtle动作

turtle.isvisible() (未测试)返回当前turtle是否可见

turtle.stamp() (未测试)复制当前图形

turtle.write(‘vshmily’) 写字符串’vshmily’

turtle.write(s[,font=(“font-name”,font_size,“font_type”)]) (未测试)写文本,s为文本内容,font是字体的参数,里面分别为字体名称,大小和类型;font为可选项, font的参数也是可选项 turtle.circle(7) 画一个半径为7的圆 turtle.circle(77, steps=3) 三边形,画一个半径为77的园的内切多边形

turtle.circle(77, 300) 圆弧为300度

turtle.screensize(800, 600, “green”)

turtle.screensize() #返回默认大小(400, 300)

 

一:画圆

import turtle  # 导入模块

turtle.screensize(800, 600, 'green') # 创建画布
turtle.circle(40) # 画笔循环画个圆,以画布中心为起点,半径为40

turtle.screensize() #返回默认大小(400, 300)

58fe9a0f078d47ffadafbcc9e9149824.png

 

import turtle as tur
tur.speed(0)  # 设置速度,让画的速度最快
# 第一个图
for i in range(12):
    tur.pencolor('black')
    tur.right(91)
    tur.circle(100)
# 第二个图
# for i in range(50):
#     tur.pencolor('red')
#     tur.right(63)
#     tur.circle(57)

tur.done()

f35b0f26f0ad4c34a3f5a9f65ec5bb5f.png

 4c7372de15ba41fe8c5f4efb09b2585b.png

二:奥运五环

import turtle as tur
tur.speed(0)
tur.pensize(9)
tur.color('black')
tur.circle(80)
tur.penup()
tur.goto(-140,0)
tur.pendown()

tur.color('blue')
tur.circle(80)
tur.penup()
tur.goto(140,0)
tur.pendown()

tur.color('red')
tur.circle(80)
tur.penup()
tur.goto(80,-100)
tur.pendown()

tur.color('yellow')
tur.circle(80)
tur.penup()
tur.goto(-60,-100)
tur.pendown()

tur.color('green')
tur.circle(80)
tur.penup()
tur.goto(-60,160)
tur.pendown()

tur.done()

三:美队盾牌

import turtle as tur
tur.speed(0)
tur.penup()
tur.goto(0,-100)
tur.pendown()
tur.color('red')
tur.begin_fill()
tur.circle(150)
tur.end_fill()

tur.penup()
tur.goto(0,-70)
tur.pendown()
tur.color('white')
tur.begin_fill()
tur.circle(120)
tur.end_fill()


tur.penup()
tur.goto(0,-50)
tur.pendown()
tur.color('red')
tur.begin_fill()
tur.circle(100)
tur.end_fill()

tur.penup()
tur.goto(0,-10)
tur.pendown()
tur.color('blue')
tur.begin_fill()
tur.circle(60)
tur.end_fill()

tur.penup()
tur.goto(-55,70)
tur.pendown()
tur.color('yellow')
tur.begin_fill()
for i in range(5):
    tur.forward(109)
    tur.right(144)
tur.end_fill()

tur.done()

3938282b11ab4a9394f8914c56898fc4.png

 四:繁星

import random
import turtle as tur

tur.speed(0)
tur.colormode(255)
tur.bgcolor('black')
tur.pensize(120)
tur.goto(-300,250)
tur.forward(600)

tur.color(50,50,50)
tur.penup()
tur.goto(-350,130)
tur.pendown()
tur.forward(700)

tur.color(75,75,75)
tur.penup()
tur.goto(-350,10)
tur.pendown()
tur.forward(700)

tur.color(100,100,100)
tur.penup()
tur.goto(-350,-110)
tur.pendown()
tur.forward(700)

tur.color(125,125,125)
tur.penup()
tur.goto(-350,-230)
tur.pendown()
tur.forward(800)

# 画星星
for i in range(10):
    tur.pensize(5)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值