Python turtle太牛了,居然可以画树,画的栩栩如生,简直无敌了。 画了多些支叶,然后随便按支条方向给光照效果。
from turtle import * from random import * from math import * def tree(n, l): pd() t = cos(radians(heading() + 45)) / 8 + 0.25 pencolor(t, t, t) pensize(n / 4) forward(l) if n > 0: b = random() * 15 + 10 c = random() * 15 + 10 d = l * (random() * 0.35 + 0.6) right(b) tree(n - 1, d) left(b + c) tree(n - 1, d) right(c) else: right(80) n = cos(radians(heading() - 45)) / 4 + 0.5 pencolor(n, n, n) circle(2) left(80) pu() backward(l) bgcolor(0.5, 0.5, 0.5) ht() speed(0) tracer(0, 0) left(90) pu() backward(300) tree(13, 100) done()