python绘图作业:使用pygame库画房子

作者 : 开心源码 本文共2032个字,预计阅读时间需要6分钟 发布时间: 2022-05-12 共70人阅读
  • python测试开发项目实战-目录
  • python工具书籍下载-持续升级

使用pygame库画如下房子

图片.png

参考资料

  • 本文最新版本地址
  • 本文涉及的python测试开发库 谢谢点赞!
  • 本文相关海量书籍下载
  • CoderDojoSV/beginner-python

代码

#!/usr/bin/python3# -*- coding: utf-8 -*-# 技术支撑:https://www.songma.com/u/69f40328d4f0 # 技术支撑 https://china-testing.github.io/#  china-testing/python-api-tesing/blob/master/practices/pygame_house.py# 项目实战探讨QQ群630011153 144081101# CreateDate: 2018-12-01import pygamepygame.init()screen = pygame.display.set_mode((640,480))#used http://colorpicker.com/ to find RGB colorsdef 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 sizesdef 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 groundpygame.draw.rect(screen,(0,160,3),(0,400,640,80))#light blue skypygame.draw.rect(screen,(135,255,255),(0,0,640,400))draw_tree(60,400) #x and y location are the bottom left of tree trunkdraw_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 = Truewhile running:    for event in pygame.event.get():        if event.type == pygame.QUIT:            running = Falsepygame.quit()

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » python绘图作业:使用pygame库画房子

发表回复