Python+turtle繪制七夕表白玫瑰花
中國情人節(jié)
七夕節(jié),又稱“七巧節(jié)”“女兒節(jié)”“乞巧節(jié)”等,是中國民間的傳統(tǒng)節(jié)日。這個(gè)節(jié)日被賦予了“牛郎織女”的美麗愛情傳說,被認(rèn)為是中國最具浪漫色彩的傳統(tǒng)節(jié)日,在當(dāng)代更是產(chǎn)生了“中國情人節(jié)”的文化含義。
一年一度的七夕又快到了,用Python畫一朵玫瑰花送給你的那個(gè)TA吧。
更多表白代碼可以翻看表白合集中的文章,可以邊聽音樂邊看Python代碼圖。
一、繪制結(jié)果
1. 玫瑰花1
2. 玫瑰花2
二、畫玫瑰花代碼
1. 用turtle庫畫一朵玫瑰花版本1
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫玫瑰花 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' #繪制玫瑰花并添加文字 import turtle # 設(shè)置畫布大小 # turtle.screensize(canvwidth=None, canvheight=None, bg=None) turtle.setup(width=0.6, height=0.6) # 設(shè)置初始位置 turtle.penup() turtle.left(90) turtle.fd(200) turtle.pendown() turtle.right(90) # 輸出文字 printer = turtle.Turtle() printer.hideturtle() printer.penup() printer.back(200) printer.write("贈(zèng)給親愛的 XX\n\n", align="right", font=("楷體", 16, "bold")) printer.write("from XXX", align="center", font=("楷體", 12, "normal")) # 花蕊 turtle.fillcolor("red") turtle.begin_fill() turtle.circle(10, 180) turtle.circle(25, 110) turtle.left(50) turtle.circle(60, 45) turtle.circle(20, 170) turtle.right(24) turtle.fd(30) turtle.left(10) turtle.circle(30, 110) turtle.fd(20) turtle.left(40) turtle.circle(90, 70) turtle.circle(30, 150) turtle.right(30) turtle.fd(15) turtle.circle(80, 90) turtle.left(15) turtle.fd(45) turtle.right(165) turtle.fd(20) turtle.left(155) turtle.circle(150, 80) turtle.left(50) turtle.circle(150, 90) turtle.end_fill() # 花瓣1 turtle.left(150) turtle.circle(-90, 70) turtle.left(20) turtle.circle(75, 105) turtle.setheading(60) turtle.circle(80, 98) turtle.circle(-90, 40) # 花瓣2 turtle.left(180) turtle.circle(90, 40) turtle.circle(-80, 98) turtle.setheading(-83) # 葉子1 turtle.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) # 葉子2 turtle.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()
效果圖
2. 用turtle庫畫一朵玫瑰花版本2
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫玫瑰花 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' import os import time import pygame import turtle as t #播放音樂 print('播放音樂') pygame.mixer.init() pygame.mixer.music.load(r"F:\公眾號(hào)\62.玫瑰花\Eran - 春の思い出.mp3") pygame.mixer.music.set_volume(0.5) pygame.mixer.music.play(1, 10) t.title('阿黎逸陽的代碼公眾號(hào)') t.speed(3) t.setup(startx=0, starty = 0, width=800, height = 600) #畫愛心 def red_heart(): t.penup() t.goto(0, 200) t.pendown() t.pensize(2) t.color('black', 'red') t.begin_fill() t.setheading(110) t.circle(30, 150) t.left(15) t.circle(50, 70) t.circle(-50, 30) t.left(100) t.circle(-50, 30) t.right(10) t.circle(50, 70) t.left(5) t.circle(29, 175) t.end_fill() def top_arc(): #畫花上面的部分 t.penup() t.goto(18, 224) t.pendown() t.begin_fill() t.setheading(125) t.pensize(2) t.color('black', 'red') t.circle(25, 125) t.color('red') t.circle(25, 360-125) t.end_fill() def under_arc(): #畫下弧線 t.penup() t.goto(-58, 190) t.pendown() t.begin_fill() t.color('black', 'red') t.setheading(290) t.circle(-120, 50) t.circle(60, 120) t.setheading(-10) t.circle(60, 120) t.left(4) t.circle(-120, 50) t.end_fill() def stamen(): #畫花蕊 t.penup() t.goto(0, 185) t.pendown() t.setheading(90) t.circle(5, 270) t.right(5) t.circle(100, 8) #t.right(10) t.circle(10, 180) t.circle(100, 8) t.right(10) t.circle(15, 160) t.circle(80, 5) t.right(34) t.circle(-30, 80) #畫花身 t.right(10) t.circle(100, 82) #畫豎線 t.penup() t.goto(-10, 183) t.pendown() t.setheading(-90) t.forward(15) t.penup() t.goto(-21, 179) t.pendown() t.setheading(-90) t.forward(25) t.penup() t.goto(18, 185) t.pendown() t.setheading(-90) t.forward(29) print('畫心') red_heart() print('畫頂部弧線') top_arc() print('畫下弧線') under_arc() print('畫心') red_heart() print('畫花蕊') stamen() # 寫文字 t.hideturtle() t.penup() t.goto(-200, -200) t.pendown() t.write("贈(zèng)給親愛的 XX\n\n", align="right", font=("楷體", 16, "bold")) t.penup() t.goto(-200, -200) t.pendown() t.write("from XXX", align="right", font=("楷體", 12, "normal"))
效果視頻
到此這篇關(guān)于Python+turtle繪制七夕表白玫瑰花的文章就介紹到這了,更多相關(guān)Python turtle玫瑰花內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
讓Django支持Sql Server作后端數(shù)據(jù)庫的方法
今天小編就為大家分享一篇讓Django支持Sql Server作后端數(shù)據(jù)庫的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-05-05利用Python編寫一個(gè)注冊(cè)機(jī)用于生成卡密
這篇文章主要為大家詳細(xì)介紹了如何利用Python編寫一個(gè)注冊(cè)機(jī)用于生成卡密(兌換碼),并使用這些卡密登錄應(yīng)用程序,感興趣的小伙伴可以了解下2023-11-11解決Keras TensorFlow 混編中 trainable=False設(shè)置無效問題
這篇文章主要介紹了解決Keras TensorFlow 混編中 trainable=False設(shè)置無效問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-06-06