Jump to content

Recommended Posts

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) 

 

Link to post
Share on other sites

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 post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...