目录

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)

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()

二:奥运五环

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()

四:繁星

import random
import turtle as turtur.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)tur.color('yellow')tur.penup()tur.goto(random.randint(-200,200),random.randint(-200,200))tur.pendown()tur.begin_fill()for i in range(10):tur.forward(10)if i%2 == 0:tur.left(35)else:tur.right(105)tur.end_fill()tur.done()

五:星空

from turtle import *
from random import random,randint
screen = Screen()
width ,height = 800,600
screen.setup(width,height)
screen.bgcolor("black")
screen.mode("logo")
screen.delay(0)#这里要设为0,否则很卡
t = Turtle(visible = False,shape='circle')
t.pencolor("white")
t.fillcolor("white")
t.penup()
t.setheading(-90)
t.goto(width/2,randint(int(-height/2),int(height/2)))
stars = []
for i in range(200):star = t.clone()s =random() /3star.shapesize(s,s)star.speed(int(s*10))star.setx(width/2 + randint(1,width))star.sety( randint(int(-height/2),int(height/2)))star.showturtle()stars.append(star)
while True:for star in stars:star.setx(star.xcor() - 3 * star.speed())if star.xcor()<-width/2:star.hideturtle()star.setx(width/2 + randint(1,width))star.sety( randint(int(-height/2),int(height/2)))star.showturtle()

六:魔法阵

