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