Python&Matlab實(shí)現(xiàn)櫻花的繪制
1.錦短情長(zhǎng)
為什么選擇這個(gè)標(biāo)題,借鑒了一封情書里面的情長(zhǎng)紙短,還吻你萬(wàn)千。
錦短情長(zhǎng)
都只謂人走茶涼,怎感覺(jué)錦短情長(zhǎng)?
一提起眼淚汪汪,是明月人心所向?
2. 一場(chǎng)櫻花雨(Matlab)
function pingba hold on,axis equal axis(0.5+[-10,50,0,50]) set(gca,'xtick',[],'ytick',[],'xcolor','w','ycolor','w') set(gca,'color',[0.5020 0.5020 0.5020]) length_trunk=6; width_trunk=4; k1=0.9; k2=0.8; number_branch=15; alp=pi/10; length_branch=k1*length_trunk; width_branch=k2*width_trunk; trunk=[12,0;12,length_trunk]; plot(trunk(:,1),trunk(:,2),'color',[0 0 0],'Linewidth',width_trunk) begins=[trunk(2,:),pi/2,1]; grow=begins; plotdata=[0 0 0 0 0 0 0 0]; plotdata(1,:)=[]; for i=1:number_branch control=randi(25,[length(grow(:,1)),1])>=10; ag=grow(:,3); l=length(ag); parta=[length_branch.*k1.^grow(:,4).*cos(ag+ones(l,1)*alp),length_branch.*k1.^grow(:,4).*sin(ag+ones(l,1)*alp),ones(l,1)*alp,ones(l,1)]; partb=[length_branch.*k1.^grow(:,4).*cos(ag-ones(l,1)*alp),length_branch.*k1.^grow(:,4).*sin(ag-ones(l,1)*alp),-ones(l,1)*alp,ones(l,1)]; parta2=[0.8.*length_branch.*k1.^grow(:,4).*cos(ag),0.8.*length_branch.*k1.^grow(:,4).*sin(ag),zeros(l,1),ones(l,1)]; partb2=[0.8.*length_branch.*k1.^grow(:,4).*cos(ag),0.8.*length_branch.*k1.^grow(:,4).*sin(ag),zeros(l,1),ones(l,1)]; parta=control.*parta+(1-control).*parta2; partb=control.*partb+(1-control).*partb2; parta=parta+grow; partb=partb+grow; congress=[parta;partb]; grow=[grow;grow]; judge=[grow,congress]; judge=unique(judge,'rows'); grow=judge(:,5:end); plotdata=[plotdata;judge]; end for i=1:number_branch temp_w=width_branch*0.8^i; temp_branch=plotdata(plotdata(:,4)==i,:); plx=[temp_branch(:,1),temp_branch(:,5)]; ply=[temp_branch(:,2),temp_branch(:,6)]; plx=plx';ply=ply'; plot(plx,ply,'color',[0 0 0]+i*[0.3020 0.3020 0.3020]./number_branch,'Linewidth',temp_w) end bloom_pos=plotdata(plotdata(:,8)==number_branch+1,[5,6]); scatter(bloom_pos(:,1),bloom_pos(:,2),10,'CData',[0.8549 0.6824 0.6824]) bloom_pos=plotdata(plotdata(:,8)==number_branch,[5,6]); scatter(bloom_pos(:,1),bloom_pos(:,2),8,'CData',[0.7451 0.5961 0.5961].*0.97) end
3.櫻花樹(Python)
import turtle as T import random import time #=======畫櫻花的軀干(60,t)=============== T.title('凋落的櫻花') def Tree(branch, t): time.sleep(0.0005) if branch > 3: if 8 <= branch <= 12: if random.randint(0, 2) == 0: t.color('snow') # 白 else: t.color('lightcoral') # 淡珊瑚色 t.pensize(branch / 3) elif branch < 8: if random.randint(0, 1) == 0: t.color('snow') else: t.color('lightcoral') # 淡珊瑚色 t.pensize(branch / 2) else: t.color('sienna') # 赭(zhě)色 t.pensize(branch / 10) # 6 t.forward(branch) a = 1.5 * random.random() t.right(20 * a) b = 1.5 * random.random() Tree(branch - 10 * b, t) t.left(40 * a) Tree(branch - 10 * b, t) t.right(20 * a) t.up() t.backward(branch) t.down() #=============掉落的花瓣=================== def Petal(m, t): for i in range(m): a = 200 - 400 * random.random() b = 10 - 20 * random.random() t.up() t.forward(b) t.left(90) t.forward(a) t.down() t.color('lightcoral') # 淡珊瑚色 t.circle(1) t.up() t.backward(a) t.right(90) t.backward(b) #=======繪圖區(qū)域============ t = T.Turtle() # 畫布大小 w = T.Screen() t.hideturtle() # 隱藏畫筆 t.getscreen().tracer(5, 0) w.screensize(bg='wheat') # wheat小麥 t.left(90) t.up() t.backward(150) t.down() t.color('sienna') #=====畫櫻花的軀干=========== Tree(60, t) # 掉落的花瓣 Petal(200, t) w.exitonclick()
到此這篇關(guān)于Python&Matlab實(shí)現(xiàn)櫻花的繪制的文章就介紹到這了,更多相關(guān)Python Matlab櫻花內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python爬蟲實(shí)戰(zhàn):分析《戰(zhàn)狼2》豆瓣影評(píng)
這篇文章主要介紹了Python爬蟲實(shí)戰(zhàn):《戰(zhàn)狼2》豆瓣影評(píng)分析,小編在這里使用的是python版本3.5,需要的朋友可以參考下2018-03-03Python使用三種方法實(shí)現(xiàn)PCA算法
這篇文章主要介紹了Python使用三種方法實(shí)現(xiàn)PCA算法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12Python range、enumerate和zip函數(shù)用法詳解
這篇文章主要介紹了Python range、enumerate和zip函數(shù)用法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09解決Mac下首次安裝pycharm無(wú)project interpreter的問(wèn)題
今天小編就為大家分享一篇解決Mac下首次安裝pycharm無(wú)project interpreter的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10Python模擬登陸網(wǎng)頁(yè)的三種方法小結(jié)
如何使用Python模擬登陸網(wǎng)頁(yè),尤其是在涉及到復(fù)雜的認(rèn)證機(jī)制時(shí)?這篇文章將詳細(xì)介紹Python模擬登陸網(wǎng)頁(yè)的三種方法,以及如何繞過(guò)一些常見(jiàn)的安全防護(hù)措施,需要的朋友可以參考下2024-01-01Python基于pygame實(shí)現(xiàn)圖片代替鼠標(biāo)移動(dòng)效果
這篇文章主要介紹了Python基于pygame實(shí)現(xiàn)圖片代替鼠標(biāo)移動(dòng)效果,可實(shí)現(xiàn)將鼠標(biāo)箭頭轉(zhuǎn)換成圖形的功能,涉及pygame圖形操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11使用django實(shí)現(xiàn)一個(gè)代碼發(fā)布系統(tǒng)
這篇文章主要介紹了使用django實(shí)現(xiàn)一個(gè)代碼發(fā)布系統(tǒng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07python圖形繪制奧運(yùn)五環(huán)實(shí)例講解
在本文里我們給大家整理了一篇關(guān)于python圖形繪制奧運(yùn)五環(huán)的實(shí)例內(nèi)容,大家可以跟著學(xué)習(xí)下。2019-09-09python的?PyPDF2實(shí)現(xiàn)pdf文件切割和合并
大家好,本篇文章主要講的是python的?PyPDF2實(shí)現(xiàn)pdf文件切割和合并,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下2022-02-02