这篇文章以甜蜜的文案开篇,主要介绍了用 Python 的 turtle 绘图实现多种花的代码,包括樱花树、玫瑰花、牡丹花等,每种花都有相应文案、代码展示和效果展示,最后表示代码结束,可找作者拿源码资料。
关联问题: 如何修改代码颜色 哪种花最难绘制 能教更多花型吗
“我想和你在一起虚度时光,坐看云卷云舒,花开花落”
又快到了一年小长假的时候啦,
单身狗的你们还好嘛~~
还是,你们找到想要表白的人啦?有想要一起去旅游的人了鸭~
在此"幸福佳节(5.1)",贴心的送上告白文案,并附上土味情话PK程序员告白代码
到底谁会赢?我是木木子,不仅能教你们写代码还是你们的恋爱军师哦!嘿嘿嘿~
本文是很多很多的Python绘图Turtle合集组合而成的,希望大家喜欢啦~
喜欢和爱是不一样的,如果你喜欢一朵花,你会摘下它。
如果你爱一朵花,你会给它浇水。
就好像我爱你这件事,表白的场景想了千万遍,假装你听见我的告白,可爱的脸庞会泛起红
晕,不自觉地笑容满溢,用拥抱回答我的告白。
为了准备好这场告白,我开始搜集甜蜜的句子,捕捉心动的节奏,然后鼓起勇气,把“我爱你”说
给你听。于是,便有了这个将《表白》进行到底的代码(turtle)集合。我想带你一起去看花海!
一、樱花树
1)樱花文案
樱花,每一次相遇都只如初见。
里樱花醉金徽,不负春光不负卿。
阳光如此明媚、陪我赏樱花可好。
在温暖的春风里,看一场浪漫樱花。
2)代码展示
from turtle import * from random import * from math import * class Tree: def __init__(self): setup(1000, 700) bgcolor(1, 1, 1) # 背景色 # ht() # 隐藏turtle speed(10) # 速度 1-10渐进,0 最快 # tracer(1, 100) # 设置绘图屏幕刷新频率,参数1设置在正常刷新频次的第参数1次刷新,参数2设置每次刷新的时延 tracer(0, 0) pu() # 抬笔 backward(100) # 保证笔触箭头方向始终不向下,此处使其左转90度,而不是右转 left(90) # 左转90度 backward(300) # 后退300 def tree(self, n, l): pd() # 下笔 # 阴影效果 t = cos(radians(heading() + 45)) / 8 + 0.25 pencolor(t, t, t) pensize(n / 1.2) forward(l) # 画树枝 if n > 0: b = random() * 15 + 10 # 右分支偏转角度 c = random() * 15 + 10 # 左分支偏转角度 d = l * (random() * 0.25 + 0.7) # 下一个分支的长度 # 右转一定角度,画右分支 right(b) self.tree(n - 1, d) # 左转一定角度,画左分支 left(b + c) self.tree(n - 1, d) # 转回来 right(c) else: # 画叶子 right(90) n = cos(radians(heading() - 45)) / 4 + 0.5 pencolor(n, n * 0.8, n * 0.8) fillcolor(n, n * 0.8, n * 0.8) begin_fill() circle(3) left(90) end_fill() # 添加0.3倍的飘落叶子 if random() > 0.7: pu() # 飘落 t = heading() an = -40 + random() * 40 setheading(an) dis = int(800 * random() * 0.5 + 400 * random() * 0.3 + 200 * random() * 0.2) forward(dis) setheading(t) # 画叶子 pd() right(90) n = cos(radians(heading() - 45)) / 4 + 0.5 pencolor(n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4) fillcolor(n, n * 0.8, n * 0.8) begin_fill() circle(2) left(90) end_fill() pu() # 返回 t = heading() setheading(an) backward(dis) setheading(t) # pass pu() backward(l) # 退回 def main(): tree = Tree() tree.tree(12, 100) # 递归7层 done() if __name__ == '__main__': main()
3)效果展示
二、玫瑰花
1)玫瑰文案
只有玫瑰,与你相称。
“玫瑰到了花期”意思是我想你了
我将玫瑰藏于身后,时刻期盼着与你赴约
也许世界上也有五千朵和你样的花,但只有你是我独一元二的玫瑰。
2)代码展示
t.setup(800,800) t.hideturtle() t.speed(11) t.penup() t.goto(50,-450) t.pensize(5) t.pencolor("black") t.seth(140) t.pendown() t.speed(10) t.circle(-300,60) t.fd(100) #叶子 t.seth(10) t.fd(50) t.fillcolor("green") t.begin_fill() t.right(40) t.circle(120,80) t.left(100) t.circle(120,80) t.end_fill() t.seth(10) t.fd(90) t.speed(11) t.penup() t.fd(-140) t.seth(80) #一片叶子 t.pendown() t.speed(10) t.fd(70) t.seth(160) t.fd(50) t.fillcolor("green") t.begin_fill() t.right(40) t.circle(120,80) t.left(100) t.circle(120,80) t.end_fill() t.seth(160) t.fd(90) t.speed(11) t.penup() t.fd(-140) t.seth(80) t.pendown() t.speed(10) # t.fd(100) #花瓣 t.seth(-20) t.fillcolor("blue") t.begin_fill() t.circle(100,100) t.circle(-110,70) t.seth(179) t.circle(223,76) t.end_fill() #2花瓣 t.speed(11) t.fillcolor("blue") t.begin_fill() t.left(180) t.circle(-223,60) t.seth(70) t.speed(10) t.circle(-213,15)#55 t.left(70)#125 t.circle(200,70) t.seth(-80) t.circle(-170,40) t.circle(124,94) t.end_fill() # t.speed(11) t.penup() t.right(180) t.circle(-124,94) t.circle(170,40) t.pendown() t.speed(10) t.seth(-60) t.circle(175,70) t.seth(235) t.circle(300,12) t.right(180) t.circle(-300,12) t.seth(125) t.circle(150,60) t.seth(70) t.fd(-20) t.fd(20) t.seth(-45) t.circle(150,40) t.seth(66) t.fd(-18.5) t.fd(18.5) t.seth(140) t.circle(150,27) t.seth(60) t.fd(-8) t.speed(11) t.penup() t.left(20.8) t.fd(-250.5) #3花瓣 t.pendown() t.speed(10) t.fillcolor("blue") t.begin_fill() t.seth(160) t.circle(-140,85) t.circle(100,70) t.right(165) t.circle(-200,32) t.speed(11) t.seth(-105) t.circle(-170,14.5) t.circle(123,94) t.end_fill() t.done()
3)效果展示
三、牡丹花
1)牡丹文案
春来无事,只为花忙。
“花香暗相许,浓淡两相如。”
下次见面可以从送我花开始吗?
你自山河林间来,惊鸿一现百花开。
2)代码展示
import turtle t = turtle.Pen() t.pencolor("red") for x in range(360): t.forward(x) t.left(49)
3)效果展示
四、不知名花花❣️
1)花花文案
见山是山,见海是海,见花便是花。
“盛开的不是花,是对你漫山遍野的喜欢。”
花出,花开,花盛,花枯,花落,有始就有终。
“我不喜欢花,我只喜欢你抱着花朝我走来的样子。”
2)代码展示
import turtle as t def drawDiamond(Tom): for i in range(2): Tom.forward(100) Tom.right(45) Tom.forward(100) Tom.right(135) def drawFlower(): window=t.Screen() window.bgcolor('green') Tom = t.Turtle() Tom.shape('turtle') Tom.color('yellow') Tom.speed(8) Tom.fillcolor('red') Tom.begin_fill() for i in range(18): drawDiamond(Tom) Tom.right(20) Tom.end_fill() Tom.hideturtle() drawDiamond(Tom) window.exitonclick() Tom.done() drawFlower()
3)效果展示
五、一朵小花
1)小花文案
✨阳光洒在花上,也能照进心里。
✨“冬天花败,春暖花开,有人离去,有人归来。”
✨“是因为快乐才买花,而不是因为买花快乐而买花。
✨“有种花叫满天星,它的花语是我甘愿做配角瞒着所有爱你,我携满天星以赠你,仍觉满天星
不及你。”
2)代码展示
# -*- coding: cp936 -*- import turtle import math def p_line(t, n, length, angle): """Draws n line segments.""" for i in range(n): t.fd(length) t.lt(angle) def polygon(t, n, length): """Draws a polygon with n sides.""" angle = 360/n p_line(t, n, length, angle) def arc(t, r, angle): """Draws an arc with the given radius and angle.""" arc_length = 2 * math.pi * r * abs(angle) / 360 n = int(arc_length / 4) + 1 step_length = arc_length / n step_angle = float(angle) / n # Before starting reduces, making a slight left turn. t.lt(step_angle/2) p_line(t, n, step_length, step_angle) t.rt(step_angle/2) def petal(t, r, angle): """Draws a 鑺辩摚 using two arcs.""" for i in range(2): arc(t, r, angle) t.lt(180-angle) def flower(t, n, r, angle, p): """Draws a flower with n petals.""" for i in range(n): petal(t, r, angle) t.lt(p/n) def leaf(t, r, angle, p): """Draws a 鍙跺瓙 and fill it.""" t.begin_fill() # Begin the fill process. t.down() flower(t, 1, r, angle, p) t.end_fill() def main(): window= turtle.Screen() #creat a screen window.bgcolor("white") window.title("draw a flower") lucy= turtle.Turtle() lucy.shape("turtle") lucy.color("red") lucy.width(3) #lucy.speed(10) # Drawing flower flower(lucy, 7, 60, 100, 360) # Drawing pedicel lucy.color("brown") lucy.rt(90) lucy.fd(200) # Drawing leaf 1 lucy.width(1) lucy.rt(270) lucy.color("green") leaf(lucy, 40, 80, 180) lucy.rt(140) lucy.color("black") lucy.fd(30) lucy.lt(180) lucy.fd(30) # Drawing leaf 2 lucy.rt(120) lucy.color("green") leaf(lucy, 40, 80, 180) lucy.color("black") lucy.rt(140) lucy.fd(30) lucy.ht() # hideturtle window.exitonclick() main()
3)效果展示
六、尖尖花
1)文案
因为有你,花便有了去处。
问了问心 它说情不自禁。
做个浪漫的人,从给自己买花开始。
揣着一口袋的开心满载而归,还有定格春天的味道。
2)代码展示
from turtle import * from math import * n=eval(input("请输入花瓣数n= (n=3,6,9...)")) angle=2*pi/n l=2*200*sin(angle/2) color("red","pink") penup() rt(90) fd(150) lt(90) pendown() lt(60) for i in range(int(n/3)): if i==0: begin_fill() for i in range(3): circle(200,120) lt(120) end_fill() elif i>0: rt(60) penup() fd(l*cos(angle/2)) lt(90) fd(l*sin(angle/2)) pendown() setheading(0) lt(60+i*degrees(angle)) begin_fill() for i in range(3): circle(200,120) lt(120) end_fill()
3)效果展示
“路灯的三个影子一个是我的 另一个也是我的 还有一个是我们的”。哎呀!今天的文案甜度已经
超标了,大家放心“食用”叭~保证甜到掉牙~~~
嘿嘿,今天的代码写到这里就结束了哟,想要继续学习的滴滴我拿源码资料啦!
相关知识
一束花的仪式感是永远不会过时的
一束花的仪式感 永远不会过时
一束花的仪式感。带着温柔和浪漫 去迎接八月的惊喜 简单整
python玫瑰花代码简单
python玫瑰花代码讲解
python的turtle画个玫瑰花
一束花的仪式感,永不过时
花时间鲜花永远给你惊喜
画个心,写个花!Python Turtle库带你玩转创意绘图!
使用Python的turtle模块绘制玫瑰花图案(含详细Python代码与注释)
网址: 【Python表白集】没有哪个女孩子 不喜欢花 不喜欢惊喜:“一束花的仪式感,永远不会过时鸭~”(turtle绘图代码) https://m.huajiangbk.com/newsview793273.html
上一篇: vbs玫瑰花表白代码 |
下一篇: 张家界七星山七夕上演山巅告白 |