栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

圣诞树代码版

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

圣诞树代码版

from turtle import *
import random as r
import time
import turtle
screensize(bg=‘black’)
color(“orange”, “yellow”)
begin_fill()
left(126)
screen=turtle.Screen()
screen.setup(375,700)
circle=turtle.Turtle()
circle.shape(‘circle’)
circle.color(‘red’)
circle.speed(‘fastest’)
circle.up()
square=turtle.Turtle()
square.shape(‘square’)
square.color(‘green’)
square.speed(‘fastest’)
square.up()
circle.goto(0,280)
circle.stamp()
k=0
for i in range(1,13):
y=30i
for j in range(i-k):
x=30
j
square.goto(x,-y+280)
square.stamp()
square.goto(-x,-y+280)
square.stamp()
if i%4==0:
x=30*(j+1)
circle.color(‘red’)
circle.goto(-x,-y+280)
circle.stamp()
circle.goto(x,-y+280)
circle.stamp()
k+=3
if i%4 ==3:
x=30*(j+1)
circle.color(‘yellow’)
circle.goto(-x,-y+280)
circle.stamp()
circle.goto(x,-y+280)
circle.stamp()
square.color(‘brown’)
for i in range(13,17):
y=30i
for j in range(2):
x=30
j
square.goto(x,-y+ 280)
square.stamp()
square.goto(-x,-y+280)
square.stamp()

turtle.color(“dark red”,“red”)#定义字体颜色
turtle.write(“Merry Christmas”,align =“center”,font=(“Comic Sans MS”,40,“bold”))#定义文字、位置、字体、大小

def drawsnow():#定义画雪花的方法
turtle.ht() #隐藏笔头,ht=hideturtle
turtle.pensize(2) #定义笔头大小
for i in range(200): #画多少雪花
turtle.pencolor(“white”) #定义画笔颜色为白色,其实就是雪花为白色
turtle.pu() #提笔,pu=penup
turtle.setx(r.randint(-350,350)) #定义x坐标,随机从-350到350之间选择
turtle.sety(r.randint(-100,350)) #定义y坐标,注意雪花一般在地上不会落下,所以不会从太小的纵座轴开始
turtle.pd() #落笔,pd=pendown
dens = 6 #雪花瓣数设为6
snowsize = r.randint(1,10) #定义雪花大小
for j in range(dens): #就是6,那就是画5次,也就是一个雪花五角星
#t.forward(int(snowsize)) #int()取整数
turtle.fd(int(snowsize))
turtle.backward(int(snowsize))
#t.bd(int(snowsize)) #注意没有bd=backward,但有fd=forward,小bug
turtle.right(int(360/dens)) #转动角度

drawsnow()#调用画雪花的方法
turtle.done() # 完成,否则会直接关闭

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/664257.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号