import turtle as tdef tcyuan(x, y, r):t.fillcolor("black")t.begin_fill()t.seth(0)y = y - rt.penup()t.goto(x, y)t.pendown()t.circle(r)t.end_fill()def yuan(x, y, r):t.seth(0)y = y - rt.penup()t.goto(x, y)t.pendown()t.circle(r)def yueliang():R = 110 - 1r = R - 22 - 1# 月亮填充t.penup()t.goto(-350 + 2 * R, 0)t.seth(90)t.fillcolor("black")t.begin_fill()t.circle(R, 359)t.left(90)t.fd(2)t.left(90)t.circle(-r, 359)t.left(90)t.fd(2)t.pendown()t.end_fill()# 轮廓yuan(-350 + R, 0, R)yuan(-350 + 44 + r - 2, 0, r - 2)def zhixian(R, r, count, jiaodu):t.seth(90 + jiaodu)#    t.goto(0, 0)for i in range(count):t.penup()t.goto(0, 0)t.fd(r)t.pendown()t.fd(R - r)t.left(360 / count)def zfx(R, r):jiange = 10#    t.pensize(jiange)t.seth(90)big = pow((R ** 2) * 2, 0.5)small = big - 2 * jiangefor i in range(13):# 大线t.penup()t.goto(0, 0)t.fd(R)t.pendown()t.right(135)t.fd(big)# 小线t.left(135)t.penup()t.goto(0, 0)t.fd(pow((small ** 2) / 2, 0.5))t.pendown()t.right(135)t.fd(small)# 粗线t.pensize(8)t.pencolor("black")t.left(135)t.penup()t.goto(0, 0)t.fd((R + pow((small ** 2) / 2, 0.5)) / 2)t.pendown()t.right(135)t.fd((big + small) / 2)t.pensize(2)t.pencolor("yellow")t.seth(90 + i * 30)else:# 大线t.penup()t.goto(0, 0)t.fd(R)t.right(135)t.fd(big / 2)t.pendown()t.fd(big / 2)# 小线t.left(135)t.penup()t.goto(0, 0)t.fd(pow((small ** 2) / 2, 0.5))t.right(135)t.fd(small / 2)t.pendown()t.fd(small / 2)# 粗线t.pensize(8)t.pencolor("black")t.left(135)t.penup()t.goto(0, 0)t.fd((R + pow((small ** 2) / 2, 0.5)) / 2)t.right(135)t.fd((big + small) / 2 / 2)t.pendown()t.fd((big + small) / 2 / 2)t.pensize(2)t.pencolor("yellow")t.seth(90 + i * 30)def wjx(r, jiaodu):t.fillcolor("black")t.penup()t.goto(0, 0)t.seth(90 + jiaodu)t.fd(r)t.pendown()t.right(18)t.begin_fill()for i in range(5):t.right(144)t.forward(144)t.left(72)t.forward(144)t.end_fill()if jiaodu != 0:t.seth(90 + jiaodu)for i in range(1, 6):t.penup()t.goto(0, 0)t.left(72)t.pendown()t.fd(r)def xingzuo():r = 250t.penup()t.goto(20, -35)t.seth(-45)t.fd(r)t.pendown()xz = ['♒', '♓', '♈', '♉', '♌', '♍', '♎', '♏']for i in range(4):t.write(xz[i], font=("", 20, ""))t.penup()t.right(90)t.circle(-300, 30)t.left(90)t.pendown()t.penup()t.goto(-r / 4 + 10, 5)t.seth(135)t.fd(r)for i in range(4, 8):t.write(xz[i], font=("", 20, ""))t.penup()t.right(90)t.circle(-300, 30)t.left(90)t.pendown()def dxnb(s):t.penup()t.fd(-19)t.left(90)t.fd(2)t.pendown()t.write(s, font=["KaiTi", 30, "bold"])def taiyang():def haicao(r, i):# 海藻t.fillcolor("black")t.penup()if i == 0:t.goto(256, r)elif i == 1:t.goto(256 - r, 0)else:t.goto(256, -r)t.pendown()t.begin_fill()t.seth(2 + i * 90)t.circle(r / 2, 105)t.left(10)t.circle(-r / 3, 90)t.circle(r / 3, 60)t.left(20)t.circle(r / 3, -80)t.left(50)t.circle(-r + 10, -40)t.right(30)t.circle(r / 2 + 10, -50)t.penup()if i == 0:t.goto(256, r)elif i == 1:t.goto(256 - r, 0)else:t.goto(256, -r)t.pendown()t.end_fill()t.seth(2 + i * 90)t.circle(r / 2, 105)t.left(10)t.circle(-r / 3, 90)t.begin_fill()t.circle(r / 3, 60)t.left(20)t.circle(r / 3, -80)t.left(50)t.circle(-r + 10, -40)t.right(30)t.circle(r / 2 + 10, -50)t.right(30)t.circle(r / 2 - 2, 110)t.circle(-r / 3, 70)t.left(7)t.circle(r / 3, 85)t.end_fill()t.penup()if i == 0:t.goto(256, r)t.pendown()t.seth(180 - (2 + i * 90))t.circle(-(r / 2), 105)elif i == 1:t.goto(256 - r, 0)t.pendown()t.seth(- (2 + i * 90))t.circle(-(r / 2), 105)else:t.goto(256, -r)t.pendown()t.seth(180 - (2 + i * 90))t.circle(-(r / 2), 105)t.begin_fill()t.left(-10)t.circle(-(-r / 3), 90)t.circle(-(r / 3), 60)t.left(-20)t.circle(-(r / 3), -80)t.left(-50)t.circle(-(-r + 10), -40)t.right(-30)t.circle(-(r / 2 + 10), -50)t.end_fill()t.penup()if i == 0:t.goto(256, r)t.pendown()t.seth(180 - (2 + i * 90))t.circle(-(r / 2), 105)elif i == 1:t.goto(256 - r, 0)t.pendown()t.seth(- (2 + i * 90))t.circle(-(r / 2), 105)else:t.goto(256, -r)t.pendown()t.seth(180 - (2 + i * 90))t.circle(-(r / 2), 105)t.pendown()t.left(-10)t.circle(-(-r / 3), 90)t.circle(-(r / 3), 60)t.left(-20)t.begin_fill()t.circle(-(r / 3), -80)t.left(-50)t.circle(-(-r + 10), -40)t.right(-30)t.circle(-(r / 2 + 10), -50)t.right(-30)t.circle(-(r / 2 - 2), 110)t.circle(-(-r / 3), 70)t.left(-7)t.circle(-(r / 3), 85)t.end_fill()def xhaicao(r, i):t.penup()t.goto(256 + r, 0)t.seth(-90)t.circle(-r, 20)t.pendown()t.begin_fill()t.seth(30)t.circle(-r / 3, 100)t.circle(r / 6, 140)t.circle(-r / 11, 100)t.left(80)t.circle(-r / 2, -30)t.circle(r / 4, -140)t.circle(-r / 3, -60)t.end_fill()t.penup()t.goto(256 + r, 0)t.seth(-90)t.circle(-r, 30)t.pendown()t.seth(45)t.circle(-r / 4, 100)t.right(20)t.circle(r / 4, 140)t.right(10)t.circle(-r / 11, 90)t.penup()t.goto(256 + r, 0)t.seth(90)t.circle(r, 20)t.pendown()t.begin_fill()t.seth(-30)t.circle(-(-r / 3), 100)t.circle(-(r / 6), 140)t.circle(-(-r / 11), 100)t.left(-80)t.circle(-(-r / 2), -30)t.circle(-(r / 4), -140)t.circle(-(-r / 3), -60)t.end_fill()t.penup()t.goto(256 + r, 0)t.seth(90)t.circle(r, 30)t.pendown()t.seth(-45)t.circle(-(-r / 4), 100)t.right(-25)t.circle(-(r / 4), 140)t.right(-10)t.circle(-(-r / 11), 90)r = 50# 海藻haicao(r, 0)haicao(r, 1)haicao(r, 2)xhaicao(r, 3)# 大三角形t.fillcolor("black")for i in range(1, 4):temp = 3t.penup()t.goto(256, 0)t.seth(i * 90)t.pendown()t.begin_fill()t.right(22.5)t.fd(r)if i == 1:t.goto(256, 3 * r - temp)t.goto(256, 0)t.seth(i * 90 + 22.5)t.fd(r)t.goto(256, 3 * r - temp)elif i == 2:t.goto(256 - 3 * r + temp, 0)t.goto(256, 0)t.seth(i * 90 + 22.5)t.fd(r)t.goto(256 - 3 * r + temp, 0)else:t.goto(256, -3 * r + temp)t.goto(256, 0)t.seth(i * 90 + 22.5)t.fd(r)t.goto(256, -3 * r + temp)t.end_fill()# 小三角形x = pow(((2 * r) ** 2) / 2, 0.5) - 8for i in range(1, 5):t.penup()t.goto(256, 0)t.seth(i * 90)t.pendown()t.begin_fill()t.right(22.5)t.fd(r)if i == 1:t.goto(256 + x, x)t.goto(256, 0)t.right(45)t.fd(r)t.goto(256 + x, x)elif i == 2:t.goto(256 - x, x)t.goto(256, 0)t.right(45)t.fd(r)t.goto(256 - x, x)elif i == 3:t.goto(256 - x, -x)t.goto(256, 0)t.right(45)t.fd(r)t.goto(256 - x, -x)else:t.goto(256 + x, -x)t.goto(256, 0)t.right(45)t.fd(r)t.goto(256 + x, -x)t.end_fill()# 圆#    t.begin_fill()tcyuan(256, 0, r)# 初始化
t.setup(1500, 800, 0, 0)
t.speed(0)
t.bgcolor("black")
t.pencolor("yellow")
t.pensize(2)
# 最大的圆
yuan(0, 0, 350)
yuan(0, 0, 325)
yuan(0, 0, 321)
yuan(0, 0, 306)
zhixian(321, 306, 72, 0)
# 小圆
yuan(0, 0, 204)
yuan(0, 0, 200)
yuan(0, 0, 186)
zhixian(200, 186, 72, 0)
# 正方形边框以及直线
zhixian(290, 213, 12, 0)
zhixian(248, 205, 12, 15)
zfx(306, 204)
# 里五角星
wjx(200, 36)
# 月亮
yueliang()
# 太阳
taiyang()
# 最小圆
tcyuan(0, 328, 22)
dxnb("北")
tcyuan(0, -328, 22)
dxnb("南")
tcyuan(-328, 0, 22)
dxnb("西")
tcyuan(328, 0, 22)
dxnb("東")# 外五角星
wjx(200, 0)
# 星座
xingzuo()
t.penup()
t.goto(-500, -500)
t.pendown()
t.done()

