欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python&Matlab實現(xiàn)櫻花的繪制

 更新時間:2022年04月07日 17:04:25   作者:電力系統(tǒng)與算法之美  
正值櫻花飄落的季節(jié),本文將利用Python和Matlab分別繪制一顆櫻花樹,文中的示例代碼講解詳細,感興趣的小伙伴快跟隨小編一起動手嘗試一下

1.錦短情長

為什么選擇這個標題,借鑒了一封情書里面的情長紙短,還吻你萬千。

錦短情長

都只謂人走茶涼,怎感覺錦短情長?

一提起眼淚汪汪,是明月人心所向?

2. 一場櫻花雨(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()

到此這篇關于Python&Matlab實現(xiàn)櫻花的繪制的文章就介紹到這了,更多相關Python Matlab櫻花內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Python爬蟲實戰(zhàn):分析《戰(zhàn)狼2》豆瓣影評

    Python爬蟲實戰(zhàn):分析《戰(zhàn)狼2》豆瓣影評

    這篇文章主要介紹了Python爬蟲實戰(zhàn):《戰(zhàn)狼2》豆瓣影評分析,小編在這里使用的是python版本3.5,需要的朋友可以參考下
    2018-03-03
  • Python使用三種方法實現(xiàn)PCA算法

    Python使用三種方法實現(xiàn)PCA算法

    這篇文章主要介紹了Python使用三種方法實現(xiàn)PCA算法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Python range、enumerate和zip函數(shù)用法詳解

    Python range、enumerate和zip函數(shù)用法詳解

    這篇文章主要介紹了Python range、enumerate和zip函數(shù)用法詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • 解決Mac下首次安裝pycharm無project interpreter的問題

    解決Mac下首次安裝pycharm無project interpreter的問題

    今天小編就為大家分享一篇解決Mac下首次安裝pycharm無project interpreter的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • Python模擬登陸網(wǎng)頁的三種方法小結

    Python模擬登陸網(wǎng)頁的三種方法小結

    如何使用Python模擬登陸網(wǎng)頁,尤其是在涉及到復雜的認證機制時?這篇文章將詳細介紹Python模擬登陸網(wǎng)頁的三種方法,以及如何繞過一些常見的安全防護措施,需要的朋友可以參考下
    2024-01-01
  • Python基于pygame實現(xiàn)圖片代替鼠標移動效果

    Python基于pygame實現(xiàn)圖片代替鼠標移動效果

    這篇文章主要介紹了Python基于pygame實現(xiàn)圖片代替鼠標移動效果,可實現(xiàn)將鼠標箭頭轉換成圖形的功能,涉及pygame圖形操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-11-11
  • 使用django實現(xiàn)一個代碼發(fā)布系統(tǒng)

    使用django實現(xiàn)一個代碼發(fā)布系統(tǒng)

    這篇文章主要介紹了使用django實現(xiàn)一個代碼發(fā)布系統(tǒng),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-07-07
  • python圖形繪制奧運五環(huán)實例講解

    python圖形繪制奧運五環(huán)實例講解

    在本文里我們給大家整理了一篇關于python圖形繪制奧運五環(huán)的實例內容,大家可以跟著學習下。
    2019-09-09
  • python?列表的查詢操作和切片

    python?列表的查詢操作和切片

    這篇文章主要介紹了python?列表的查詢操作和切片,列表是python內置的數(shù)據(jù)結構,相當于數(shù)組,列表中所有數(shù)據(jù)都是按順序有序排列,列表屬于序列類型,接下來一起學習下面的文章內容吧
    2022-01-01
  • python的?PyPDF2實現(xiàn)pdf文件切割和合并

    python的?PyPDF2實現(xiàn)pdf文件切割和合并

    大家好,本篇文章主要講的是python的?PyPDF2實現(xiàn)pdf文件切割和合并,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02

最新評論