python做玫瑰
① python音樂可視化:好玩的matplotlib南丁格爾玫瑰圖版
效果圖:
操作演示:
技術要點:
1 matplotlib的南丁格爾玫瑰圖,用極坐標polar製作,並動畫顯示。
2 pygame新版的播放mp3,但本機的操作系統不能播放mp3,我用pyb做些格式轉換。
3 用librosa獲取音樂的相關數據和采樣。
4 參考代碼,並對源代碼進行修改,增加,刪減,排版和注釋,感謝原作者,如有侵權,請聯系,定刪除。
====下面分步,講解代碼====
第1步:模塊導入
第2步:窗口的初始化設置
第3步:參數設置
第4步:核心代碼:
第5步:filter類
第6步:函數定義
第7步:啟動主函數
自己整理,分享出來,希望大家喜歡。
② 怎麼用python畫玫瑰花,求大神貼代碼,感激不盡
importturtle
#設置初始位置
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
#花蕊
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)
運行結果:
③ python怎麼畫玫瑰花
操縱海龜繪圖有著許多的命令,這些命令可以劃分為兩種:一種為運動命令,一種為畫筆控制命令
1. 運動命令:
forward(degree) #向前移動距離degree代表距離
backward(degree) #向後移動距離degree代表距離
right(degree) #向右移動多少度
left(degree) #向左移動多少度
goto(x,y) #將畫筆移動到坐標為x,y的位置
stamp() #復制當前圖形
speed(speed) #畫筆繪制的速度范圍[0,10]整數
2. 畫筆控制命令:
down() #移動時繪制圖形,預設時也為繪制
up() #移動時不繪制圖形
pensize(width) #繪制圖形時的寬度
color(colorstring) #繪制圖形時的顏色
fillcolor(colorstring) #繪制圖形的填充顏色
fill(Ture)
fill(false)
lucy : 夢想照進現實;露茜;青春風采;
draw_flower1.py
[python]view plain
#-*-coding:cp936-*-
importturtle
importmath
defp_line(t,n,length,angle):
"""Drawsnlinesegments."""
foriinrange(n):
t.fd(length)
t.lt(angle)
defpolygon(t,n,length):
"""Drawsapolygonwithnsides."""
angle=360/n
p_line(t,n,length,angle)
defarc(t,r,angle):
"""."""
arc_length=2*math.pi*r*abs(angle)/360
n=int(arc_length/4)+1
step_length=arc_length/n
step_angle=float(angle)/n
#Beforestartingreces,makingaslightleftturn.
t.lt(step_angle/2)
p_line(t,n,step_length,step_angle)
t.rt(step_angle/2)
defpetal(t,r,angle):
"""Drawsa花瓣usingtwoarcs."""
foriinrange(2):
arc(t,r,angle)
t.lt(180-angle)
defflower(t,n,r,angle,p):
"""Drawsaflowerwithnpetals."""
foriinrange(n):
petal(t,r,angle)
t.lt(p/n)
defleaf(t,r,angle,p):
"""Drawsa葉子andfillit."""
t.begin_fill()#Beginthefillprocess.
t.down()
flower(t,1,40,80,180)
t.end_fill()
defmain():
window=turtle.Screen()#creatascreen
window.bgcolor("blue")
lucy=turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(5)
lucy.speed(0)
#Drawingflower
flower(lucy,7,60,100,360)
#Drawingpedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200)
#Drawingleaf
lucy.rt(270)
lucy.color("green")
leaf(lucy,40,80,180)
lucy.ht()
window.exitonclick()
main()
④ 用Python matplotlib 怎麼畫風向玫瑰圖 能給出程序的
importnumpyasnp
importmatplotlib.pyplotasplt
N=20
theta=np.linspace(0.0,2*np.pi,N,endpoint=False)
radii=10*np.random.rand(N)
width=np.pi/4*np.random.rand(N)
ax=plt.subplot(111,projection='polar')
bars=ax.bar(theta,radii,width=width,bottom=0.0)
#Usecustomcolorsandopacity
forr,barinzip(radii,bars):
bar.set_facecolor(plt.cm.jet(r/10.))
bar.set_alpha(0.5)
plt.show()
差不多上面代碼的原理,具體的自己照著官方文檔改
⑤ 求編寫一個表白程序
JAVA
傳說中規范的愛情代碼(2010-11-10 21:37:36)
轉載
標簽:it
private final static DEPOSIT = 100000;
private final static FELLING = 8;
public void love(boy, girl) {
Boolean isMarried = false;
if(boy.有房() &&boy.有車()) {
doMarry(boy, girl);
isMarried = true;
} else if(girl.願意等()) {
while(!(boy.賺錢 > DEPOSIT && girl.感情 > FELLING)) {
for(int day=1; day <=365; day++) {
if( day == 情人節 ) {
if(boy.givegirl(玫瑰)) {
girl.感情++;
} else {
girl.感情--;
}
}
if(day == girl.生日) {
if( boy.givegirl(玫瑰) )
{
girl.感情++;
}
else {
girl.感情--;
boy.拚命賺錢();
}
}
}
if(boy.有房() && boy.有車()) {
doMarry(boy, girl);
isMarried = true;
break;
}
年齡++;
girl.感情--;
}
}
if(!IsMarried) {
girl.goto(another_boy);
}
private void doMarry(boy, girl) {
boy.set(nothing);
girl.嫁給(boy);
}