码迷,mamicode.com
首页 > 编程语言 > 详细

Paint a leaf with python turtle

时间:2015-10-20 11:49:52      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

参考博文:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!