Commit 924e2ae9 by BellCodeEditor

auto save

parent ef7dc539
Showing with 92 additions and 0 deletions
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
# 创建figure窗口及axes坐标区域
fig = plt.figure()
ax = plt.axes(projection='3d')
# 构造玫瑰花曲面
x = np.linspace(0, 1, 200)
theta = np.linspace(-2*np.pi, 15*np.pi, 300)
[x, theta]=np.meshgrid(x, theta)
phi = (np.pi/2)*np.exp(-theta/8/np.pi)
X = 1-.5*pow(1.25*pow(1-np.mod(3.6*theta,2*np.pi)/np.pi, 2)-1/4, 2)
y = 1.95653*pow(x, 2)*pow(1.27689*x-1,2)*np.sin(phi)
r = X*(x*np.sin(phi)+y*np.cos(phi))
h = X*(x*np.cos(phi)-y*np.sin(phi))
# 设置颜色并绘制曲面
c = cm.get_cmap('magma')
surf = ax.plot_surface(r * np.cos(theta), r * np.sin(theta), h, rstride=1, cstride=1,
cmap= c, linewidth=0, antialiased=True)
# 减小空白区域并绘图
ax.set_position((0,0,1,1))
plt.show()
import turtle,random
def tree(branchLen,t):
if branchLen > 3:
if 8<= branchLen <=12:
if random.randint(0,2) == 0:
t.color('snow')
else:
t.color('lightcoral')
t.pensize(branchLen / 3)
elif branchLen < 8:
if random.randint(0,1) == 0:
t.color('snow')
else:
t.color('lightcoral')
t.pensize(branchLen / 2)
else:
t.color('sienna')
t.pensize(branchLen / 10)
t.forward(branchLen)
a = 1.5 * random.random()
t.right(20*a)
b = 1.5 * random.random()
tree(branchLen-10*b, t)
t.left(40*a)
tree(branchLen-10*b, t)
t.right(20*a)
t.up()
t.backward(branchLen)
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('pink')
t.circle(1)
t.up()
t.backward(a)
t.right(90)
t.backward(b)
def main():
t = turtle.Turtle()
w = turtle.Screen()
t.hideturtle()
turtle.getscreen().tracer(5, 0)
w.screensize(bg='wheat')
t.left(90)
t.up()
t.backward(150)
t.down()
t.color('sienna')
tree(60,t)
petal(200,t)
w.exitonclick()
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment