Last active
February 22, 2020 14:33
-
-
Save arpruss/6c0683a80e72c9f6744e5e3f5413339d to your computer and use it in GitHub Desktop.
accrete falling pixels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# public domain | |
import pygame | |
from random import randint | |
width = 400 | |
height = 400 | |
screen = pygame.display.set_mode((width, height)) | |
color = (255,255,255) | |
def clampWidth(x): | |
return max(min(x,width-1),0) | |
neighbors = ( (0,1), (1,1), (-1,1), (-1,0), (1,0) ) | |
def haveNeighbor(x,y): | |
if y >= height-1: | |
return True | |
for n in neighbors: | |
if screen.get_at((clampWidth(x+n[0]),y+n[1])) == color: | |
return True | |
return False | |
while True: | |
if pygame.QUIT in (event.type for event in pygame.event.get()): | |
break | |
x = randint(width//3,2*width//3) #randint(0,width-1) | |
y = 0 | |
while True: | |
if haveNeighbor(x,y): | |
screen.set_at((x,y),color) | |
pygame.display.flip() | |
break | |
x = clampWidth( x + randint(-1,1) ) | |
y += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment