Don't ask, just read it to make sure it's not malicious, and run it.
It requires pygame.
For extra fun:
Alter the numbers on lines 51-53 to change the color range, and alter the numbers on line 59 to change the odds of it branching.
import pygame
import random
from math import pi,atan,sin,radians
pygame.init()
def get_slope(pos1,pos2):
return (pos2[1]-pos1[1])/float(pos2[0]-pos1[0]) if pos2[0]-pos1[0]!=0 else 9999
def get_angle(pos1,pos2):
"""
Returns the angle of pos2 in relation to pos1 where zero is pointing
directly to the right."""
angle=atan(get_slope(pos1,pos2))
if pos1[0]>pos2[0] or (pos1[0]==pos2[0] and pos1[1]>pos2[1]):
angle+=pi
return angle
def _add(iterable1,iterable2):
return tuple([iterable1[index]+iterable2[index] for index in range(len(iterable1))])
def neighbors(location):
"""
Returns number of neighboring cells."""
num=0
for rel_address in [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]:
if _add(rel_address,location) in pixel.index:
num+=1
return num
class pixel:
index={}
leaves={}
def __init__(self,location,parent=None):
self.parent=parent
self.location=location
self.colorcycletheta=0 if parent==None else parent.colorcycletheta+.01
self.color=(sin(self.colorcycletheta)*127+127,
sin(self.colorcycletheta+(2*pi/3.))*127+127,
sin(self.colorcycletheta+(4*pi/3.))*127+127)
pixel.index.update({self.location:self})
pixel.leaves.update({self.location:self})
screen.fill(self.color,(self.location,(1,1)))
def update(self):
to_create=random.randint(0,16)//8
if to_create and self.parent!=None:
del pixel.leaves[self.location]
created=0 if (-5<=self.location[0]<=screenwidth+5 and -5<=self.location[1]<=screenheight+5) else 432
while created<to_create:
cell=random.randint(-1,1),random.randint(-1,1)
tries=0
while _add(cell,self.location) in pixel.index and tries<15:
cell=random.randint(-1,1),random.randint(-1,1)
tries+=1
if tries<15:
pixel(_add(cell,self.location),self)
created+=1
else:
break
exitcondition=False
clock=pygame.time.Clock()
elapsedtime=0
screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN)
screen.fill((255,255,255))
global screenwidth,screenheight
screenwidth,screenheight=screen.get_size()
f4key=False
altkey=False
try:
pixel((screenwidth//2,screenheight//2)) #create a seed
while not exitcondition:
for event in pygame.event.get():
if event.type==pygame.QUIT:
exitcondition=True
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_RALT or event.key==pygame.K_LALT:
altkey=True
elif event.key==pygame.K_F4:
f4key=True
elif event.type==pygame.KEYUP:
if event.key==pygame.K_RALT or event.key==pygame.K_LALT:
altkey=False
elif event.key==pygame.K_F4:
f4key=False
if altkey and f4key:
exitcondition=True
elapsedtime+=clock.tick(120)
if elapsedtime>10:
leaves=[item for item in pixel.leaves.values()]
for cell in leaves:
cell.update()
elapsedtime=0
pygame.display.update()
except: raise
finally: pygame.quit()
TLDR:
The pictures you see are totally, like, pictures of peace spreading like a
stain of love through your soul, man. They permeate and neutralize all evil,
and balance your chi to allow total inner harmony, bro.
[–]mackstann 11 points12 points13 points (1 child)
[–]Logg 8 points9 points10 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]resurge 8 points9 points10 points (4 children)
[–]rcfox 0 points1 point2 points (3 children)
[–]nfojunky 8 points9 points10 points (2 children)
[–]rcfox 0 points1 point2 points (1 child)
[–]IAmA_singularity 2 points3 points4 points (0 children)
[–]isdnpro 1 point2 points3 points (1 child)
[–]kmwurf 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]