114 lines
3.4 KiB
Python
114 lines
3.4 KiB
Python
|
|
import pygame
|
|
import random
|
|
|
|
pygame.init()
|
|
|
|
# Set the height and width of the screen
|
|
size = (400, 100)
|
|
screen = pygame.display.set_mode(size)
|
|
|
|
pygame.display.set_caption("Blafoo")
|
|
|
|
# Loop until the user clicks the close button.
|
|
done = False
|
|
clock = pygame.time.Clock()
|
|
|
|
import time
|
|
|
|
|
|
FLUORESCENTTEMPMAX=400
|
|
|
|
fluorescentCurrentBrightness=0
|
|
fluorescentTemp=0
|
|
fluorescentActive=True
|
|
|
|
|
|
fluorescentSet=255
|
|
|
|
|
|
# Loop as long as done == False
|
|
while not done:
|
|
ms = time.time()*1000.0
|
|
|
|
for event in pygame.event.get(): # User did something
|
|
if event.type == pygame.QUIT: # If user clicked close
|
|
done = True # Flag that we are done so we exit this loop
|
|
|
|
|
|
|
|
|
|
'''
|
|
if (fluorescentActive):
|
|
fluorescentTemp+=random.randint(0,3 +1)
|
|
|
|
if (random.randint(0, 256+1) < fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256):
|
|
if (random.randint(0, 40+1) ==0): #ignite
|
|
fluorescentCurrentBrightness=fluorescentSet*random.randint(50,100)/100
|
|
|
|
if (random.randint(0, 256+1) > fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256):
|
|
if (fluorescentCurrentBrightness<5):
|
|
if (random.randint(0,50 +1)==0): #ignite
|
|
fluorescentCurrentBrightness=fluorescentSet*random.randint(50,100)/100
|
|
if (fluorescentCurrentBrightness>20):
|
|
fluorescentCurrentBrightness-=30
|
|
|
|
if (fluorescentTemp>=FLUORESCENTTEMPMAX):
|
|
fluorescentActive=False
|
|
fluorescentCurrentBrightness=fluorescentSet
|
|
|
|
|
|
if (fluorescentCurrentBrightness>255):
|
|
fluorescentCurrentBrightness=255
|
|
if (fluorescentCurrentBrightness<0):
|
|
fluorescentCurrentBrightness=0
|
|
|
|
COLOR = (fluorescentCurrentBrightness,fluorescentCurrentBrightness,fluorescentCurrentBrightness)
|
|
else:
|
|
COLOR = (fluorescentSet,fluorescentSet,fluorescentSet)
|
|
'''
|
|
|
|
|
|
if (fluorescentActive):
|
|
fluorescentTemp+=1+ random.randint(0,20* fluorescentTemp/FLUORESCENTTEMPMAX)
|
|
#fluorescentTemp+=3
|
|
|
|
|
|
if (random.randint(0,80 +1)==0): #ignite
|
|
fluorescentCurrentBrightness=fluorescentSet*random.randint(50,100)/100
|
|
|
|
if (fluorescentTemp>200): #warm enough to glow
|
|
if (fluorescentCurrentBrightness<20): #if under glow brightness
|
|
fluorescentCurrentBrightness+=5 #start glowing
|
|
elif (fluorescentCurrentBrightness>50): #too bright for glow
|
|
fluorescentCurrentBrightness-=random.randint(0,30) #reduce intencity (flashing effect)
|
|
else: #not warm enough to glow
|
|
if (fluorescentCurrentBrightness>0): #too bright for glow
|
|
fluorescentCurrentBrightness-=random.randint(20,50) #reduce intencity (flashing effect)
|
|
|
|
if (fluorescentTemp>=FLUORESCENTTEMPMAX):
|
|
fluorescentActive=False
|
|
fluorescentCurrentBrightness=fluorescentSet
|
|
print("Finished")
|
|
|
|
if (fluorescentCurrentBrightness>255):
|
|
fluorescentCurrentBrightness=255
|
|
if (fluorescentCurrentBrightness<0):
|
|
fluorescentCurrentBrightness=0
|
|
|
|
COLOR = (fluorescentCurrentBrightness,fluorescentCurrentBrightness,fluorescentCurrentBrightness)
|
|
else:
|
|
COLOR = (fluorescentSet,fluorescentSet,fluorescentSet)
|
|
|
|
|
|
screen.fill(COLOR)
|
|
|
|
pygame.display.flip()
|
|
|
|
# This limits the while loop to a max of 60 times per second.
|
|
# Leave this out and we will use all CPU we can.
|
|
clock.tick(50)
|
|
|
|
# Be IDLE friendly
|
|
pygame.quit()
|