如何在Python 3中使用枕头生成一个分形树图片

  介绍

这篇文章给大家介绍如何在Python 3中使用枕头生成一个分形树图片,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

该程序通过绘制树干(最初是树,后来是树枝)并递归地添加树来绘制“树”。使用枕头。

利用递归函数绘制分形树(分形树),分形几何学的基本思想:客观事物具有自相似的层次结构,局部与整体在形态,功能,信息,时间,空间等方面具有统计意义上的相似性,成为自相似性。自相似性是指局部是整体成比例缩小的性质。

版本:Python 3

#, Adapted 得到http://rosettacode.org/wiki/Fractal_tree Python   #,用parameterise,以及add 色彩。   #,http://pillow.readthedocs.org/作者:#还以为,Alan 里士满,Python3.codes,,以及others  (Rosettacode)   import 数学,colorsys   得到PIL  import 形象,ImageDraw   spread =, 17岁,,,,,#,请,much  branches  spread 分开   宽度,,height =, 1000,, 800, #, window 大小   maxd =, 12,,,,, #, maximum  recursion 深度   len  9.0=,,,,,, #, branch  length 因素   #,http://pillow.readthedocs.org/en/latest/reference/Image.html   时间=img  Image.new (& # 39; rgb # 39;,,(宽度,高度))   #,http://pillow.readthedocs.org/en/latest/reference/ImageDraw.html   时间=d  ImageDraw.Draw (img)   #,却;能够function  calls  itself 用add 点子树   def  drawTree (x1, y1,,角度,深度):   ,if  depth 和gt;, 0:   ,,#,compute 却;能够分支# 39;s  next 端点   时间=x2 才能;x1  +, int (math.cos (math.radians(角),*,depth  *, len)   时间=y2 才能;y1  +, int (sin (math.radians(角),*,depth  *, len)   #才能,https://docs.python.org/2/library/colorsys.html   ,,(r, g, b),=, colorsys.hsv_to_rgb(浮动(深度),/,maxd,, 1.0, 1.0)   ,,R, G, B =, int (255, *, R), int (255, *, G), int (255, *, b)   #,才能draw 从而分支   d.line才能((x1, y1, x2, y2),, (R, G, B),,深度)   #,才能,以及append  2, trees  by 递归   drawTree才能(x2, y2,, angle 作用;蔓延,,depth 作用;1)   drawTree才能(x2, y2,, angle  +,蔓延,,depth 作用;1)   #,Start 画!   drawTree(时间/width  2, height  *, 0.9, -90年,maxd)   img.show ()   img.save (“www.linuxidc.com.png",“PNG")

关于如何在Python 3中使用枕头生成一个分形树图片就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。

如何在Python 3中使用枕头生成一个分形树图片