【Python Turtle合集】”外面的花已经开得很像样了, 我看到风拥作一团, 前来庆贺“(春天来啦~)
前言
🚀 作者 :“程序員梨子”
🚀 **文章簡(jiǎn)介 **:本篇文章主要是寫(xiě)了利用Turtle庫(kù)繪制2種不一樣的花花的小程序!
🚀 **文章源碼免費(fèi)獲取 : 為了感謝每一個(gè)關(guān)注我的小可愛(ài)💓每篇文章的項(xiàng)目源碼都是無(wú)
償分享滴💓👇👇👇👇
點(diǎn)這里藍(lán)色這行字體自取,需要什么源碼記得說(shuō)標(biāo)題名字哈!私信我也可!
🚀 歡迎小伙伴們 點(diǎn)贊👍、收藏?、留言💬
正文
“花在不遠(yuǎn)處盛開(kāi),你從我心田中走來(lái)。?又是一年好風(fēng)光,海風(fēng)依舊,事事皆歡。”
——關(guān)于《春》的文案
盼望著,盼望著,春天來(lái)了!
三月的花期也如約而至,小編帶你“云賞”美麗“花海”!先來(lái)給大家看看那些漂亮的風(fēng)景👇
嘻嘻!這么漂亮的風(fēng)景這可太復(fù)雜了,小編只能給大家繪制一些簡(jiǎn)單款的啦!👇
1)“你來(lái)了,剛好春天也到了”
?代碼展示——
import turtleimport mathdef 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/np_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) / 360n = int(arc_length / 4) + 1step_length = arc_length / nstep_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 screenwindow.bgcolor("white")window.title("draw a flower")lucy= turtle.Turtle()lucy.shape("turtle")lucy.color("red")lucy.width(3)#lucy.speed(10)# Drawing flowerflower(lucy, 7, 60, 100, 360)# Drawing pedicellucy.color("brown")lucy.rt(90)lucy.fd(200)# Drawing leaf 1lucy.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 2lucy.rt(120)lucy.color("green")leaf(lucy, 40, 80, 180)lucy.color("black")lucy.rt(140)lucy.fd(30)lucy.ht() # hideturtlewindow.exitonclick()2)“待度過(guò)斜風(fēng)冷雨 春暖在眼前”
?
代碼展示——
from turtle import * # 定義畫(huà)花瓣的函數(shù) def drawLeaf():begin_fill()for i in range(2):for i in range(15):lt(6)fd(5)lt(90)end_fill()#主程序開(kāi)始 speed(0) pu() goto(0,-200)# 畫(huà)花柄 pd() color('black','green') for i in range(2): lt(90)fd(100)drawLeaf()rt(90)drawLeaf() # 畫(huà)花朵 lt(90) fd(130) color('black','red') for i in range(12):drawLeaf()lt(360/12) # 畫(huà)花心的圓圈 pu() ls(90) fd(-10) rt(90) pd() color('black','yellow') begin_fill() circle(10) end_fill() hideturtle()總結(jié)
“何謂春風(fēng)?”“繁花,綠茵,凍水初融。”“可否具體?”“桃眼,笑渦,春心洋溢。”“可否再具體?”“走
過(guò)你。”——網(wǎng)易網(wǎng)友
注小編獲取更多精彩內(nèi)容!源碼記得點(diǎn)擊傳送門哈👇👇👇👇
記得三連哦! 如需打包好的源碼+素材免費(fèi)分享滴!!傳送門
總結(jié)
以上是生活随笔為你收集整理的【Python Turtle合集】”外面的花已经开得很像样了, 我看到风拥作一团, 前来庆贺“(春天来啦~)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Python Turtle合集】有趣好
- 下一篇: 【Pygame小游戏】这款经典的炸弹人超