File: sample54.rb

package info (click to toggle)
ruby-graphviz 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,216 kB
  • sloc: ruby: 7,685; xml: 26; makefile: 17
file content (26 lines) | stat: -rw-r--r-- 496 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$:.unshift( "../lib" )
require 'graphviz'

class Array
  def rotate
    ## Solution #1 by greg
    # self.push(r = self.shift)
    # return r

    ## Solution #2 by madx
    # shift.tap {|e| push e }

    ## Solution #3 by greg
    push(shift)[-1]
  end
end

type = ["box", "point"]

GraphViz.graph( :G, :use => :neato ) { |g|
  (1..5).each do |x|
    (1..5).each do |y|
      g.add_nodes( "n#{x}x#{y}", :pos => "#{x},#{y}!", :shape => type.rotate )
    end
  end
}.output( :png => "#{$0}.png" )