先来看看效果:

是不是很好看呢?现在我们来编程吧。

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 = pygame.draw.rect(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 = pygame.draw.rect(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 = pygame.draw.rect(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 = pygame.draw.rect(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 = pygame.draw.rect(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 = pygame.draw.rect(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 = pygame.draw.rect(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)

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 pygame.event.get():

if event.type == pygame.QUIT:

running = False

pygame.quit()

运行程序后就能看到美丽的樱花了,快去试试吧!

喜欢的话请关注微信公众号:迷你恐龙的博客。

python代码画樱花带图片_python编程——pygame画樱花树相关推荐

  1. python代码画樱花带图片_用python画一颗樱花树(不同品种) 实现代码:

    原博文 2019-12-31 14:56 − 动态生成樱花效果图(这个是动态的): 实现代码: 1 import turtle as T 2 import random 3 import time 4 ...

  2. python代码运行不了怎么办_Python编程之运行出错怎么办

    程序运行错误大概是每个程序员都可能会遇到的问题,就算是再仔细的人,也会有失误的时候.Python编程同样如此,这是一种面向对象的程序设计语言,主要服务于人工智能领域,也是现在小孩子学编程比较热门的选择 ...

  3. python制作合同模板带图片_Python操作Word批量生成合同的实现示例

    背景:大约有3K家商家需要重新确认信息并签订合同.合同是统一的Word版本.每个供应商需要修改合同内的金额部分.人工处理方式需要每个复制粘贴且金额要生成大写金额.基于重复工作可偷懒.用Python解救 ...

  4. python制作合同模板带图片_python生成各类合同

    安装包 pip install  python_docx pip install xlrd 代码示例 from docx import Document import xlrd def change_ ...

  5. c语言将一幅画转换为字符画,C#将图片转换成字符画

    先看一下效果图 在Main方法中调用(首先要添加程序集System.Drawing,然后引入命名空间System.Drawing) ConvertToChar(new Bitmap(@"D: ...

  6. python turtle画画 30排以内_Python竟能画这么漂亮的花,帅呆了(代码分享)

    阅读本文大概需要3分钟 关于函数和模块讲了这么久,我一直想用一个好玩有趣的小例子来总结一下,同时也作为实战练习一下. 趣味编程其实是最好的学习途径,回想十几年前我刚毕业的时候,第一份工作就给手机上写a ...

  7. 用Python 学一段 将图片转换成简笔画的代码

    下面是一段将图片转换为简笔画的 Python 代码示例: import cv2# 读取图片 img = cv2.imread('image.jpg', 0)# 阈值化处理 _, img = cv2.t ...

  8. python画多个圆_python turtle库画一个方格和圆实例

    python turtle库画一个方格和圆实例 使用python的turtle库画一个方格和圆 打开python编译器,导入turtle库 from turtle import * 首先画一个距离为1 ...

  9. python docx 合并文档 图片_Python+pymupdf处理PDF文档案例6则

    推荐图书:<Python程序设计(第3版)>,(ISBN:978-7-302-55083-9),清华大学出版社,2020年6月第1次印刷,7月第2次印刷 京东购买链接:https://it ...

最新文章

  1. Java修饰符:public,protected,private,不加修饰符的区别
  2. 使用apache的HttpGet\HttpPost获取返回内容编码问题
  3. CodeForces 1616H Keep XOR Low {a^b≤x} / CodeForces gym102331 Bitwise Xor {a^b≥x}(trie树 + 计数)
  4. 5分钟内完成胸部CT扫描机器学习
  5. 计算机英语900句.pdf,计算机英语900句第一章第一课:概貌
  6. 一个或多个音频服务未运行 win7 错误1079:此服务的账户不同于运行于同一进程上的其他服务账户...
  7. 深度linux 无线网卡,在Deepin Linux系统无线网卡、蓝牙模块驱动安装和出现问题的解决...
  8. 一篇文章入门Python
  9. 浅析集线器、交换机、路由器
  10. 网页设计课设【登录注册系统及增删改查】
  11. 5G系统——连接管理CM
  12. python填写问卷星_Python填写问卷星
  13. MakerBot Replicator Z18使用说明文档
  14. centos7 离线安装 rar 解压缩软件
  15. winfows 切换 双屏_Win10系统如何设置双屏显示?windows10设置双屏显示的方法
  16. 22个无版权限制的高清无码图库站
  17. wps如何在目录里面打省略号_在wps中怎么让文档目录的省略号对齐 - 卡饭网
  18. 再见 Xshell,这个开源的终端工具更酷炫。
  19. 洛谷 1462 通往奥格瑞玛的道路 题解
  20. PGM图片格式与代码

热门文章

  1. WebView 微信小程序跳转h5项目,h5项目拿到token
  2. 使用Highcharts来画一个简易的甘特图
  3. Unity生成和使用obb
  4. 中文真伟大!竟然有只能看,不能读的文章
  5. excel怎样修改表格时间和计算机一制,Excel表格中如何自动生成记录数据的日期和时间...
  6. java设计模式-观察者模式和中介者模式的异同
  7. 有感而发20210216
  8. 在线公开课 | 5G时代的视频云服务关键技术与实践
  9. 网络学习(第十八篇-HSRP协议讲解以及配置思路)
  10. RSA的dp泄露 —— 【WUST-CTF2020】leak