[雪峰磁针石博客]python绘图作业:使用pygame库画房子
使用pygame库画如下房子
参考资料
代码
#!/usr/bin/python3 # -*- coding: utf-8 -*- # 技术支持:https://www.jianshu.com/u/69f40328d4f0 # 技术支持 https://china-testing.github.io/ # https://github.com/china-testing/python-api-tesing/blob/master/practices/pygame_house.py # 项目实战讨论QQ群630011153 144081101 # CreateDate: 2018-12-01 import pygame pygame.init() screen = pygame.display.set_mode((640,480)) #used http://colorpicker.com/ to find RGB colors def draw_tree(x,y): #tree trunk (50 wide and 100 tall) pygame.draw.rect(screen,(117,90,0),(x,y-100,50,100)) #leaves are a circle pygame.draw.circle(screen,(27,117,0),(x+25,y-120),50) def draw_house(x,y): #pink house pygame.draw.rect(screen,(255,171,244),(x,y-180,200,180)) #brown door pygame.draw.rect(screen,(89,71,0),(x+80,y-60,40,60)) #yellow door knob pygame.draw.circle(screen,(255,204,0),(x+112,y-30),4) #triangle roof pygame.draw.polygon(screen, (125,125,125), ( (x,y-180),(x+100,y-250),(x+200,y-180) ) ) draw_window(x+20,y-90) draw_window(x+130,y-90) def draw_window(x,y): #glass pygame.draw.rect(screen,(207,229,255),(x,y-50,50,50)) #frame pygame.draw.rect(screen,(0,0,0),(x,y-50,50,50),5) pygame.draw.rect(screen,(0,0,0),(x+23,y-50,5,50)) pygame.draw.rect(screen,(0,0,0),(x,y-27,50,5)) #this function is able to draw clouds of different sizes def draw_cloud(x,y,size): #put int() around any multiplications by decimals to get rid of this warning: #DeprecationWarning: integer argument expected, got float pygame.draw.circle(screen,(255,255,255),(x,y),int(size*.5)) pygame.draw.circle(screen,(255,255,255),(int(x+size*.5),y),int(size*.6)) pygame.draw.circle(screen,(255,255,255),(x+size,int(y-size*.1)),int(size*.4)) #green ground pygame.draw.rect(screen,(0,160,3),(0,400,640,80)) #light blue sky pygame.draw.rect(screen,(135,255,255),(0,0,640,400)) draw_tree(60,400) #x and y location are the bottom left of tree trunk draw_tree(550,400) draw_house(225,400) draw_cloud(60,120,80) draw_cloud(200,50,40) draw_cloud(450,100,120) pygame.display.flip() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.quit()

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
[雪峰磁针石博客]python GUI作业:使用tkinter的重要控件
python测试开发项目实战-目录 python工具书籍下载-持续更新 题目1:使用tkinter的重要控件 绘制如下菜单: 参考代码: #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 技术支持:https://www.jianshu.com/u/69f40328d4f0 # 技术支持 https://china-testing.github.io/ # https://github.com/china-testing/python-api-tesing/blob/master/practices/tk/tk3.py # 项目实战讨论QQ群630011153 144081101 # CreateDate: 2018-11-29 import tkinter as tk root = tk.Tk() root.title('tkinter控件') #create a frame widget for placing menu my_menu_bar = tk.Frame(root, relief='raised', bd=2) my_me...
- 下一篇
[雪峰磁针石博客]python tkinter图形工具样式作业
python测试开发项目实战-目录 python工具书籍下载-持续更新 使用tkinter绘制如下窗口 参考资料 本文最新版本地址 本文涉及的python测试开发库 谢谢点赞! 本文相关海量书籍下载 https://github.com/CoderDojoSV/beginner-python 代码 #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 技术支持:https://www.jianshu.com/u/69f40328d4f0 # 技术支持 https://china-testing.github.io/ # https://github.com/china-testing/python-api-tesing/blob/master/practices/tk/tk4.py # 项目实战讨论QQ群630011153 144081101 # CreateDate: 2018-12-02 import tkinter as tk root = tk.Tk() root.configure(background='#4D4D4D') #to...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS7设置SWAP分区,小内存服务器的救世主
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS6,CentOS7官方镜像安装Oracle11G
- Mario游戏-低调大师作品
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7