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.



5
6
7
# File 'lib/seafoam/spotlight.rb', line 5

def initialize(graph)
  @graph = graph
end

Instance Method Details

#light(node) ⇒ Object

Mark a node as lit by the spotlight.



10
11
12
13
14
15
16
17
18
# 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

#shadeObject

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



22
23
24
25
26
# 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