python简单的画图代码爱心(用python画一个爱心的代码)
python简单的画图代码爱心(用python画一个爱心的代码),新营销网红网本栏目通过数据整理汇集了python简单的画图代码爱心(用python画一个爱心的代码)相关信息,下面一起看看。
龟画一个彩色螺旋图形进口turtleturtle.shape(乌龟)龟.速(9) #画笔速度turtle.pensize(2) #画笔的宽度turtle.bgcolor(black) #画布背景色colors=[红色,黄色,绿色,蓝色] #定义画笔线色对于范围(255): #内的英语字母表中第九个字母循环一次画一条线turtle.forward(2 i) #向当前方向前进n像素turtle.color(colors[i % 4]) #根据求余调整画笔线色turtle.left(91) #向左旋转91度turtle.done()
仙人球导入乌龟乌龟。形(龟)龟。彩色(橙色,绿色)乌龟。begin _ fill()while true :海龟。前进(200)龟。左(170)如果ABS(海龟。pos())1:破龟。end _ fill()乌龟。完成()
国旗进口龟鳖。形(龟)龟。屏幕尺寸(2000,2000,白色)#设置画布大小龟速(9)#绘制旗面乌龟。钢笔颜色(红色)# pu()乌龟。goto(-300,-200)乌龟。PD()龟。填充颜色(红色)乌龟。范围(0,2): turtle中I的begin _ fill()。FD(600)龟。lt(90)龟。FD(400)龟。lt(90)龟。end _ fill()#绘制大五角星乌龟。溥()龟。笔色(黄色)乌龟。goto(-260,120)龟。PD()龟。填色(黄色)乌龟。范围(0,5):turtle.fd(113.137)中I的begin _ fill()大星一划的边长乌龟。rt(144)龟。end _ fill()#绘制四个小五角星list1=[(-100,160),(-60,120),(-60,60),(-100,20)] #四个五角星的中心坐标list2=[31.98,8.13,-15.59,-38.66] #相对角度0的后退1.111需要左转的角度对于范围(0,4):中的英语字母表中第十个字母这是角度为0乌龟。溥()龟。goto(list 1[j])#定位到五角星中心turtle.lt(list2[j]) #旋转角度,以背向指向大五角星的角尖乌龟.bk(20) #从五角星中心到指向大五角星的角尖(龟倒着爬)退一个小圆半径turtle.lt(18) #五角星的半角角度乌龟。PD()龟。范围(0,5):turtle.fd(113.137/3)中I的begin _ fill()小星一划的边长乌龟。rt(144)龟。end _ fill()乌龟。溥()龟。ht()龟。完成()
玫瑰花进口海龟进口时间海龟。形(龟)龟。速度(5)#设置初始位置乌龟。penup()海龟。左(90)龟。FD(200)龟。pendown()海龟。右(90)#花蕊乌龟。填充颜色(红色)乌龟。begin _ fill()乌龟。圆(10,180)龟圆(25,110)龟。左(50)龟。圆(60,45)龟圆(20,170)龟。右(24)龟。FD(30)龟。左(30,110)龟。FD(20)龟。左(40)龟。圆(90,70)海龟。圆(30)花瓣1只乌龟。左(150)龟。圆(-90,70)龟。左(20)龟。圆(75,105)龟。setheading(60)海龟。圆(80,98)龟.圆(-90,40)#花瓣注射毒品图数字一(one)
eft(180)turtle.circle(90,40)turtle.circle(-80,98)turtle.setheading(-83)# 叶子1turtle.fd(30)turtle.left(90)turtle.fd(25)turtle.left(45)turtle.fillcolor("green")turtle.begin_fill()turtle.circle(-80,90)turtle.right(90)turtle.circle(-80,90)turtle.end_fill()turtle.right(135)turtle.fd(60)turtle.left(180)turtle.fd(85)turtle.left(90)turtle.fd(80)# 叶子2turtle.right(90)turtle.right(45)turtle.fillcolor("green")turtle.begin_fill()turtle.circle(80,90)turtle.left(90)turtle.circle(80,90)turtle.end_fill()turtle.left(135)turtle.fd(60)turtle.left(180)turtle.fd(60)turtle.right(90)turtle.circle(200,60)turtle.done()
彩色树import turtleturtle.shape(turtle)# 设置色彩模式是RGB:turtle.colormode(255)turtle.lt(90)lv = 14l = 120s = 45turtle.width(lv)# 初始化RGB颜色:r = 0g = 0b = 0turtle.pencolor(r, g, b)turtle.penup()turtle.bk(l)turtle.pendown()turtle.fd(l)def draw_tree(l, level):global r, g, b# save the current pen widthw = turtle.width()# narrow the pen widthturtle.width(w 3.0 / 4.0)# set color:r = r + 1g = g + 2b = b + 3turtle.pencolor(r % 200, g % 200, b % 200)l = 3.0 / 4.0 lturtle.lt(s)turtle.fd(l)if level lv:draw_tree(l, level + 1)turtle.bk(l)turtle.rt(2 s)turtle.fd(l)if level lv:draw_tree(l, level + 1)turtle.bk(l)turtle.lt(s)# restore the previous pen widthturtle.width(w)turtle.speed("fastest")draw_tree(l, 4)turtle.done()
随机樱花树# 每次运行 树的形状是随机的import turtle as Timport randomimport time# 画樱花的躯干(60,t)def Tree(branch, t):time.sleep(0.0005)if branch 3:if 8 = branch = 12:if random.randint(0, 2) == 0:t.color(snow) # 白else:t.color(lightcoral) # 淡珊瑚色t.pensize(branch / 3)elif branch 8:if random.randint(0, 1) == 0:t.color(snow)else:t.color(lightcoral) # 淡珊瑚色t.pensize(branch / 2)else:t.color(sienna) # 赭(zhě)色t.pensize(branch / 10) # 6t.forward(branch)a = 1.5 random.random()t.right(20 a)b = 1.5 random.random()Tree(branch - 10 b, t)t.left(40 a)Tree(branch - 10 b, t)t.right(20 a)t.up()t.backward(branch)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)# 绘图区域t = T.Turtle()# 画布大小w = T.Screen()t.shape(turtle)# t.hideturtle() # 隐藏画笔t.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()T.done()
爱情树import randomimport turtledef love(x, y): # 在(x,y)处画爱心lalalalv = turtle.Turtle()lv.hideturtle()lv.up()lv.goto(x, y) # 定位到(x,y)def curvemove(): # 画圆弧for i in range(20):lv.right(10)lv.forward(2)lv.color(red, pink)lv.speed(0)lv.pensize(1)# 开始画爱心lalalalv.down()lv.begin_fill()lv.left(140)lv.forward(22)curvemove()lv.left(120)curvemove()lv.forward(22)lv.write("{}".format("I Love You!"), font=("Arial", 10, "normal"), align="center")lv.left(140) # 画完复位lv.end_fill()def tree(branchLen, t):if branchLen 5: # 剩余树枝太少要结束递归if branchLen 20: # 如果树枝剩余长度较短则变绿t.color("green")t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))t.down()t.forward(branchLen)love(t.xcor(), t.ycor()) # 传输现在turtle的坐标t.up()t.backward(branchLen)t.color("brown")returnt.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))t.down()t.forward(branchLen)# 以下递归ang = random.uniform(15, 45)t.right(ang)tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度t.left(2 ang)tree(branchLen - random.uniform(12, 16), t) # 随机决定减小长度t.right(ang)t.up()t.backward(branchLen)def Fonts():t.penup()t.goto(-300, -300)t.pencolor(red)t.write("我爱你!^_^", font=(方正行黑简体, 30, normal))myWin = turtle.Screen()t = turtle.Turtle()t.hideturtle()t.speed(0)t.left(90)t.up()t.backward(200)t.down()t.color("brown")t.pensize(32)t.forward(60)tree(100, t)Fonts()myWin.exitonclick()
哆啦A梦import turtledef flyTo(x, y):turtle.penup()turtle.goto(x, y)turtle.pendown()def drawEye():turtle.tracer(False)a = 2.5for i in range(120):if 0 = i 30 or 60 = i 90:a -= 0.05else:a += 0.05turtle.left(3)turtle.fd(a)turtle.tracer(True)def beard():""" 画胡子, 一共六根"""# 左边第一根胡子flyTo(-37, 135)turtle.seth(165)turtle.fd(60)# 左边第二根胡子flyTo(-37, 125)turtle.seth(180)turtle.fd(60)# 左边第三根胡子flyTo(-37, 115)turtle.seth(193)turtle.fd(60)# 右边第一根胡子flyTo(37, 135)turtle.seth(15)turtle.fd(60)# 右边第二根胡子flyTo(37, 125)turtle.seth(0)turtle.fd(60)# 右边第三根胡子flyTo(37, 115)turtle.seth(-13)turtle.fd(60)def drawRedScarf():""" 画围巾"""turtle.fillcolor("red") # 填充颜色turtle.begin_fill()turtle.seth(0) # 朝向右turtle.fd(200) # 前进10个单位turtle.circle(-5, 90)turtle.fd(10)turtle.circle(-5, 90)turtle.fd(207)turtle.circle(-5, 90)turtle.fd(10)turtle.circle(-5, 90)turtle.end_fill()def drawMouse():flyTo(5, 148)turtle.seth(270)turtle.fd(100)turtle.seth(0)turtle.circle(120, 50)turtle.seth(230)turtle.circle(-120, 100)def drawRedNose():flyTo(-10, 158)turtle.fillcolor("red") # 填充颜色turtle.begin_fill()turtle.circle(20)turtle.end_fill()def drawBlackdrawEye():turtle.seth(0)flyTo(-20, 195)turtle.fillcolor("#000000") # 填充颜色turtle.begin_fill()turtle.circle(13)turtle.end_fill()turtle.pensize(6)flyTo(20, 205)turtle.seth(75)turtle.circle(-10, 150)turtle.pensize(3)flyTo(-17, 200)turtle.seth(0)turtle.fillcolor("#ffffff")turtle.begin_fill()turtle.circle(5)turtle.end_fill()flyTo(0, 0)def drawFace():turtle.forward(183) # 前行183个单位turtle.fillcolor("white") # 填充颜色为白色turtle.begin_fill() # 开始填充turtle.left(45) # 左转45度turtle.circle(120, 100) # 右边那半边脸turtle.seth(90) # 朝向向上drawEye() # 画右眼睛turtle.seth(180) # 朝向左turtle.penup() # 抬笔turtle.fd(60) # 前行60turtle.pendown() # 落笔turtle.seth(90) # 朝向上drawEye() # 画左眼睛turtle.penup() # 抬笔turtle.seth(180) # 朝向左turtle.fd(64) # 前进64turtle.pendown() # 落笔turtle.seth(215) # 修改朝向turtle.circle(120, 100) # 左边那半边脸turtle.end_fill() #def drawHead():""" 画了一个被切掉下半部分的圆"""turtle.penup() # 抬笔turtle.circle(150, 40) # 画圆, 半径150,圆周角40turtle.pendown() # 落笔turtle.fillcolor("#00a0de") # 填充色turtle.begin_fill() # 开始填充turtle.circle(150, 280) # 画圆,半径150, 圆周角280turtle.end_fill()def drawAll():drawHead()drawRedScarf()drawFace()drawRedNose()drawMouse()beard()flyTo(0, 0)turtle.seth(0)turtle.penup()turtle.circle(150, 50)turtle.pendown()turtle.seth(30)turtle.fd(40)turtle.seth(70)turtle.circle(-30, 270)turtle.fillcolor("#00a0de")turtle.begin_fill()turtle.seth(230)turtle.fd(80)turtle.seth(90)turtle.circle(1000, 1)turtle.seth(-89)turtle.circle(-1000, 10)turtle.seth(180)turtle.fd(70)turtle.seth(90)turtle.circle(30, 180)turtle.seth(180)turtle.fd(70)turtle.seth(100)turtle.circle(-1000, 9)turtle.seth(-86)turtle.circle(1000, 2)turtle.seth(230)turtle.fd(40)turtle.circle(-30, 230)turtle.seth(45)turtle.fd(81)turtle.seth(0)turtle.fd(203)turtle.circle(5, 90)turtle.fd(10)turtle.circle(5, 90)turtle.fd(7)turtle.seth(40)turtle.circle(150, 10)turtle.seth(30)turtle.fd(40)turtle.end_fill()# 左手turtle.seth(70)turtle.fillcolor("#FFFFFF")turtle.begin_fill()turtle.circle(-30)turtle.end_fill()# 脚flyTo(103.74, -182.59)turtle.seth(0)turtle.fillcolor("#FFFFFF")turtle.begin_fill()turtle.fd(15)turtle.circle(-15, 180)turtle.fd(90)turtle.circle(-15, 180)turtle.fd(10)turtle.end_fill()flyTo(-96.26, -182.59)turtle.seth(180)turtle.fillcolor("#FFFFFF")turtle.begin_fill()turtle.fd(15)turtle.circle(15, 180)turtle.fd(90)turtle.circle(15, 180)turtle.fd(10)turtle.end_fill()# 右手flyTo(-133.97, -91.81)turtle.seth(50)turtle.fillcolor("#FFFFFF")turtle.begin_fill()turtle.circle(30)turtle.end_fill()# 口袋flyTo(-103.42, 15.09)turtle.seth(0)turtle.fd(38)turtle.seth(230)turtle.begin_fill()turtle.circle(90, 260)turtle.end_fill()flyTo(5, -40)turtle.seth(0)turtle.fd(70)turtle.seth(-90)turtle.circle(-70, 180)turtle.seth(0)turtle.fd(70)# 铃铛flyTo(-103.42, 15.09)turtle.fd(90)turtle.seth(70)turtle.fillcolor("#ffd200")turtle.begin_fill()turtle.circle(-20)turtle.end_fill()turtle.seth(170)turtle.fillcolor("#ffd200")turtle.begin_fill()turtle.circle(-2, 180)turtle.seth(10)turtle.circle(-100, 22)turtle.circle(-2, 180)turtle.seth(180 - 10)turtle.circle(100, 22)turtle.end_fill()flyTo(-13.42, 15.09)turtle.seth(250)turtle.circle(20, 110)turtle.seth(90)turtle.fd(15)turtle.dot(10)flyTo(0, -150)drawBlackdrawEye()def main():turtle.screensize(800, 6000, "#F0F0F0")turtle.pensize(3)turtle.speed(9)drawAll()if __name__ == "__main__":main()turtle.mainloop()
时钟import turtlefrom datetime import # 抬起画笔,向前运动一段距离放下def Skip(step):turtle.penup()turtle.forward(step)turtle.pendown()def mkHand(name, length):# 注册Turtle形状,建立表针Turtleturtle.reset()Skip(-length 0.1)# 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。turtle.begin_poly()turtle.forward(length 1.1)# 停止记录多边形的顶点。当前的乌龟位置是多边形的一个顶点。将与第一个顶点相连。turtle.end_poly()# 返回记录的多边形。handForm = turtle.get_poly()turtle.register_shape(name, handForm)def Init():global secHand, minHand, hurHand, printer# 重置Turtle指向北turtle.mode("logo")# 建立三个表针Turtle并初始化mkHand("secHand", 135)mkHand("minHand", 125)mkHand("hurHand", 90)secHand = turtle.Turtle()secHand.shape("secHand")minHand = turtle.Turtle()minHand.shape("minHand")hurHand = turtle.Turtle()hurHand.shape("hurHand")for hand in secHand, minHand, hurHand:hand.shapesize(1, 1, 3)hand.pencolor(orange)hand.speed(0)# 建立输出文字Turtleprinter = turtle.Turtle()printer.pencolor(red)# 隐藏画笔的turtle形状printer.hideturtle()printer.penup()def SetupClock(radius):# 建立表的外框turtle.reset()turtle.pencolor(blue)turtle.pensize(7)for i in range(60):Skip(radius)if i % 5 == 0:turtle.forward(20)Skip(-radius - 20)Skip(radius + 20)if i == 0:turtle.write(int(12), align="center", font=("Courier", 14, "bold"))elif i == 30:Skip(25)turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))Skip(-25)elif (i == 25 or i == 35):Skip(20)turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))Skip(-20)else:turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))Skip(-radius - 20)else:turtle.dot(5)Skip(-radius)turtle.right(6)def Week(t):week = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]return week[t.weekday()]def Date(t):y = t.yearm = t.monthd = t.dayreturn "%s-%d-%d" % (y, m, d)def Tick():# 绘制表针的动态显示t = datetime.today()second = t.second + t.microsecond 0.000001minute = t.minute + second / 60.0hour = t.hour + minute / 60.0secHand.setheading(6 second)minHand.setheading(6 minute)hurHand.setheading(30 hour)turtle.tracer(False)printer.forward(65)printer.write(Week(t), align="center", font=("Courier", 14, "bold"))printer.back(130)printer.write(Date(t), align="center", font=("Courier", 14, "bold"))printer.home()turtle.tracer(True)# 100ms后继续调用tickturtle.ontimer(Tick, 100)def main():# 打开/关闭龟动画,并为更新图纸设置延迟。turtle.tracer(False)Init()SetupClock(160)turtle.tracer(True)Tick()turtle.done()if __name__ == "__main__":main() 相关文章
豪杰超级解霸(还记得豪杰超级解霸吗?)
龚自珍的资料(清代诗人龚自珍一生功绩简介)
象牙塔是什么意思(“象牙塔”里怎么了?)
水色风信子(水培风信子容易养)
婧字怎么读
虞姬是哪里人(古代著名美人虞姬到底是哪里人?)
公办三本院校(我们还有哪些“三本”?)
电子酒柜(酒柜最全选购指南)
德州景点(德州市景区景点62个)
玉兰油官方网(OLAY发布高端臻粹系列)
驱鬼咒语(道教辟邪的神咒)
奥运五环代表什么(奥运会五环代表着什么?)
更多python简单的画图代码爱心(用python画一个爱心的代码)相关信息请关注本文章,本文仅仅做为展示!