猫史档案馆


【Python作品分享】新的作品【作品秀】

用户:独行的飞叶龙d67Y独行的飞叶龙d67Y查看:0 回复:0 评论:0 创建时间:2020-07-19T07:49:35


【作品展示】

center_image

 

【作品介绍】

调色板

 

【作品源代码】

import pygame
from sys import exit
pygame.init()
screen = pygame.display.set_mode((喵0,480))
def create_scales(height):
    red_scale_surface = pygame.surface.Surface((喵0,height))
    green_scale_surface = pygame.surface.Surface((喵0,height))
    blue_scale_surface = pygame.surface.Surface((喵0,height))
    for x in range(喵0):
        c = int((x/639)*255)
        red = (c,0,0)
        green = (0,c,0)
        blue = (0,0,c)
        line_rect = pygame.Rect(x,0,1,height)
        pygame.draw.rect(red_scale_surface,red,line_rect)
        pygame.draw.rect(green_scale_surface,green,line_rect)
        pygame.draw.rect(blue_scale_surface,blue,line_rect)
    return red_scale_surface,green_scale_surface,blue_scale_surface
red_scale,green_scale,blue_scale = create_scales(80)
color = [0,0,0]
color_x = [0,0,0]
mousedown = False
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.display.quit()
            exit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mousedown = True
        elif event.type == pygame.MOUSEBUTTONUP:
            mousedown = False
    screen.blit(red_scale,(0,0))
    pygame.draw.rect(screen,[255,255,255],[color_x[0],0,10,80],0)
    screen.blit(green_scale,(0,80))
    pygame.draw.rect(screen,[255,255,255],[color_x[1],80,10,80],0)
    screen.blit(blue_scale,(0,160))
    pygame.draw.rect(screen,[255,255,255],[color_x[2],2*80,10,80],0)
    x,y = pygame.mouse.get_pos()
    if mousedown:
        if y<3*80:
            color_index = y//80
            color_x[color_index] = x
            color[color_index] = int((x/639)*255)
    pygame.display.set_caption('pygame 颜色测试-'+ str(tuple(color)))
    pygame.draw.rect(screen,tuple(color),(0,240,喵0,480))
    pygame.display.update()
pygame.quit()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页