用python画漂亮图-用Python画一些漂亮图形--Quora代码赏析

我在逛Quora的时候发现这么一个问题:

What is the most beautiful program you ever coded in Python?

有网友分享了自己用turtle或者pylab画出来的酷炫图形。

前两个是用turtle画的动态图(简书可以传动图吗?),第三个是用pylab画的静态图,原来用pylab也能画出这么多彩的图形。

from turtle import*

from time import sleep

title("fanatic")

bgcolor("white")

speed(0)

ht()

pu()

goto(-400,0)

pd()

tracer(False)

L=["green","yellow"]

for i in range(5,101,2):

for j in range(i):

for z in range(40):

pencolor(L[z%2])

fd(20)

rt(180-180/i)

tracer(True)

sleep(0.03)

tracer(False)

clear()

'''

5d8123d589fc

效果图

'''

from turtle import *

from random import randint

speed(0)

bgcolor('white')

x = 1

while x < 400:

r = randint(0,255) #让颜色随机变化

g = randint(0,255)

b = randint(0,255)

colormode(255)

pencolor(r,g,b) # 根据r,g,b的值改变笔触颜色

fd(50 + x)

rt(90.911)

x = x+1

exitonclick()

'''

5d8123d589fc

效果图

'''

from pylab import *

from numpy import NaN

def m(a):

z = 0

for n in range(1, 100):

z = z**2 + a

if abs(z) > 2:

return n

return NaN

X = arange(-2, .5, .002)

Y = arange(-1, 1, .002)

Z = zeros((len(Y), len(X)))

for iy, y in enumerate(Y):

print (iy, "of", len(Y))

for ix, x in enumerate(X):

Z[iy,ix] = m(x + 1j * y)

imshow(Z, cmap = plt.cm.prism, interpolation = 'none', extent = (X.min(), X.max(), Y.min(), Y.max()))

xlabel("Re(c)")

ylabel("Im(c)")

savefig("mandelbrot_python.png")

show()

'''

5d8123d589fc

效果图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值