LEDstoffroehre/lighttest/lighttest.py

109 lines
2.7 KiB
Python
Raw Normal View History

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
2019-01-26 22:51:30 +00:00
lamp0e=0
lamp0=0
lamp1e=0
lamp1=0
2019-01-26 22:51:30 +00:00
setbrightness0 = 0
#setbrightness1 = 0;
fluorescent0Active=False
#fluorescent1Active=False;
fluorescent0Age=10
#fluorescent1Age=10;
FLUORESCENTAGEMAX= 20
FLUORESCENTTEMPMAX= 1000
fluorescent0Temp=0
#fluorescent1Temp=0;
GLOWBRIGHTNESS= 50
2019-01-26 22:51:30 +00:00
flashprobability0=300 #the higher the lesser
flashprobabilitymin0=100 #the higher the lesser (at peak)
tempincreasemax0=10 #the higher the faster lightup
2019-01-26 22:51:30 +00:00
FLASHPROBABILITY_MIN=200
FLASHPROBABILITY_MAX=600
FLASHPROBABILITYMIN_MIN=100
FLASHPROBABILITYMIN_MAX=150
TEMPINCREASEMAX_MIN=5
TEMPINCREASEMAX_MAX=15
2019-01-26 22:51:30 +00:00
flashprobability0=random.randint(FLASHPROBABILITY_MIN,FLASHPROBABILITY_MAX)
flashprobabilitymin0=random.randint(FLASHPROBABILITYMIN_MIN,FLASHPROBABILITYMIN_MAX)
tempincreasemax0=random.randint(TEMPINCREASEMAX_MIN,TEMPINCREASEMAX_MAX)
2019-01-26 22:51:30 +00:00
fluorescent0Active=True #start
setbrightness0=255
2019-01-26 22:51:30 +00:00
def constrain(val, min_val, max_val):
return min(max_val, max(min_val, val))
2019-01-26 22:51:30 +00:00
# Loop as long as done == False
while not done:
ms = time.time()*1000.0
2019-01-26 22:51:30 +00:00
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
2019-01-26 22:51:30 +00:00
if (fluorescent0Active):
fluorescent0Temp+=random.randint(1,tempincreasemax0)
if (random.randint(0,flashprobability0-constrain(fluorescent0Temp*flashprobability0/FLUORESCENTTEMPMAX,0,flashprobability0-flashprobabilitymin0))==0):
lamp0=setbrightness0*random.randint(30,100)/10
lamp0e=lamp0 #flash everything
lamp0-=20
lamp0e+=constrain(random.randint(-10,fluorescent0Temp*10/FLUORESCENTTEMPMAX) , 0, 10) #start glowing slowly
if (lamp0e>GLOWBRIGHTNESS):
lamp0e-=constrain(lamp0e-GLOWBRIGHTNESS,0,20) #make sides darker until glowbrightness
if fluorescent0Temp>=FLUORESCENTTEMPMAX:
fluorescent0Active=False
fluorescent0Temp=0
lamp0=setbrightness0
lamp0e=setbrightness0
print("finished")
lamp0=constrain(int(lamp0),0,255)
lamp0e=constrain(int(lamp0e),0,255)
clamp0 = (lamp0,lamp0,lamp0)
clamp0e = (lamp0e,lamp0e,lamp0e)
screen.fill(clamp0) #center
pygame.draw.rect(screen,clamp0e,(0,0,20,size[1])) #left edge
pygame.draw.rect(screen,clamp0e,(size[0]-20,0,20,size[1]))#right edge
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()