栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python-pygame调色板绘图

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python-pygame调色板绘图

首先安装pygame库:pip install pygame

import	pygame
pygame.init()
screen = pygame.display.set_mode([800,600])
pygame.display.set_caption("拖动鼠标左键来画画")
mousedown = False
unfinished=True

white = (255,255,255)
red = (255,50,50)
yellow = (230,230,50)
blue = (0,0,255)

pygame.draw.rect(screen,white,(0,0,50,50),0)
pygame.draw.rect(screen,red,(50,0,50,50),0)
pygame.draw.rect(screen,yellow,(100,0,50,50),0)
pygame.draw.rect(screen,blue,(150,0,50,50),0)
color=white
while unfinished:
	for event in pygame.event.get():
		if event.type==pygame.QUIT:
			unfinished = False
		if event.type == pygame.MOUSEBUTTONDOWN:
			mousedown = True
		if event.type == pygame.MOUSEBUTTONUP:
			mousedown = False
	if mousedown:
		spot = pygame.mouse.get_pos()
		#spot[0]X坐标,spot[1]Y坐标
		if spot[0]<=50 and spot[1]<=50:
			color = white
			print(color)
		elif spot[0]<=100 and spot[1]<=50:
			color = red
			print(color)
		elif spot[0]<=150 and spot[1]<=50:
			color = yellow
			print(color)
		elif spot[0]<=200 and spot[1]<=50:
			color = blue
			print(color)
		pygame.draw.circle(screen,color,spot,15)
	pygame.display.update()
pygame.quit()

			


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/498692.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号