七:樱花树

import turtle as tur
import random
import math
def tree(n, l):tur.setup(800, 600)tur.pd()  # 下笔# 阴影效果t = math.cos(math.radians(tur.heading() + 45)) / 8 + 0.25tur.pencolor('tan')tur.pensize(n / 3)tur.forward(l)  # 画树枝if n > 0:b = random.random() * 15 + 10  # 右分支偏转角度c = random.random() * 15 + 10  # 左分支偏转角度d = l * (random.random() * 0.25 + 0.7)  # 下一个分支的长度# 右转一定角度,画右分支tur.right(b)tree(n - 1, d)# 左转一定角度,画左分支tur.left(b + c)tree(n - 1, d)# 转回来tur.right(c)else:# 画叶子tur.right(90)n = math.cos(math.radians(tur.heading() - 45)) / 4 + 0.5tur.pencolor('lightcoral')tur.circle(3)tur.left(90)# 添加0.3倍的飘落叶子if (random.random() > 0.7):tur.pu()# 飘落t = tur.heading()an = -40 + random.random() * 40tur.setheading(an)dis = int(800 * random.random() * 0.5 + 400 * random.random() * 0.3 + 200 * random.random() * 0.2)tur.forward(dis)tur.setheading(t)# 画叶子tur.pd()tur.right(90)n = math.cos(math.radians(tur.heading() - 45)) / 4 + 0.5tur.pencolor(n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4)tur.circle(2)tur.left(90)tur.pu()# 返回t = tur.heading()tur.setheading(an)tur.backward(dis)tur.setheading(t)tur.pu()tur.backward(l)  # 退回tur.bgcolor('white')  # 背景色
tur.ht()  # 隐藏turtle
tur.speed(0)  # 速度,1-10渐进,0最快
tur.tracer(0, 0)
tur.pu()  # 抬笔
tur.backward(100)
tur.left(90)  # 左转90度
tur.pu()  # 抬笔
tur.backward(300)  # 后退300
tree(10, 100)  # 递归7层
tur.done()

 八:小猪佩奇

# -*- coding:utf-8 -*-from turtle import*def nose(x,y):#鼻子penup()#提起笔goto(x,y)#定位pendown()#落笔,开始画setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)begin_fill()#准备开始填充图形a=0.4for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.08left(3) #向左转3度forward(a) #向前走a的步长else:a=a-0.08left(3)forward(a)end_fill()#填充完成penup()setheading(90)forward(25)setheading(0)forward(10)pendown()pencolor(255,155,192)#画笔颜色setheading(10)begin_fill()circle(5)color(160,82,45)#返回或设置pencolor和fillcolorend_fill()penup()setheading(0)forward(20)pendown()pencolor(255,155,192)setheading(10)begin_fill()circle(5)color(160,82,45)end_fill()def head(x,y):#头color((255,155,192),"pink")penup()goto(x,y)setheading(0)pendown()begin_fill()setheading(180)circle(300,-30)circle(100,-60)circle(80,-100)circle(150,-20)circle(60,-95)setheading(161)circle(-300,15)penup()goto(-100,100)pendown()setheading(-30)a=0.4for i in range(60):if 0<=i<30 or 60<=i<90:a=a+0.08lt(3) #向左转3度fd(a) #向前走a的步长else:a=a-0.08lt(3)fd(a)end_fill()def ears(x,y): #耳朵color((255,155,192),"pink")penup()goto(x,y)pendown()begin_fill()setheading(100)circle(-50,50)circle(-10,120)circle(-50,54)end_fill()penup()setheading(90)forward(-12)setheading(0)forward(30)pendown()begin_fill()setheading(100)circle(-50,50)circle(-10,120)circle(-50,56)end_fill()def eyes(x,y):#眼睛color((255,155,192),"white")penup()setheading(90)forward(-20)setheading(0)forward(-95)pendown()begin_fill()circle(15)end_fill()color("black")penup()setheading(90)forward(12)setheading(0)forward(-3)pendown()begin_fill()circle(3)end_fill()color((255,155,192),"white")penup()seth(90)forward(-25)seth(0)forward(40)pendown()begin_fill()circle(15)end_fill()color("black")penup()setheading(90)forward(12)setheading(0)forward(-3)pendown()begin_fill()circle(3)end_fill()def cheek(x,y):#腮color((255,155,192))penup()goto(x,y)pendown()setheading(0)begin_fill()circle(30)end_fill()def mouth(x,y): #嘴color(239,69,19)penup()goto(x,y)pendown()setheading(-80)circle(30,40)circle(40,80)def body(x,y):#身体color("red",(255,99,71))penup()goto(x,y)pendown()begin_fill()setheading(-130)circle(100,10)circle(300,30)setheading(0)forward(230)setheading(90)circle(300,30)circle(100,3)color((255,155,192),(255,100,100))setheading(-135)circle(-80,63)circle(-150,24)end_fill()def hands(x,y):#手color((255,155,192))penup()goto(x,y)pendown()setheading(-160)circle(300,15)penup()setheading(90)forward(15)setheading(0)forward(0)pendown()setheading(-10)circle(-20,90)penup()setheading(90)forward(30)setheading(0)forward(237)pendown()setheading(-20)circle(-300,15)penup()setheading(90)forward(20)setheading(0)forward(0)pendown()setheading(-170)circle(20,90)def foot(x,y):#脚pensize(10)color((240,128,128))penup()goto(x,y)pendown()setheading(-90)forward(40)setheading(-180)color("black")pensize(15)fd(20)pensize(10)color((240,128,128))penup()setheading(90)forward(40)setheading(0)forward(90)pendown()setheading(-90)forward(40)setheading(-180)color("black")pensize(15)fd(20)def tail(x,y):#尾巴pensize(4)color((255,155,192))penup()goto(x,y)pendown()seth(0)circle(70,20)circle(10,330)circle(70,30)def setting():          #参数设置pensize(4)hideturtle()        #使乌龟无形(隐藏)colormode(255)      #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内color((255,155,192),"pink")setup(840,500)speed(10)def main():setting()           #画布、画笔设置nose(-100,100)      #鼻子head(-69,167)       #头ears(0,160)         #耳朵eyes(0,140)         #眼睛cheek(80,10)        #腮mouth(-20,30)       #嘴body(-32,-8)        #身体hands(-56,-45)      #手foot(2,-177)        #脚tail(148,-155)      #尾巴done()if __name__ == '__main__':main()

九:多来爱梦

import turtle as t
# t.speed(5)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')
# 猫脸
# 先画个圆
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
# 再画个小圆
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
# 鼻子
t.pu()  # 表示将画笔抬起,也就是相当于海龟在飞行的意思。
t.home()  # 返回初始位置:home()
t.goto(0, 134)  # 将画笔移动到坐标为x,y的位置
t.pd()  # 表示将画笔落下,让海龟爬行
t.pensize(4)  # 画笔宽度,海龟的腰围
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
#
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
# 画眼圈
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.08t.lt(3)  # 向左转3度t.fd(a)  # 向前走a的步长else:a = a - 0.08t.lt(3)t.fd(a)
t.end_fill()
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.08t.lt(3)  # 向左转3度t.fd(a)  # 向前走a的步长else:a = a - 0.08t.lt(3)t.fd(a)
t.end_fill()
# 眼睛
t.pu()
t.goto(-38, 190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
# 胡子
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
# 左边的胡子
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
# 笑脸
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80, 40)
t.circle(80, 80)
t.end_fill()
t.pu()
t.home()
t.goto(-80, 70)
t.pd()
t.forward(160)
t.pu()
t.home()
t.goto(-50, 50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
# 领带
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
# 铃铛
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pensize(3)
t.right(115)
t.forward(7)
t.mainloop()

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

  1. Python库 turtlede的使用(绘制小黄人、樱花树、小猪佩奇、皮卡丘)

    最近在学习Python库turtle的用法,顺便也整理了几个用turtle库画的图形,具体如下. 一  turtle的基本操作 1. 引用 turtle库 2. 常用的基础函数 (1)绘制状态的函数 ...

  2. python中turtle的用法及实例--你的唐僧哥哥

    今天接触了一下python中的turtle库,发现它的用法挺简单的,就想着自己用代码画一个其他人没有画过的,首先给大家介绍一下这个库. turtle也叫海龟,是turtle绘图体系的python实现, ...

  3. python中MySQLdb模块用法实例

    篇文章主要介绍了python中MySQLdb模块用法,以实例形式详细讲述了MySQLdb模块针对MySQL数据库的各种常见操作方法,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了python中 ...

  4. python中random模块用法_Python中random模块用法实例分析

    本文实例讲述了Python中random模块用法.分享给大家供大家参考.具体如下: import random x = random.randint(1,4); y = random.choice([ ...

  5. pythonturtle画房子_用python的turtle模块实现给女票画个小心心

    晚上自习无聊 正好拿自己的平板电脑用python写了个小程序,运用turtle模块画一个小心心,并在心上画女票名字的首字母缩写,单纯只为红颜一笑. 代码贴出来,很简单 import turtle im ...

  6. python画图代码turtle-使用Python的turtle模块画图的方法

    简介:turtle是一个简单的绘图工具.它提供了一个海龟,你可以把它理解为一个机器人,只听得懂有限的指令. 1.在文件头写上如下行,这能让我们在语句中插入中文 #-*-coding:utf-8-*- ...

  7. Python 的turtle模块讲座

    Python 的turtle模块讲座 turtle库是Python语言中一个很流行的绘制图像的函数库,可以轻松地绘制出精美的形状和图案,很适合用来引导孩子学习编程. turtle模块(module)是 ...

  8. Python的turtle模块画爱心箭(附源码)

    Python的turtle模块画爱心箭源码 import turtle as t t.hideturtle() t.speed(100) def f(a,b):#画箭,a,b为箭尖坐标t.penup( ...

  9. chatgpt赋能python:Python绝对值符号:用法及实例

    Python绝对值符号:用法及实例 Python程序设计语言是一种高级编程语言,其语法简洁且易于学习.Python中的绝对值符号是一个非常实用的工具,可以用于任何需要获取数值大小而不需要其符号的情况. ...

最新文章

  1. oracle 11gR2 RAC 安装
  2. 10种常用降维算法源代码(python)
  3. 【小技巧】notepad++ 输入中文无响应
  4. linux按日期备份mysql,在Linux、Windows上如何按日期逻辑备份数据库
  5. 不等式约束的序列二次规划(SQP)
  6. 使用Python解压,对比文件
  7. java 反射 getClass()
  8. 对话AI一线大咖,零基础入门Python机器学习与深度学习
  9. Eclipse中去掉代码中的警告Warn
  10. vue+高德离线地图vue-amap开发
  11. 从前慢-SpringCloud
  12. win7服务器如何还原系统教程,怎么快速处理win7系统架设本地服务器的还原技巧...
  13. 使用pdf.js把PDF文件转图片
  14. spring中的注解和xml配置文件中配置对应总结
  15. 深信服2018春季招聘-研发卷编程题 - 题解
  16. 计蒜客 T1817 分解质因数(数论)
  17. 深度学习优化函数详解(5)-- Nesterov accelerated gradient (NAG)
  18. c语言追光篮球程序,追光篮球游戏下载-追光篮球苹果版v1.0_6137游戏网
  19. chrome inspect联调android手机webview和web h5遇坑
  20. 微软 workflow 工作流总结

热门文章

  1. Word、Excel、PPT转PDF,dwg转svg或png
  2. 免费OpenStack私有云-Rackspace Private Cloud(01) 简介
  3. php如何获取百度快照,php获取某网站的百度快照日期
  4. Siebel界面搭建
  5. 为何要使用一物一码防伪系统
  6. 测试不能隶属开发部门
  7. Maven打包错误:Failed to execute goal on project client: Could not resolve dependencies for project
  8. devDept Eyeshot Fem 2022.2 Crack
  9. UDS protocol - 周期报文 periodical message 多字节通信 multi-byte message
  10. Java堆转储Dump文件的几种方法,java高级程序员面试笔试