这个代码主要有两个部分,第一部分是画出故宫,第二部分是用random函数随机画心,故宫部分设置多个函数和循环再进行颜色填充即可完成。

此处为视频链接

from turtle import*
import random as r speed(0.4) def xy(x,y):
fd(x)
left(90)
fd(y)
left(90)
fd(x)
left(90)
fd(y)
left(90) colormode(255)
setup(900,900)
penup()
goto(-300,-250)
pensize(1)
pendown() begin_fill()
fillcolor(220,220,220)
xy(250,45)
fd(350)
xy(250,45)
end_fill() goto(-50,-250)
begin_fill()
fillcolor(211,77,80)
color(211,77,80)
xy(100,35)
end_fill() def little():
for i in range(9):
xy(12.5,7.5)
penup()
fd(25)
pendown()
penup()
goto(-275,-220)
pendown()
begin_fill()
fillcolor(211,77,80)
little()
penup()
forward(125)
pendown()
little()
end_fill() def zhuzhi():
for i in range(3):
xy(12.5,75)
penup()
fd(87.5)
pendown()
penup()
goto(-275,-205)
pendown()
begin_fill()
fillcolor(211,77,80)
zhuzhi()
fd(90)
zhuzhi()
end_fill() def cube():
for i in range(3):
for j in range(4):
fd(12.5)
left(90)
penup()
fd(87.5)
pendown() penup()
goto(-275,-160)
pendown()
begin_fill()
fillcolor(228,190,82)
cube()
fd(90)
cube()
end_fill() def fill():
for i in range(2):
begin_fill()
fillcolor(156,2,2)
xy(75,58)
end_fill()
penup()
fd(87.5)
pendown() penup()
goto(-262.5,-206)
pendown()
fill()
fd(176.5)
fill() penup()
goto(-87,-206)
pendown()
color(156,2,2)
begin_fill()
fillcolor(156,2,2)
fd(37)
right(90)
fd(10)
left(90)
fd(100)
left(90)
fd(10)
right(90)
fd(27)
left(90)
fd(58)
left(90)
fd(164)
left(90)
fd(58)
left(90)
end_fill() def huise():
for i in range(2):
xy(75,17.6)
penup()
fd(87.5)
pendown()
pencolor(177,172,137)
penup()
goto(-262.5,-148)
pendown()
begin_fill()
fillcolor(177,172,137)
huise()
fd(176.9)
huise()
goto(-87,-148)
xy(164,17.6)
end_fill() penup()
goto(-293,-130)
pendown()
color(65,66,77)
begin_fill()
fillcolor(65,66,77)
fd(570)
seth(45)
fd(20)
seth(180)
fd(590)
seth(-45)
fd(20)
seth(0)
end_fill() penup()
goto(-310,-115)
pendown()
pencolor(220,157,72)
begin_fill()
fillcolor(220,157,72)
fd(610)
circle(5,180)
fd(610)
circle(5,180)
end_fill() penup()
goto(-280,-104)
pendown()
pencolor(251,194,4)
begin_fill()
fillcolor(251,194,4)
fd(570)
seth(150)
fd(48)
seth(180)
fd(510)
seth(-150)
fd(48)
seth(0)
end_fill() goto(-264,-80)
pencolor(65,66,67)
begin_fill()
fillcolor(65,66,67)
xy(510,8)
end_fill()
penup()
goto(-248,-72)
pendown()
def heise():
for i in range(7):
xy(8,20)
penup()
fd(79)
pendown()
begin_fill()
fillcolor(65,66,67)
heise()
end_fill() penup()
goto(-264,-52)
pendown()
begin_fill()
fillcolor(65,66,67)
fd(510)
seth(45)
fd(20)
seth(180)
fd(536)
seth(-45)
fd(20)
seth(0)
end_fill() penup()
goto(-240,-72)
pendown()
def huise1():
for i in range(6):
xy(71,20)
penup()
fd(79)
pendown()
begin_fill()
fillcolor(177,172,137)
huise1()
end_fill() penup()
goto(-15,-80)
pendown()
begin_fill()
fillcolor(218,153,66)
xy(30,42)
end_fill() penup()
goto(-10,-73)
pendown()
begin_fill()
fillcolor(42,6,194)
xy(20,28)
end_fill() penup()
goto(-285,-38)
pendown()
begin_fill()
fillcolor(220,157,72)
fd(560)
circle(5,180)
fd(560)
circle(5,180)
end_fill() penup()
goto(-195,-28)
pendown()
begin_fill()
fillcolor(251,194,4)
fd(458)
seth(135)
fd(70)
seth(180)
fd(438)
seth(-135)
fd(70)
seth(0)
end_fill() penup()
goto(-220,21)
pendown()
begin_fill()
fillcolor(220,157,72)
fd(435)
seth(90)
fd(20)
circle(5,180)
fd(6)
seth(180)
fd(417)
seth(90)
fd(6)
circle(5,180)
fd(20)
end_fill() colormode(1.0) def randomcolor():
color = (r.random(), r.random(), r.random())
return color def pink():
color = (1, r.random(), 1)
return color def randomrange(min, max):
return r.randint(min,max) def heart(r, a):
factor = 180
seth(a)
circle(-r, factor)
fd(2 * r)
right(90)
fd(2 * r)
circle(-r, factor) pensize(1)
pencolor(randomcolor())
fillcolor(randomcolor()) penup()
for i in range(20):
goto(randomrange(-400, 400), randomrange(140, 420))
begin_fill()
fillcolor(pink())
heart(randomrange(10, 50), randomrange(-10, 90))
end_fill() done()

