这个梅有背景,有配图,还有古诗,虽有点空荡,但十分好看!我用了random库和函数把它做出来。
代码:
from turtle import *
from random import *
def drawSnow():
pensize(2)
for i in range(20):
pencolor("white")
penup()
setx(randint(-640, 640))
sety(randint(-400, 400))
pendown()
dens = randint(8, 12)
snowsize = randint(10, 14)
for j in range(dens):
forward(snowsize)
backward(snowsize)
right(360/dens)
def gotopos(x, y):
up()
goto(x, y)
down()
ht()
def apply_rules(path, rules):
L = [_ for _ in path]
for i in range(len(L)):
symbol = L[i]
if symbol == 'F':
L[i] = rules[symbol]
if symbol == 'X':
L[i] = rules