Skip to content

Instantly share code, notes, and snippets.

@fronx
Last active August 29, 2015 14:07
Show Gist options
  • Save fronx/a2d7bdb26fb9f83d1c58 to your computer and use it in GitHub Desktop.
Save fronx/a2d7bdb26fb9f83d1c58 to your computer and use it in GitHub Desktop.
import pygame, sys
from pygame.locals import *
def to_color(a, a_max, b, b_max):
return (255,
int(float(a)/a_max*255),
int(float(b)/b_max*255))
def pixel(x, y, size):
return (x * size, y * size, size, size)
def draw_gradient((width, height), display, box_size):
m_max = width / box_size
n_max = height / box_size
for m in range(m_max):
for n in range(n_max):
pygame.draw.rect(display,
to_color(m, m_max, n, n_max),
pixel(m, n, box_size))
pygame.init()
width = 500
height = 400
display = pygame.display.set_mode((width, height))
draw_gradient((width, height), display, 10)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment