python代码画樱花带图⽚_python编程——pygame画樱花树先来看看效果:
是不是很好看呢?现在我们来编程吧。
import pygame,random#⾸先导⼊pygame、random模块
pygame.init()
screen = pygame.display.set_mode([640,480])#绘制⼀个长640,宽480的窗⼝
screen.fill([0,0,0])#以⿊⾊填充屏幕
x = 320
y = 530
size = 50
for tree in range(200):
y = y - 1
x = x - 0.2
size = size - 0.1
my_tree = (screen,[134,78,2],[x,y,size,size],0)#画出主树⼲
size = 30
for tree in range(180):
y = y - 1
x = x + 0.5
size = size - 0.15
my_tree = (screen,[134,78,2],[x,y,size,size],0)#剩下的画出不同的树枝
x = 280
y = 330
size = 15
for tree in range(180):
y = y - 1
x = x - 0.4
size = size - 0.05
my_tree = (screen,[134,78,2],[x,y,size,size],0)
x = 270
y = 180
size = 10
for tree in range(50):
y = y - 1
x = x + 1.5
size = size - 0.05
my_tree = (screen,[134,78,2],[x,y,size,size],0) x = 280
y = 310
size = 15
for tree in range(150):
y = y - 1
x = x - 1
size = size - 0.05
my_tree = (screen,[134,78,2],[x,y,size,size],0) x = 180
y = 210
size = 10
for tree in range(50):
y = y + 0.3
x = x - 1
size = size - 0.05
my_tree = (screen,[134,78,2],[x,y,size,size],0) x = 240
y = 230
size = 12
for tree in range(80):
y = y - 1.5
x = x + 1
size = size - 0.1
my_tree = (screen,[134,78,2],[x,y,size,size],0) f_x = 0
f_y = 0
colour_R = 0
colour_G = 0
colour_B = 0
for flower in range(250):#画出樱花
f_x = random.randint(250,350)
f_y = random.randint(100,300)
colour_R = random.randint(254,255)
colour_G = random.randint(103,255)
colour_B = random.randint(205,255)
my_flower = pygame.draw.circle(screen,[colour_R,colour_G,colour_B],[f_x,f_y],5,1) for flower in range(130):
f_x = random.randint(350,450)
f_y = random.randint(130,250)
colour_R = random.randint(254,255)
colour_G = random.randint(103,255)
colour_B = random.randint(205,255)
my_flower = pygame.draw.circle(screen,[colour_R,colour_G,colour_B],[f_x,f_y],5,1) for flower in range(130):
f_x = random.randint(150,250)
f_y = random.randint(130,250)
colour_R = random.randint(254,255)
colour_G = random.randint(103,255)
colour_B = random.randint(205,255)
my_flower = pygame.draw.circle(screen,[colour_R,colour_G,colour_B],[f_x,f_y],5,1) for flower in range(80):
f_x = random.randint(200,250)
python新手代码画图f_y = random.randint(200,300)
colour_R = random.randint(254,255)
colour_G = random.randint(103,255)
colour_B = random.randint(205,255)
my_flower = pygame.draw.circle(screen,[colour_R,colour_G,colour_B],[f_x,f_y],5,1) for flower in range(80):
f_x = random.randint(400,500)
f_y = random.randint(100,200)
colour_R = random.randint(254,255)
colour_G = random.randint(103,255)
colour_B = random.randint(205,255)
my_flower = pygame.draw.circle(screen,[colour_R,colour_G,colour_B],[f_x,f_y],5,1)
for flower in range(80):
f_x = random.randint(100,200)
f_y = random.randint(150,250)
colour_R = random.randint(254,255)
colour_G = random.randint(103,255)
colour_B = random.randint(205,255)
my_flower = pygame.draw.circle(screen,[colour_R,colour_G,colour_B],[f_x,f_y],5,1) #此部分樱花使⽤那么多的for循环是为了增强樱花排列的⾃然感,否则就是⼀⼤块⽅形樱花pygame.display.flip()
running = True
while running:
for event in ():
pe == pygame.QUIT:
running = False
pygame.quit()
运⾏程序后就能看到美丽的樱花了,快去试试吧!
喜欢的话请关注:迷你恐龙的博客。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。