母亲节快到了,用python绘制一株简单好看的康乃馨叭
Posted slandarer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了母亲节快到了,用python绘制一株简单好看的康乃馨叭相关的知识,希望对你有一定的参考价值。
绘制效果:
此代码源自:
https://my.numworks.com/python/apocaliips/carnation
网站 apocaliips 的代码
其代码旨在宣传 kandinsky 函数库
本人将其使用大家更常用的 matplotlib库进行改写,以下是完整代码:
import matplotlib.pyplot as plt
import matplotlib.patches as patches
rects = [
(137,65,34,4,(124,30,31)),(167,69,16,4,(124,30,31)),(133,98,21,4,(124,30,31)),
(150,94,17,4,(124,30,31)),(162,89,5,5,(124,30,31)),(167,85,12,5,(124,30,31)),
(167,98,16,4,(124,30,31)),(179,90,4,8,(124,30,31)),(183,90,13,4,(124,30,31)),
(192,82,4,8,(124,30,31)),(184,82,8,3,(124,30,31)),(167,77,21,5,(124,30,31)),
(171,73,4,4,(124,30,31)),(179,73,4,4,(124,30,31)),(175,82,4,3,(124,30,31)),
(133,69,4,13,(124,30,31)),(125,82,4,12,(124,30,31)),(129,90,21,4,(124,30,31)),
(133,94,4,4,(124,30,31)),(129,77,4,9,(124,30,31)),(142,82,8,4,(124,30,31)),
(142,73,16,4,(124,30,31)),(154,69,9,4,(124,30,31)),(154,77,9,5,(124,30,31)),
(158,82,9,4,(124,30,31)),(150,86,8,4,(124,30,31)),(142,69,4,4,(124,30,31)),
(137,77,6,5,(124,30,31)),(137,94,13,4,(245,42,44)),(150,90,12,4,(245,42,44)),
(129,86,21,4,(245,42,44)),(133,82,9,4,(245,42,44)),(137,69,5,8,(245,42,44)),
(146,69,8,4,(245,42,44)),(143,77,11,5,(245,42,44)),(150,82,8,4,(245,42,44)),
(158,73,13,4,(245,42,44)),(163,77,4,5,(245,42,44)),(163,69,4,4,(245,42,44)),
(175,73,4,4,(245,42,44)),(179,82,5,8,(245,42,44)),(184,85,8,5,(245,42,44)),
(167,90,12,8,(245,42,44)),(167,82,8,3,(245,42,44)),(158,86,9,3,(245,42,44)),
(158,89,4,1,(245,42,44)),(150,102,4,13,(15,65,23)),(167,102,3,9,(15,65,23)),
(162,111,5,8,(15,65,23)),(154,111,4,8,(15,65,23)),(158,119,4,92,(15,65,23)),
(138,120,5,5,(15,65,23)),(143,123,7,2,(15,65,23)),(142,125,2,11,(15,65,23)),
(179,119,4,4,(15,65,23)),(177,123,2,12,(15,65,23)),(171,123,6,2,(15,65,23)),
(171,125,1,4,(15,65,23)),(173,135,6,1,(15,65,23)),(162,141,9,3,(15,65,23)),
(167,129,5,1,(15,65,23)),(162,136,5,1,(15,65,23)),(167,130,1,7,(15,65,23)),
(171,135,2,9,(15,65,23)),(149,125,5,2,(15,65,23)),(150,141,8,3,(15,65,23)),
(152,134,6,2,(15,65,23)),(142,136,8,1,(15,65,23)),(152,127,2,7,(15,65,23)),
(148,137,2,7,(15,65,23)),(154,98,13,13,(23,146,51)),(158,111,4,8,(23,146,51)),
(172,125,5,10,(23,146,51)),(168,130,4,5,(23,146,51)),(168,135,3,6,(23,146,51)),
(162,137,6,4,(23,146,51)),(150,136,8,5,(23,146,51)),(144,125,5,11,(23,146,51)),
(149,127,3,9,(23,146,51)),
]
fig1 = plt.figure()
ax1 = fig1.add_subplot(111, aspect='equal')
plt.xlim(70,250)
plt.ylim(20,240)
for r in rects:
ax1.add_patch(
patches.Rectangle(
(r[0], 250-r[1]), # (x,y)
width = r[2], # width
height = -r[3], # height
facecolor =
(r[4][0]/255,r[4][1]/255,r[4][2]/255),# color
)
)
plt.pause(0.01)
plt.show()
以上是关于母亲节快到了,用python绘制一株简单好看的康乃馨叭的主要内容,如果未能解决你的问题,请参考以下文章
七夕节快到了,教你用MATLAB绘制blingbling的大钻石