class Seafoam::Spotlight
Spotlight
can light nodes, which makes them visible, their adjacent nodes visible by grey, and other nodes invisible. Multiple nodes can be lit.
Public Class Methods
new(graph)
click to toggle source
# File lib/seafoam/spotlight.rb, line 5 def initialize(graph) @graph = graph end
Public Instance Methods
light(node)
click to toggle source
Mark a node as lit by the spotlight.
# File lib/seafoam/spotlight.rb, line 10 def light(node) # This node is lit. node.props[:spotlight] = 'lit' # Adjacent nodes are shaded, if they haven't be lit themselvs. node.adjacent.each do |adjacent| adjacent.props[:spotlight] ||= 'shaded' end end
shade()
click to toggle source
Go through all other nodes and make them hidden, having lit as many nodes as you want.
# File lib/seafoam/spotlight.rb, line 22 def shade @graph.nodes.each_value do |node| node.props[:hidden] = true unless node.props[:spotlight] end end