【发布时间】:2019-12-01 17:56:02
【问题描述】:
我需要识别从 PixelArray 中的元素采样的像素颜色,然后输入 pygame.Color()。 pygame.Color() 返回的值之一让我感到困惑。
我研究了像素数组的选定元素中保存的整数值,将值转换为二进制并识别 RGB 分量。可以考虑所有三个组成部分。对 pygame.Color(pixel_integer) 的调用会返回所有三个值以及 (0, R, G, B) 中的一个额外值(零)。那个零让我感到困惑。有人可以确定这个值代表什么。色调?饱和?两个都?两者都不?完全不同的东西?为什么是零?
from os import system
import pygame
system('cls') # Clear greeting from CC screen.
usecolor = (46,12,187,255) # Declare our chosen color.
sprite = pygame.Surface((10,10)) # Greate a surface. Let us call it a 'sprite'.
sprite.fill(usecolor) # Fill the 'sprite' with our chosen color.
array = pygame.PixelArray(sprite) # Create a pixel array of the sprite, locking the sprite.
sample = array[5,5] # Sample the integer holding the color values of pixel [5,5]
del array # Delete the pixel array, unlocking the sprite.
print("\n Challenge: Use a pixel-array of a sprite to sample the color of the pixel at location [5,5]")
print(" Determine the RGB-values held by the integer found there.")
print("\n We have created a 100x100 'sprite' and filled it with the color "+str(usecolor))
print(" Then we cerated a pixel array of the sprite and sampled the color of the element at location [5,5],")
print(" corrosponding to pixel [5,5] on the sprite.")
print("\n The color we used to fill the sprite was",usecolor)
print(" The value sampled from pixel [5,5] is",sample)
print(" pygame.Color(sample) =",pygame.Color(sample))
print("\n Notice that there is a mystery zero at the front of the values returned by pygame.Color().")
print(" Notice too that our Alpha value is missing from the back.")
print(" (Let us ignore the missing alpha value. It doesn't matter.)")
print("\n m,r,g,b = pygame.Color(sample) where 'm' stands for 'mystery'")
m,r,g,b = pygame.Color(sample)
print("\n m >>",m)
print(" r >>",r)
print(" g >>",g)
print(" b >>",b)
color = (r,g,b)
print("\n From these values we find that color =",color)
print("\n Question: What is 'm'?")
print("\n 'm' can't be alpha because that value would be 255 (opaque); an alpha value of 0 is transparent.")
print(" Besides, the alpha value should be at the end of the color series, not at the beginning. Any ideas?")
print("\n\n\tThanks!\n\n -Science_1")
print('',end="\n ")
exit()
没有错误,但前导零值让我感到困惑。是什么原因造成的,它是什么意思?
【问题讨论】: