我正在做一个随机移动点的pygame。这些点在黑色的表面上移动。其目的是添加upp点的RGB颜色,以防它们重叠。下图中有3个重叠的点。如何将点的RGB相加?图中的例子是三个重叠的点。点的重叠部分应具有颜色[3*250/N,3*250/N.,3*250/N],N=4。该部分应具有颜色[187.5187.5187.5]。不重叠的点部分应保持基本点颜色[250/N,250/N,250/N]。你知道吗
我不知道怎么把RGB的颜色加起来。有什么想法吗?你知道吗
以及当前代码:
import math
import random
import pygame
import random
N = 4
class focalspot(object):
def __init__(self,dirnx=0,dirny=0,color=(250/N,250/N,250/N)):
self.pos = 100,100
self.dirnx = 0
self.dirny = 0
self.color = color
def move(self, dirnx, dirny):
self.dirnx = dirnx
self.dirny = dirny
self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny)
if self.pos[0] >= width:
self.dirnx = -self.dirnx
if self.pos[1] >= width:
self.dirny = -self.dirny
if self.pos[0] <= 0:
self.dirnx = -self.dirnx
if self.pos[1] <= 0:
self.dirny = -self.dirny
def draw(self, surface):
pygame.draw.circle(surface, self.color, self.pos, 80, 0)
dots = [focalspot() for i in range(N)]
def redrawWindow(surface,dots):
global rows, width
surface.fill((0,0,0))
for dot in dots:
focalspot.draw(dot,surface)
pygame.display.update()
def main(flag,dots):
global width, rows
width = 400
win = pygame.display.set_mode((width, width))
counter = 0
clock = pygame.time.Clock()
while flag:
pygame.time.delay(50)
clock.tick(10)
for dot in dots:
dot.dirnx = int(random.uniform(-10, 10))
dot.dirny = int(random.uniform(-10, 10))
focalspot.move(dot,dot.dirnx,dot.dirny)
redrawWindow(win,dots)
pygame.image.save(win,'temp'+str(counter)+'.png')
counter =+ 1
print(counter)
main(True,dots)
您应该使用^{} 类来绘制圆。这允许您使用special blitting flags,例如
BLEND_ADD
,它将执行您想要的操作:相关问题 更多 >
编程相关推荐