Paint a leaf with python turtle

参考博文:

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()

 

转载于:https://www.cnblogs.com/kusong/p/4894223.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值