Skip to content

Instantly share code, notes, and snippets.

@princessruthie
Created July 12, 2018 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save princessruthie/5040cc8c0d34f12637044ddcadf8bcd0 to your computer and use it in GitHub Desktop.
Save princessruthie/5040cc8c0d34f12637044ddcadf8bcd0 to your computer and use it in GitHub Desktop.
Powered*
Powered*
power failed -> Unpowered
Green*
tick -> Yellow
Yellow
tick -> Red
Red
tick -> Green
Unpowered
power restored -> Powered
Red On*
//A function that draws individual traffic lights
function light(color, is_illuminated){
return $('div', {style: {backgroundColor: color,
width: '20px',
height: '20px',
opacity: is_illuminated ? 1 : 0.005}});
}
//A function that draws all of our lights, based on the statechart
function render(model){
var active_light = model.active_states[0].name;
return $('div',
light('Red', active_light === 'Red' || active_light === 'Red On'),
light('Yellow', active_light === 'Yellow'),
light('Green', active_light === 'Green'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment