python四瓣花图形_python绘制樱花,彩虹旋等
1.樱花树
效果:图一 樱花树
代码:
import turtle
import random
from turtle import *
from time import sleep
# 画樱花的躯干(60,t)
def tree(branchLen,t):
sleep(0.0005)
if branchLen >3:
if 8<= branchLen <=12:
if random.randint(0,2) == 0:
t.color('snow') # 白
else:
t.color('lightcoral') # 淡珊瑚色
t.pensize(branchLen / 3)
elif branchLen <8:
if random.randint(0,1) == 0:
t.color('snow')
else:
t.color('lightcoral') # 淡珊瑚色
t.pensize(branchLen / 2)
else:
t.color('sienna') # 赭(zhě)色
t.pensize(branchLen / 10) # 6
t.forward(branchLen)
a = 1.5 * random.random()
t.right(20*a)
b = 1.5 * random.random()
tree(branchLen-10*b, t)
t.left(40*a)
tree(branchLen-10*b, t)
t.right(20*a)
t.up()
t.backward(branchLen)
t.down()
# 掉落的花瓣
def petal(m, t):
for i in range(m):
a = 200 - 400 * random.random()
b = 10 - 20 * random.random()
t.up()
t.forward(b)
t.left(90)
t.forward(a)
t.down()
t.color('lightcoral') # 淡珊瑚色
t.circle(1)
t.up()
t.backward(a)
t.right(90)
t.backward(b)
def main():
# 绘图区域
t = turtle.Turtle()
# 画布大小
w = turtle.Screen()
t.hideturtle() # 隐藏画笔
getscreen().tracer(5,0)
w.screensize(bg='wheat') # wheat小麦
t.left(90)
t.up()
t.backward(150)
t.down()
t.color('sienna')
# 画樱花的躯干
tree(60,t)
# 掉落的花瓣
petal(200, t)
w.exitonclick()
main()
2.彩虹
效果:图二 彩虹旋
代码:
import turtle
q = turtle.Pen()
turtle.bgcolor("black")
sides = 7
colors =["red","yellow",
"green","cyan","red","blue","purple"]
for x in range(360):
q.pencolor(colors[x%sides])
q.forward(x*3/sides+x)
q.left(360/sides+1)
q.width(x*sides/200)
3.玫瑰
效果:图三 玫瑰
代码:
import turtle
# 设置初始位置
turtle.penup(); turtle.left(90); turtle.fd(200);
turtle.pendown(); turtle.right(90); turtle.pensize(5); turtle.speed(10);
# 花蕊
turtle.fillcolor("red"); turtle.begin_fill();
turtle.circle(10,180); turtle.circle(25,110); turtle.left(50);
turtle.circle(60,45); turtle.circle(20,170);
turtle.right(24); turtle.fd(30); turtle.left(10);
turtle.circle(30,110); turtle.fd(20); turtle.left(40);
turtle.circle(90,70); turtle.circle(30,150);turtle.right(30);
turtle.fd(15); turtle.circle(80,90); turtle.left(15);
turtle.fd(45); turtle.right(165); turtle.fd(20);
turtle.left(155); turtle.circle(150,80); turtle.left(50);
turtle.circle(150,90); turtle.end_fill();
# 花瓣1
turtle.left(150); turtle.circle(-90,70); turtle.left(20);turtle.circle(75,105);
turtle.setheading(60); turtle.circle(80,98); turtle.circle(-90,40);
# 花瓣2
turtle.left(180); turtle.circle(90,40);
turtle.circle(-80,98); turtle.setheading(-83);
# 叶子1
turtle.fd(30); turtle.left(90); turtle.fd(25); turtle.left(45);
turtle.fillcolor("blue"); turtle.begin_fill(); turtle.circle(-80,90);
turtle.right(90); turtle.circle(-80,90); turtle.end_fill(); turtle.right(135);
turtle.left(180); turtle.fd(25); turtle.left(90); turtle.fd(80);
# 叶子2
turtle.right(90); turtle.right(45); turtle.fillcolor("cyan");
turtle.begin_fill(); turtle.circle(80,90); turtle.left(90);
turtle.circle(80,90); turtle.end_fill(); turtle.left(135);
turtle.left(180); turtle.right(90); turtle.circle(200,60);
4.钟表
效果:图四 黎明的钟
代码:
from turtle import *
from datetime import *
import time
def SetupClock(radius):
#建立表的外框
reset()
pensize()
for i in range(60):
Skip(radius)
if i % 5 == 0:
forward(20)
Skip(-radius-20)
else:
dot(5)
Skip(-radius)
right(6)
def Skip(step):
penup()
forward(step)
pendown()
#定义表针函数mkHand()
def mkHand(name, length):
#注册Turtle形状,建立表针Turtle
reset()
Skip(-length*0.1)
begin_poly()
forward(length*1.1)
end_poly()
handForm = get_poly()
register_shape(name, handForm)
def Init():
global secHand, minHand, hurHand, printer
mode("logo") # 重置Turtle指向北
#建立三个表针Turtle并初始化
mkHand("secHand", 125)
mkHand("minHand", 130)
mkHand("hurHand", 90)
secHand = Turtle()
secHand.shape("secHand")
minHand = Turtle()
minHand.shape("secHand")
hurHand = Turtle()
hurHand.shape("secHand")
for hand in secHand, minHand, hurHand:
hand.shapesize(1, 1, 3)
hand.speed(0)
#建立输出文字Turtle
printer = Turtle()
printer.hideturtle()
printer.penup()
def get_week_day():
week_day_dict = {
0 : '星期一',
1 : '星期二',
2 : '星期三',
3 : '星期四',
4 : '星期五',
5 : '星期六',
6 : '星期天',
}
today = int(time.strftime("%w"))
return week_day_dict[today]
#更新时钟函数Tick()
def Tick():
#绘制表针的动态显示
t = datetime.today()
second = t.second + t.microsecond*0.000001
minute = t.minute + second/60.0
hour = t.hour + minute/60.0
tracer(False)
printer.forward(65)
# print(get_week_day())
printer.write(get_week_day(), align="center", font=("Courier", 14, "bold"))
printer.back(130)
printer.write((str(t.year)+"-"+str(t.month)+"-"+str(t.day)), align="center", font=("Courier", 14, "bold"))
printer.home()
tracer(True)
secHand.setheading(6*second)
minHand.setheading(6*minute)
hurHand.setheading(30*hour)
ontimer(Tick, 100) #100ms后继续调用tick
def main():
tracer(False)
Init()
SetupClock(160)
tracer(True)
Tick()
mainloop()
if __name__ == '__main__':
main()
5.穿雨鞋的小鸭子
效果:图五 穿雨鞋的小鸭子
代码:
from turtle import *
#扁嘴
pensize(2)
pu()
goto(-100,100)#上嘴最高顶点
seth(-50)
pd()
color('#6C3100','#FADD77')
begin_fill()
fd(16)
vertex_right = pos()#嘴最右顶点
rt(50)
fd(12)
vertex_down = pos()#下嘴最低顶点
rt(80)
fd(30)
circle(-3,200)
vertex_left = pos()#嘴最左顶点
goto(-100,100)
end_fill()
goto(vertex_left)#回到最左顶点
circle(-3,-200)#扁嘴
goto(vertex_right)
#身体
#头颈背尾曲线
color('#B6A88E')
pu()
goto(-100,100)
pd()
seth(80)
circle(-36,160)
fd(25)
circle(115,20)
circle(60,55)
circle(-200,20)
circle(110,20)
color('#7D6A4C')
circle(40,40)
color('#B6A88E')
seth(-100)
circle(-180,30)
circle(-20,50)
#右鸭腿
circle(20,70)
color('#736856')
circle(-12,120)
leg_pos1 = pos()#定位左腿位置
fd(25)
#前胸肚曲线
pu()
goto(vertex_down)
pd()
seth(-10)
color('#B9AD9D')
circle(-40,50)
circle(-80,48)
color('#736856')
circle(250,5)
circle(50,75)
color('#B9AD9D')
circle(220,28)
#左鸭腿
pu()
seth(175)
fd(40)
pd()
seth(-120)
fd(8)
circle(-10,120)
leg_pos2 = pos()#定位右腿位置
fd(15)
#眼睛
color('black')
#左眼
pu()
goto(vertex_down - (1,-29))
pd()
dot(4,'black')#相比circle(),不需要再额外填充颜色
#右眼
pu()
goto(vertex_down + (23,20))
pd()
dot(4,'black')
#翅膀
color('#BCB2A6')
pu()
goto(vertex_down - (-75,130))
seth(130)
pd()
circle(-25,130)
circle(-100,30)
fd(85)
point = pos()
rt(137)
fd(52)
circle(-100,58)
pu()
goto(point)
lt(30)
pd()
fd(60)
pu()
goto(point)
pd()
lt(10)
fd(70)
#腿部
#左腿
def leg(pos0):#鸭腿绘制函数
pensize(8)
color('#ECC578')
pu()
goto(pos0)
seth(0)
fd(7)
seth(-90)
fd(8.5)
pd()
fd(20)#腿长
leg(leg_pos1)
leg(leg_pos2)
#小红靴——函数
def boot(pos0):
pensize(2)
color('#B4070B','#FBA06B')
pu()
goto(pos0)#靴子右上顶点
pd()
begin_fill()
seth(140)
circle(25,80)
seth(-80)
fd(35)#fd(30)左侧线条
circle(-2,60)#靴低
fd(20)
circle(4,180)
seth(5)
fd(30)
circle(2,60)
goto(pos0)#右侧线条
end_fill()
boot(leg_pos1-(-20,30))
boot(leg_pos2-(-20,30))
#小雨滴
color('#77DDFF','#D8E8E5')
fd_ls = [200,140,250,240,230,220,180,250]
lt_ls = [30,60,60,100,125,170,200,330]
for i in range(8):
pu()
home()
lt(lt_ls[i])
fd(fd_ls[i])
pd()
seth(-78)
fd(15)
begin_fill()
circle(-3,200)
end_fill()
fd(15)
#文字
pu()
goto(vertex_left)
seth(180)
fd(150)
seth(-90)
fd(300)
color('black')
write('code by totoup',font=("Arial",15,"normal"))
hideturtle()
done()
6.骷髅头
效果:图六 骷髅头
代码:
import turtle as t
#黄底帽子
t.pu()
t.goto(0,200)
t.circle(-130,-80)
t.pd()
t.colormode(255)
t.pensize(5)
t.color(242,232,184) #帽子黄底RGB
t.begin_fill()
t.pencolor(0,0,0)
t.circle(-130,160)
t.seth(180)
t.fd(255)
t.end_fill()
#红色线条
t.begin_fill()
t.color(221,65,43) #帽子红色带
t.pencolor(0,0,0)
t.seth(80)
t.circle(-130,19)
t.seth(0)
t.fd(225)
t.seth(-59)
t.circle(-130,19)
t.seth(180)
t.fd(255)
t.end_fill()
#帽檐
t.begin_fill()
t.color(242,232,184)
t.pencolor(0,0,0)
t.fd(60)
t.circle(12,180)
t.fd(375)
t.circle(12,180)
t.fd(255 + 60)
t.end_fill()
#脸部下半轮廓
t.pu()
t.setpos(0,-30)
t.seth(-180)
t.circle(-130,-75)
t.pd()
t.circle(-130,150)
#眼睛鼻子
t.pu()
t.color(33,24,24) #眼睛、鼻子RGB
t.setpos(-45,64)
t.seth(-180)
t.pd()
t.begin_fill()
t.circle(33)
t.pu()
t.setpos(45,64)
t.pd()
t.circle(33)
t.end_fill()
t.pu()
t.setpos(0,5)
t.pd()
t.begin_fill()
t.circle(8)
t.end_fill()
#下巴
t.pencolor(0,0,0)
t.pu()
t.setpos(0,0)
t.seth(0)
t.circle(-75,45)
t.pd()
t.circle(-75,270)
#牙齿
t.pu()
t.setpos(0,120)
t.seth(0)
t.circle(-105,136)
t.pd()
t.circle(-105,86)
t.pu()
t.seth(0)
t.goto(0,200)
t.circle(-130,150)
t.pd()
t.circle(-130,60)
t.pu() #牙齿三根竖线
t.setpos(-30,-27)
t.seth(260)
t.pd()
t.fd(52)
t.pu()
t.setpos(30,-27)
t.pd()
t.seth(-260)
t.fd(-52)
t.pu()
t.setpos(0,-30)
t.seth(-90)
t.pd()
t.fd(56)
#上排右侧小爪爪
#释放注释为:上排右侧小爪爪实心金方案
t.pu()
#t.color(255,215,0) #金色的RGB
t.pencolor(0,0,0)
t.setpos(110,145)
t.seth(45)
t.pd()
#t.begin_fill()
t.fd(40)
t.seth(135)
t.circle(-30,235)
t.seth(-20)
t.circle(-30,220)
t.seth(-135)
t.fd(40)
#t.end_fill()
#上排左侧小爪爪
t.pu()
t.pencolor(0,0,0)
t.setpos(-110,145)
t.seth(135)
t.pd()
t.fd(40)
t.seth(45)
t.circle(30,235)
t.seth(-160)
t.circle(30,220)
t.seth(-45)
t.fd(40)
#下排右侧小爪爪
t.pu()
t.setpos(70,-10)
t.seth(-45)
t.pd()
t.fd(70)
t.seth(45)
t.circle(-30,235)
t.seth(-70)
t.circle(-30,255)
t.seth(135)
t.fd(22)
#下排左侧小爪爪
t.pu()
t.setpos(-70,-10)
t.seth(-135)
t.pd()
t.fd(70)
t.seth(135)
t.circle(30,235)
t.seth(-110)
t.circle(30,255)
t.seth(45)
t.fd(22)
7.奥运五环
效果:图七 五环
代码:
import turtle
p = turtle
p.pensize(3)
p.color("blue")
p.circle(30,360)
p.pu()
p.goto(60,0)
p.pd()
p.color("black")
p.circle(30,360)
p.pu()
p.goto(120,0)
p.pd()
p.color("red")
p.circle(30,360)
p.pu()
p.goto(90,-30)
p.pd()
p.color("green")
p.circle(30,360)
p.pu()
p.goto(30,-30)
p.pd()
p.color("yellow")
p.circle(30.360)
p.done()
python四瓣花图形_python绘制樱花,彩虹旋等相关推荐
- python turtle画彩虹-python绘制樱花,彩虹旋等
1.樱花树 效果:图一 樱花树 代码: import turtle import random from turtle import * from time import sleep # 画樱花的躯干 ...
- python四瓣花图形_Python竟能画这么漂亮的花,帅呆了(代码分享)
阅读本文大概需要3分钟 关于函数和模块讲了这么久,我一直想用一个好玩有趣的小例子来总结一下,同时也作为实战练习一下. 趣味编程其实是最好的学习途径,回想十几年前我刚毕业的时候,第一份工作就给手机上写a ...
- Python基本图形的绘制
Python基本图形的绘制 曲线图- 画出 y=x2+2x+1y=x2+2x+1 在区间[-5,3]的函数图像. 折线图-在同一张图中创建两个子图,分别画出sinx和cosx在[-3.14,3.14] ...
- python奥运五环_Python绘制奥运五环
绘制奥运五环主要涉及到Python中的turtle绘图库运用: turtle.forward(distance) 向当前画笔方向移动distance像素长度 turtle.backward(dista ...
- python桌面图形_Python桌面图形程序美化的方法论
很多人都吐槽,使用 Tkinter.PyQt5等工具制作出来的图形界面程序太丑了.既然觉得它丑,我们来想想,它为什么会那么丑. 功能性是开发的第一要务 每一个 Python 图形界面库都有它自有的功能 ...
- python绘制简单彩虹图_python绘制简单彩虹图
本文实例为大家分享了python绘制彩虹图的具体代码,供大家参考,具体内容如下 代码: from turtle import * #控制彩虹路径 def path(pen, r, g, b): pen ...
- python绘制分形图形_Python绘制L-System的分形图
Python绘制L-System的分形图代码及解析. 完整代码如下 # -*- coding: utf-8 -*- #L-System(Lindenmayer system)是一种用字符串替代产生分形 ...
- python turtle画彩虹简单_python绘制简单彩虹图
本文实例为大家分享了python绘制彩虹图的具体代码,供大家参考,具体内容如下 代码: from turtle import * #控制彩虹路径 def path(pen, r, g, b): pen ...
- 用python绘制图形_python绘制图形
1 ''' 2 File Name: draw3 Author: tim4 Date: 2018/8/15 16:475 Description: 图形绘制.十分有用,对于工作中实验性的项目,可以快速 ...
最新文章
- mysql数据库之linux版本
- 使用postman测试oauth2.0认证服务中出现OAuth出现Bad credentials
- 音视频技术开发周刊 | 199
- eclipse控制台自动换行不分割单词_这 7 个实用的文档技巧,不掌握就太可惜了...
- 7月发布?华为李昌竹确认Mate 50系列:会来的但不是现在
- 冷门的linux设备,你可能不知道的6个冷门linux实用命令
- 将Notepad++配置为Python编译器
- js 数组 实现 完全树_Flink实例(六十八):布隆过滤器(Bloom Filter)的原理和实现 - 秋华...
- mysql5.7.20新特_Mysql5.7新特性
- java连接数据库的基本操作
- linux定位到文件,locate 在linux下快速定位文档
- 怎么调用新建模型里文章的内容_读完这篇文章,再难的建筑模型你都能快速上手...
- indexOf(String.indexOf 方法)
- 全国省市区(县)级地名xml(一)
- JPG图像太大怎么免费压缩
- 前端程序员福利 利用node写接口
- 最简解决方案--安装ubuntu 遇到32位 EFI(UEFI) /EFI/BOOT/bootia32.efi unavilable
- iText7解套(二)中文行首行末标点符号处理
- 服务器系统都有哪些?
- 使用setoolkit克隆钓鱼网站时修改网页错误的解决方法