python画雪景

简单的random库配合海龟库画一个彩色雪景

# SnowViewcolorful.py雪景
from turtle import *
from random import *


def drawSnow():#画雪花
    hideturtle()
    pensize(2)
    for i in range(100):
        r, g, b = random(), random(), random()#多彩
        pencolor(r,g,b)
        
        penup()
        setx(randint(-350,350))#修改画笔横坐标
        sety(randint(1,270))#修改画笔纵坐标
        pendown()

        dens = randint(10,14)
        snowsize = randint(10,14)#雪花边长
        for j in range(dens):
            forward(snowsize)
            backward(snowsize)
            right(360/dens)

def drawGround():#画雪地
    hideturtle()
    for i in range(400):
        pensize(randint(5,10))
        x = randint(-400,350)
        y = randint(-280,-1)
        r, g, b = -y/280, -y/280, -y/280#白色逐渐变深
        pencolor((r,g,b))

        penup()
        goto(x,y)
        pendown()

        forward(randint(40,100))
setup(800,600,200,200)
tracer(2)
bgcolor("black")
drawSnow()
drawGround()
done()

运行截图:
在这里插入图片描述

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页