Python+turtle繪制對稱圖形的示例代碼
最近有個(gè)朋友,想要我?guī)兔τ胮ython畫幾個(gè)圖,在畫的過程中覺得有些圖還挺有意思的,分享給大家。
1.圖1
第一個(gè)圖是由三角形組成的花,感興趣的小伙伴可以自己嘗試在python中用turtle庫繪制一下。
具體代碼如下:
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫對稱圖形 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' import os import time import pygame import turtle as t t.title('阿黎逸陽的代碼公眾號') t.speed(10) t.setup(startx=0, starty = 0, width=800, height = 600) #第一幅圖 def w_sg1(theta): t.setheading(theta) t.color('green') t.begin_fill() t.forward(60) t.left(100) t.forward(20) t.left(100) t.forward(60) t.end_fill() for i in range(8): w_sg1(70 + i*45) t.hideturtle()
2.圖2
第二個(gè)圖是旋風(fēng)輪,怎么通過調(diào)整圖1代碼,繪制出如下圖形?
具體代碼如下:
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫對稱圖形 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' import os import time import pygame import turtle as t t.title('阿黎逸陽的代碼公眾號') t.speed(10) t.setup(startx=0, starty = 0, width=800, height = 600) #第二幅圖 def w_sg2(theta): t.setheading(theta) t.color('green') t.begin_fill() t.forward(55) t.left(100) t.forward(20) t.left(100) t.forward(60) t.end_fill() for i in range(24): w_sg2(70 + i*15) t.hideturtle()
3.圖3
第三個(gè)圖是八葉花,你也可以試著把葉子改成別的顏色。
具體代碼如下:
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫對稱圖形 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' import os import time import pygame import turtle as t t.title('阿黎逸陽的代碼公眾號') t.speed(10) t.setup(startx=0, starty = 0, width=800, height = 600) #第三幅圖 def w_sg3(theta): t.color('green') t.begin_fill() t.setheading(theta) t.circle(80, 50) t.left(130) t.circle(80, 50) t.end_fill() for i in range(8): w_sg3(30 + i*45) t.hideturtle()
4.圖4
第四個(gè)圖是16葉花,怎么通過調(diào)整8葉花代碼,繪制出如下圖形?
具體代碼如下:
t.clearscreen() #第四幅圖 for i in range(16): w_sg3(30 + i*30) t.hideturtle() t.goto(0, -3) t.color('white') t.begin_fill() t.circle(6, 360) t.end_fill()
5.圖5
第五個(gè)圖是小太陽,怎么通過調(diào)整8葉花代碼,繪制出如下圖形?
具體代碼如下:
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫對稱圖形 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' import os import time import pygame import turtle as t t.title('阿黎逸陽的代碼公眾號') t.speed(10) t.setup(startx=0, starty = 0, width=800, height = 600) #第五幅圖 def w_sg3(theta): t.color('red') t.begin_fill() t.setheading(theta) t.circle(80, 50) t.left(130) t.circle(80, 50) t.end_fill() for i in range(24): w_sg3(30 + i*15) t.hideturtle()
6.圖6
第六個(gè)圖是陰陽圖。
具體代碼如下:
# -*- coding: UTF-8 -*- ''' 代碼用途 :畫對稱圖形 作者 :阿黎逸陽 博客 : https://blog.csdn.net/qq_32532663/article/details/106176609 ''' import os import time import pygame import turtle as t t.title('阿黎逸陽的代碼公眾號') t.speed(10) t.setup(startx=0, starty = 0, width=800, height = 600) #陰陽圖 def w_sg4(): t.color('black') t.begin_fill() t.circle(80, 360) t.end_fill() t.color('black', 'white') t.begin_fill() t.circle(80, 180) t.circle(40, 180) t.circle(-40, 180) t.end_fill() t.penup() t.goto(0, 130) t.pendown() t.begin_fill() t.color('black') t.circle(8, 360) t.end_fill() t.penup() t.goto(0, 130-90) t.pendown() t.begin_fill() t.color('white') t.circle(8, 360) t.end_fill() t.hideturtle() w_sg4()
到此這篇關(guān)于Python+turtle繪制對稱圖形的示例代碼的文章就介紹到這了,更多相關(guān)Python turtle繪制對稱圖形內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python進(jìn)階教程之函數(shù)參數(shù)的多種傳遞方法
這篇文章主要介紹了python進(jìn)階教程之函數(shù)參數(shù)的多種傳遞方法,包括關(guān)鍵字傳遞、默認(rèn)值傳遞、包裹位置傳遞、包裹關(guān)鍵字混合傳遞等,需要的朋友可以參考下2014-08-08淺談python的dataframe與series的創(chuàng)建方法
今天小編就為大家分享一篇淺談python的dataframe與series的創(chuàng)建方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11如何通過Python實(shí)現(xiàn)RabbitMQ延遲隊(duì)列
這篇文章主要介紹了如何通過Python實(shí)現(xiàn)RabbitMQ延遲隊(duì)列,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11Python中函數(shù)的多種格式和使用實(shí)例及小技巧
這篇文章主要介紹了Python中函數(shù)的多種格式和使用實(shí)例及小技巧,本文講解了普通格式、帶收集位置參數(shù)的函數(shù)、帶收集關(guān)鍵字參數(shù)的函數(shù)、函數(shù)特殊用法、內(nèi)嵌函數(shù)和閉包等內(nèi)容,需要的朋友可以參考下2015-04-04Django視圖之ORM數(shù)據(jù)庫查詢操作API的實(shí)例
下面小編就為大家?guī)硪黄狣jango視圖之ORM數(shù)據(jù)庫查詢操作API的實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10CodeWhisperer基于python使用經(jīng)驗(yàn)分享
這篇文章主要為大家介紹了CodeWhisperer基于python使用經(jīng)驗(yàn)分享,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11