I am wondering how to blend two pygame.Color objects and cannot find a solution after extensive reasearch.
I have created two pygame.Color objects and would like to create a new object who's colour value is the two colours blended together.
import pygame
white = pygame.Color(255, 255, 255)
red = pygame.Color(255, 0, 0)
#If I want to blend white and red with the option of how much dominace each should have what code would I write
Use the pygame.Color.lerp function to linear interpolation to the given Colors.
white = pygame.Color(255, 255, 255)
red = pygame.Color(255, 0, 0)
pink = white.lerp(red, 0.5)
Minimal example:

import pygame
pygame.init()
window = pygame.display.set_mode((500, 100))
clock = pygame.time.Clock()
white = pygame.Color(255, 255, 255)
red = pygame.Color(255, 0, 0)
pink25 = white.lerp(red, 0.25)
pink50 = white.lerp(red, 0.5)
pink75 = white.lerp(red, 0.75)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
window.fill(0)
pygame.draw.circle(window, white, (50, 50), 45)
pygame.draw.circle(window, pink25, (150, 50), 45)
pygame.draw.circle(window, pink50, (250, 50), 45)
pygame.draw.circle(window, pink75, (350, 50), 45)
pygame.draw.circle(window, red, (450, 50), 45)
pygame.display.flip()
clock.tick(60)
pygame.quit()
exit()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With