日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

圣诞树代码版

發布時間:2024/3/12 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 圣诞树代码版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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=30j
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=30j
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() # 完成,否則會直接關閉

總結

以上是生活随笔為你收集整理的圣诞树代码版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。