123456789_123456789_123456789_123456789_123456789_

Class: IRB::Canvas

Relationships & Source Files
Inherits: Object
Defined in: lib/irb/easter-egg.rb

Class Method Summary

Class Method Details

.draw

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 55

def draw
  @data.each {|row| row.fill(0) }
  yield
  @data.map {|row| row.map {|n| " ',;"[n] }.join }.join("\n")
end

.initialize(h, w)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 32

def initialize((h, w))
  @data = (0..h-2).map { [0] * w }
  @scale = [w / 2.0, h-2].min
  @center = Complex(w / 2, h-2)
end

.line(x1, y1, x2, y2)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 38

def line((x1, y1), (x2, y2))
  p1 = Complex(x1, y1) / 2 * @scale + @center
  p2 = Complex(x2, y2) / 2 * @scale + @center
  line0(p1, p2)
end

.line0(p1, p2)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 44

private def line0(p1, p2)
  mid = (p1 + p2) / 2
  if (p1 - p2).abs < 1
    x, y = mid.rect
    @data[y / 2][x] |= (y % 2 > 1 ? 2 : 1)
  else
    line0(p1, mid)
    line0(p2, mid)
  end
end