本文主要是介绍一朵玫瑰花,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一朵玫瑰花
参考文献(https://blog.csdn.net/kangqiao0422/article/details/103901548?ops_request_misc=%25257B%252522request%25255Fid%252522%25253A%252522161242311516780269838285%252522%25252C%252522scm%252522%25253A%25252220140713.130102334…%252522%25257D&request_id=161242311516780269838285&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-3-103901548.pc_search_result_no_baidu_js&utm_term=python+turtle%25E7%258E%25AB%25E7%2591%25B0)
本人在参考文献上添加了一些自己的创意,附上效果图
时间采用了七段晶体管,可直接从系统中自动获取,附上全部代码
from turtle import *
import time
#设置绘制起点
setup(0.7,0.9)
#画笔颜色
pencolor("red")
hideturtle()
penup()
goto(0,280)
pendown()
left(135)
speed(10)
#左侧弧形绘制
a=0.2
for i in range (80):if i < 50:pensize(a)forward(2)a+=0.15if i<10:left(0.7)elif 10<i<24:left(1)elif 24<i<40:left(3)elif 40<i<50:left(4)elif i >=50:pensize(a)forward(2.2)a-=0.25if 50<i<65:left(6.7)elif 65<i<80:left(2)
setheading(0)
penup()
goto(40,305)
pendown()
left(145)
#右侧弧形绘制
a=0.1
for i in range (100):if i < 60:pensize(a)forward(3)a+=0.15if i<10:left(0.8)elif 10<i<24:left(0.8)elif 24<i<40:left(1.7)elif 40<i<60:left(2.2)elif i >=60:pensize(a)forward(2.4)a-=0.15if 60<i<85:left(3.2)elif 85<i<90:left(4)
setheading(0)
penup()
goto(45,320)
pendown()
left(10)
a=0.1
for i in range (100):if i < 60:pensize(a)forward(3)a+=0.15if i<17:right(3.2)elif 17<i<20:right(3.5)elif 20<i<40:right(6.8)elif 40<i<50:right(0.6)elif 50<i<60:left(1)elif i >=60:pensize(a)forward(2.4)a-=0.16if 60<i<85:left(0.4)elif 85<i<90:left(1)
setheading(0)
penup()
goto(-135,265)
pendown()
left(160)
a=0.1
for i in range (120):if i < 60:pensize(a)forward(3)a+=0.15if i<10:left(2)elif 10<i<15:left(8)elif 15<i<35:left(6)elif 35<i<40:left(4)elif 40<i<60:left(1)elif i >=60:pensize(a)forward(3)a-=0.15if 60<i<90:right(0.4)elif 90<i<120:right(0.8)
setheading(0)
penup()
goto(80,250)
pendown()
left(245)
a=0.2
for i in range (80):if i < 40:pensize(a)forward(1.2)a+=0.15if i<15:left(0.6)elif 15<i<40:left(0.3)elif i >=40:pensize(a)forward(1.2)a-=0.15if 40<i<65:left(0.6)elif 65<i<80:left(0.35)
setheading(0)
penup()
goto(-150,195)
pendown()
left(300)
a=0.2
for i in range (80):if i < 40:pensize(a)forward(1.2)a+=0.16if i<15:right(0.6)elif 15<i<40:right(0.3)elif i >=40:pensize(a)forward(1.2)a-=0.16if 40<i<65:right(0.6)elif 65<i<80:right(0.35)
setheading(0)
penup()
goto(-205,225)
pendown()
left(194)
a=0.1
for i in range (100):if i < 50:pensize(a)forward(3)a+=0.15if i<10:left(7)elif 10<i<30:left(3)elif 30<i<50:left(0.1)elif i >=50:pensize(a)forward(3)a-=0.15if 50<i<80:right(0.3)elif 80<i<100:right(0.6)
setheading(0)
penup()
goto(110,280)
pendown()
left(6)
a=0.1
for i in range (120):if i < 60:pensize(a)forward(3)a+=0.15if i<10:right(4.5)elif 10<i<30:right(5)elif 30<i<60:right(0.1)elif i >=60:pensize(a)forward(3)a-=0.15if 50<i<80:left(0.6)elif 80<i<100:left(0.9)
setheading(0)
penup()
goto(-160,110)
pendown()
left(283)
a=0.2
for i in range (80):if i < 40:pensize(a)forward(2.4)a+=0.15if i<10:right(0.6)elif 15<i<40:right(0.1)elif i >=40:pensize(a)forward(2.4)a-=0.15if 40<i<65:left(2)elif 65<i<80:left(3)
setheading(0)
penup()
goto(90,155)
pendown()
left(258)
a=0.2
for i in range (80):if i < 40:pensize(a)forward(3)a+=0.15if i<10:left(0.8)elif 15<i<40:left(0.1)elif i >=40:pensize(a)forward(3)a-=0.15if 40<i<65:right(2)elif 65<i<80:right(3)
setheading(0)
penup()
goto(-60,-45)
pendown()
right(9)
a=0.2
for i in range (40):if i < 20:pensize(a)forward(1.3)a+=0.15if i<5:left(0.7)elif 5<i<20:left(0.4)elif i >=20:pensize(a)forward(1.3)a-=0.15if 20<i<35:left(0.7)elif 35<i<40:left(0.4)
setheading(0)
penup()
goto(-70,-55)
pencolor("green")
pendown()
right(170)
a=0.2
for i in range (80):if i <40 :pensize(a)forward(2)a+=0.15if i<25:right(0.5)elif 25<i<40:right(1)elif i >=40:pensize(a)forward(2.5)a-=0.15if 40<i<55:right(1)elif 55<i<70:right(2)elif 70<i<80:right(1)
setheading(270)
left(30)
a=0.2
for i in range (80):if i <40 :pensize(a)forward(2.5)a+=0.15if i<25:left(0.5)elif 25<i<40:left(1)elif i >=40:pensize(a)forward(3)a-=0.15if 40<i<55:left(2)elif 55<i<70:left(1.3)elif 70<i<80:left(1)
setheading(270)
penup()
goto(20,-55)
pendown()
left(65)
a=0.2
for i in range (60):if i <30 :pensize(a)forward(2)a+=0.15if i<15:left(1)elif 15<i<30:left(2)elif i >=30:pensize(a)forward(2.5)a-=0.15if 30<i<45:left(2)elif 45<i<50:left(2.5)elif 50<i<60:left(1.5)
setheading(270)
right(17)
a=0.2
for i in range (80):if i <40 :pensize(a)forward(2.2)a+=0.15if i<25:right(1)elif 25<i<40:right(2)elif i >=40:pensize(a)forward(2.5)a-=0.15if 40<i<55:right(2)elif 55<i<70:right(1.5)elif 70<i<80:right(0.6)
setheading(0)
penup()
pencolor("brown")
goto(-49,-90)
pendown()
right(89)
a=1
for i in range (120):if i < 60:pensize(a)forward(3.5)a+=0.08elif i >=60:pensize(a)forward(3.5)a-=0.08
setheading(0)
penup()
goto(-16,-70)
pendown()
right(91)
a=1
for i in range (120):if i < 60:pensize(a)forward(3.5)a+=0.08elif i >=60:pensize(a)forward(3.5)a-=0.08
setheading(0)speed(3)
penup()
goto(-16,-150)
pendown()
pensize(3)
left(35)
forward(15)
setheading(0)
right(115)
forward(34)setheading(180)
penup()
goto(-49,-250)
pendown()
pensize(3)
right(35)
forward(15)
setheading(180)
left(115)
forward(34)def drawGap():penup()fd(5)
def drawLine(draw):drawGap()pendown() if draw else penup()fd(40)drawGap()right(90)
def drawDigit(digit):drawLine(True) if digit in [2,3,4,5,6,8,9] else drawLine(False)drawLine(True) if digit in [0,1,3,4,5,6,7,8,9] else drawLine(False)drawLine(True) if digit in [0,2,3,5,6,8,9] else drawLine(False)drawLine(True) if digit in [0,2,6,8] else drawLine(False)left(90)drawLine(True) if digit in [0,4,5,6,8,9] else drawLine(False)drawLine(True) if digit in [0,2,3,5,6,7,8,9] else drawLine(False)drawLine(True) if digit in [0,1,2,3,4,7,8,9] else drawLine(False)left(180)penup()fd(20)
def drawDate(date):pencolor("red")for i in date:if i== '-':write("年",font=("Arial",18,"normal"))pencolor("green")fd(40)elif i =='=':write("月",font=("Arial",18,"normal"))pencolor("blue")fd(40)elif i=='+':write("日",font=("Arial",18,"normal"))else:drawDigit(eval(i))
def main():speed(5)left(60)penup()fd(-300)left(90)fd(150)right(90)penup()pensize(5)drawDate(time.strftime("%Y-%m=%d+",time.gmtime()))right(90)fd(150)right(90)fd(500)right(180)pencolor("purple")write("送给我心中的人",font=("Arial",30,"normal"))hideturtle()input('input:')
main()
如果你不太会看代码,可以直接修改最后的文字,改成自己喜欢人的名字就好。
喜欢的人变了,也改个名字可以继续用。
这篇关于一朵玫瑰花的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!