Mucus Posted February 5, 2021 Share Posted February 5, 2021 Purpose, Makes lights randomly change rgb colour and cycles them to give a breathing effect. Level: Lua beginner = cut and paste code, create filters unit start and system update in lua editor , DU = know how to link lights to a programming board Build You need 1 Programming Board(PB) and some lights. Connect the lights to the PB and name each slot in the lua editor (Ctrl L) you have connected l1 , l2 etc. If you don't want 8 then edit the source code and remove. code is below. Other stuff you can do : add a detector to autostart , change parameters in unit start to get the feel you like. -- copy and paste into unit start unit.hide() -- hides programming board -- remove these where you have not connected a light l1.activate() l2.activate() l3.activate() l4.activate() l5.activate() l6.activate() l7.activate() l8.activate() bClock = system.getTime() -- start clock origRgb = l1.getRGBColor() -- stores the colour of the original light if you want to reset lights on exit breathRate = 1 --export: rate of breathing Multiplier changeFrame = 1200 --export: frame colour and channel cycle rgbIndex = utils.round(math.random(3)) -- choose channel to breathe r = math.random(255) -- setup channels g = math.random(255) b = math.random(255) frameCount = 0 -- Copy and Paste into System update frameCount = frameCount + 1 if ( frameCount % changeFrame == 0 ) then --randomize rgb and channel r = math.random(255) g = math.random(255) b = math.random(255) rgbIndex = utils.round(math.random(3)) -- choose channel to breathe end nClock = system.getTime() local timeSeconds = ( nClock - bClock) local breath = utils.round(( math.exp( math.sin(timeSeconds * breathRate )) - 0.36787944 )* 108.0) if rgbIndex == 1 then r = breath elseif rgbIndex == 2 then g = breath else b = breath end -- set rgb colour of linked lights ,remove these where you have not connected a light l1.setRGBColor(r,g,b) l2.setRGBColor(r,g,b) l3.setRGBColor(r,g,b) l4.setRGBColor(r,g,b) l5.setRGBColor(r,g,b) l6.setRGBColor(r,g,b) l7.setRGBColor(r,g,b) l8.setRGBColor(r,g,b) Rolfbier and michaelk 2 Link to comment Share on other sites More sharing options...
Mucus Posted February 5, 2021 Author Share Posted February 5, 2021 A few notes on parameters and code: breathRate can be changed to speed or slow the rate of breathing. try various small numbers like ,1.1 or 0.9 as values . changeFrame decides when to change the colour and channel that is being cycled. so as update runs at about 60 frames a second a value of 300 would mean change every 5 seconds. To autostart connect a detector to the PB and link it from the detector to the PB. When you walk in the detection space the PB will start. You could remove modify the script to remove the random rgb changes or change the rgb values to react to movement, engines , velocity if you use in a dynamic core Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now