如何用python画雪人_能力橙少儿编程 - 学员作品 - Python作品-雪人(可变位置和大小)...

import turtle

import math

from random import uniform

#准备:

t = turtle.Turtle() #这个变量在定义函数时也可用

t.reset()

t.tracer(0)

x = float(input(\"Please input the X-axis of the graph\"))

y = float(input(\"Please input the Y-axis of the graph\"))

size = float(input(\"Please input the size of this graph\"))

side = math.sqrt(size**2/2.0)

#画圆:

def draw_circle(diameter,x,y,color,fill=\"fill\"):

t.pu()

t.goto(x,y-diameter/2)

t.pd()

t.color(color)

if fill == \"fill\":

t.begin_fill()

t.circle(diameter/2)

if fill == \"fill\":

t.end_fill()

#科赫雪花:

def koch(level,size):

if(level==0):

t.forward(size)

else:

new_size = size/3

koch(level-1,new_size)

t.left(60)

koch(level-1,new_size)

t.right(120)

koch(level-1,new_size)

t.left(60)

koch(level-1,new_size)

#背景:

draw_circle(side,x,y,\"#69D9FF\",\"fill\")

#雪花:

#定义

def draw_snow(size,x,y,color,fill=\"fill\"):

tside = math.sqrt(3)

side = size/4*3/tside*2

t.color(color)

t.pu()

t.goto(x-side/2,y-size/4)

t.pd()

level = 3

if fill == \"fill\" :

t.begin_fill()

for a in range(3):

koch(3,side)

t.rt(120)

if fill == \"fill\" :

t.end_fill()

#绘图

for a in range(70):

x1 = uniform(x-side/2,x+side/2)

y1 = uniform(y-side/2,y+side/2)

side1 = uniform(side/45,side/22.5)

draw_snow(side1,x1,y1,\"white\")

#雪人:

#身体

for a in range(3):

if a == 0: s = side/1.8 ; y2 = y-side/2.4/2

if a == 1: s = side/3 ; y2 = y+side/3./2

if a == 2: s = side/3.6 ; y2 = y+side/1.44/2

draw_circle(s,x,y2,\"white\",\"fill\")

#脸

for a in range(2):

if a == 0: b = -1

else : b = 1

draw_circle(side/30,x+side/12/2*b,y+side/180*145/2,\"black\",\"fill\")

for a in range(2):

if a == 0: color = \"red\" ; y3 = y+side/1.5/2

else : color = \"white\" ; y3 = y+side/1.44/2

draw_circle(side/18,x,y3,color,\"fill\")

#扣子

v = 50

for a in range(5):

draw_circle(side/36,x,y+side/180*v/2,\"black\")

v -= 40

#手

for a in range(2):

if a == 0: b = -1

else : b = 1

t.pu()

t.goto(x+side/4.5/2*b,y+side/2.25/2)

t.pd()

t.color(\"brown\")

t.lt(-140*b)

t.pensize(side/36/2)

t.fd(-side/3/2*b)

t.bk(-side/9/2*b)

t.lt(-60*b)

t.fd(-side/9/2*b)

t.bk(-side/9/2*b)

t.right(-120*b)

t.fd(-side/9/2*b)

t.rt(-80*b)

t.ht()

t.update()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值