Disco Lights

From kJams Wiki
Jump to navigation Jump to search

I set up a few lights around the room, with LIFX bulbs, but you could as easily use Phillips Hue bulbs.

Then i run LIFXstyle or Hue-topia.

Then i run my color-changing-lights script:

tell application "LIFXStyle"
	set hueScaleFactor to 3 # larger number: cycle faster, smaller number: cylce slower
	set intraLampHueOffset to 45 # number of hue steps to take per bulb (so they're offset from each other)
	set kMaxValue to 255 # constant: don't change this number
	
	set groupNameList to {"Barn"} #, "Pool"} #, "Music Room"}
	
	set lampList to my get_all_lamps_in_group_list(groupNameList)
	
	repeat with curLamp in lampList
		set (whiteness of curLamp) to 25
		set (brightness of curLamp) to kMaxValue
	end repeat
	
	set hueStart to hue of item 1 of lampList
	set hueStartScaled to (hueStart / hueScaleFactor) as integer
	set hueEndScaled to (kMaxValue / hueScaleFactor) as integer
	
	repeat
		repeat with hueValue from hueStartScaled to hueEndScaled
			set curScaledHue to (hueValue * hueScaleFactor)
			
			repeat with itemNo from 1 to count of lampList
				set curLamp to item itemNo of lampList
				set curLampHue to ((curScaledHue + (itemNo * intraLampHueOffset)) mod kMaxValue) as integer
				set (hue of curLamp) to curLampHue
			end repeat
			
			delay 0.25
		end repeat
		
		set hueStartScaled to 0
	end repeat
end tell

on get_all_lamps_in_group_list(groupNameList)
	set lampList to {}
	
	repeat with curGroup in groupNameList
		set lampList to lampList & my get_group_lamp_list(curGroup)
	end repeat
	
	return lampList
end get_all_lamps_in_group_list

on get_group_lamp_list(groupName)
	set lampList to {}
	
	tell application "LIFXStyle"
		set lampGroup to a reference to lamps of (first group whose title is groupName)
		
		repeat with lampNo from 1 to (count of lampGroup)
			set lampList to lampList & {a reference to (item lampNo of lampGroup)}
		end repeat
		
	end tell
	
	return lampList
end get_group_lamp_list