i am working on a pygame with random moving dots. The dots are moving across a black surface. The aim is to add upp the RGB-Colors of the dots in case they overlap. In the following image are 3 dots which do overlap. How can i add up the RGB of the Dots? Example in the Image are three dots overlapping. The part of a dot which is overlapping should have the color [3*250/N, 3*250/N., 3*250/N] with N = 4 the part should have the color [187.5,187.5,187.5]. The parts of the dots that are not overlapping shall stay the basic dot color [250/N, 250/N, 250/N].
I dont know how to add up the RGB colors. Any ideas?
And the current code:
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)