使用turtle画故宫(伍奇,侯俊豪小组)的更多相关文章

  1. python运用turtle 画出汉诺塔搬运过程

    python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...

  2. python3 turtle 画国际象棋棋盘

    python3 turtle 画国际象棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import turt ...

  3. day 03 turtle 画鹅

    turtle 画鹅 import turtle t=turtle turtle.speed(10) t. setup(800,600) #画头 turtle.penup() turtle.goto(0 ...

  4. *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

    如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...

  5. 【Python】【demo实验29】【练习实例】【使用turtle画五角星】

    原题: 使用turtle画五角星: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- from turtle impor ...

  6. 用python turtle画玫瑰

    1.turtle 库 2.画玫瑰的代码: import turtle turtle.penup() turtle.left() turtle.fd() turtle.pendown() turtle. ...

  7. Python之turtle画同心圆和棋盘

    画饼图 import turtle t = turtle.Pen() for i in range(5): t.penup() t.goto(0, -i*30) t.pendown() t.circl ...

  8. 用python的turtle画分形树

    由于分形树具有对称性,自相似性,所以我们可以用递归来完成绘制.只要确定开始树枝长.每层树枝的减短长度和树枝分叉的角度,我们就可以把分形树画出来啦!! 代码如下: # -*- coding: utf-8 ...

  9. python 用turtle 画小猪佩奇

    from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟 ...

随机推荐

  1. 移动质量(MQ)测试系列

    移动质量(MQ)测试 向移动开发者提供专业.稳定.全面.高价值的自动化测试平台. 发现 APP 中的各类隐患,包括 APP 崩溃.各类兼容性.功能性.性能问题等等. MQ 的 5 大功能(兼容性测试. ...

  2. /etc/security/limits.conf不生效

    总结下来发现要使limits.conf生效,需要在  /etc/ssh/sshd_config  配置中 设置 UsePAM  yes UseLogin yes    #这个保证其他的用户也能修改设置 ...

  3. 【VS2019】F12跳转到源码

    1.工具->选项 2.文本编辑器->C#->高级->勾选支持导航到反编译源码 3.关闭浏览器不停止项目

  4. 实现img图片不能被拖动的两种简单方法

    1,在img标签中添加属性 draggable="false" 2,通过css样式设置 img { -webkit-user-drag: none; }

  5. Python3爬虫相关软件,库的安装

    Anaconda 百度搜Anaconda清华,根据环境选择版本下载 安装时记得勾选添加到环境变量,不要还要手动添加 Anaconda Navigator可视化界面,可以方便地调用Jupyter等工具. ...

  6. 用JavaScript比较两个数组是否相等

    JS怎么比较两个数组是否有完全相同的元素?Javascript不能直接用==或者===来判断两个数组是否相等,无论是相等还是全等都不行,以下两行JS代码都会返回false alert([0,0,0]= ...

  7. Asp.net core Identity + identity server + angular 学习笔记 (第四篇)

    来说说 RBAC (role based access control) 这是目前全世界最通用的权限管理机制, 当然使用率高并不是说它最好. 它也有很多局限的. 我们来讲讲最简单的 role base ...

  8. 登录获取token,token参数关联至所有请求的请求体内

    问题描述: 有些系统接口判断用户是否登录,是校验登录接口成功后传的token值,也就是请求系统所有接口时,前端传参必带登录成功后接口返回的token,后台以此检验是否过期或是否有登录.所有接口都依赖登 ...

  9. Git基本命令整理

    git help <command> # 显示command的help git show # 显示某次提交的内容 git show $id git co -- <file> # ...

  10. AndroidStudio中导入jar包的方法

    1.首先去下载需要的jar包 2.将jar包复制到project下的app->libs目录下(如果不存在libs目录新建一个) 3.右击该jar包,选择add as library,弹出窗口,点 ...