Class: Seafoam::Spotlight

Inherits:
Object
  • Object
show all
Defined in:
lib/seafoam/spotlight.rb

Overview

Spotlight can light nodes, which makes them visible, their adjacent nodes visible by grey, and other nodes invisible. Multiple nodes can be lit.

Instance Method Summary collapse

Constructor Details

#initialize(graph) ⇒ Spotlight

Returns a new instance of Spotlight.



7
8
9
# File 'lib/seafoam/spotlight.rb', line 7

def initialize(graph)
  @graph = graph
end

Instance Method Details

#light(node) ⇒ Object

Mark a node as lit by the spotlight.



12
13
14
15
16
17
18
19
20
# File 'lib/seafoam/spotlight.rb', line 12

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

#shadeObject

Go through all other nodes and make them hidden, having lit as many nodes as you want.



24
25
26
27
28
# File 'lib/seafoam/spotlight.rb', line 24

def shade
  @graph.nodes.each_value do |node|
    node.props[:hidden] = true unless node.props[:spotlight]
  end
end