标签:
参考博文:
http://biancheng.dnbcw.info/python/443280.html
https://docs.python.org/2/library/turtle.html?highlight=turtle#turtle.speed
效果图:
code:
import turtle as tt import numpy as ny import random x = ny.array([[.5],[.5]]) p = [.85,.92,.99,1.00] A1 = ny.array([[.85,.04], [-0.04,.85]]) A2 = ny.array([[.2,-0.26], [.23,.22]]) A3 = ny.array([[-0.15,.28], [.26,.24]]) A4 = ny.array([[0,0], [0,.16]]) b1 = b2 = ny.array([[0],[1.6]]) b3 = ny.array([[0],[.44]]) cnt = 1 while 1: cnt += 1 if cnt == 2000: break r = random.random() if(r<p[0]): x = ny.dot(A1,x)+b1 elif(r<p[1]): x = ny.dot(A2,x)+b2 elif(r<p[2]): x = ny.dot(A3,x)+b3 else: x = ny.dot(A4,x) tt.up() tt.goto(x[0][0]*50,x[1][0]*40-240) tt.down() tt.speed(0) tt.dot() tt.mainloop()
Paint a leaf with python turtle
标签:
原文地址:http://www.cnblogs.com/kusong/p/4894223.html