Class: Circle

Inherits:
Object
  • Object
show all
Defined in:
lib/r2d/circle.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(radius) ⇒ Circle

Returns a new instance of Circle.



7
8
9
10
11
12
13
14
15
16
# File 'lib/r2d/circle.rb', line 7

def initialize radius
  @columns = @rows = radius * 2
  lower_half = (0...radius).map do |y|
    x = Math.sqrt(radius**2 - y**2).round
    right_half = "#{"\xff" * x}#{"\x00" * (radius - x)}"
    "#{right_half.reverse}#{right_half}"
  end.join
  @blob = lower_half.reverse + lower_half
  @blob.gsub!(/./) { |alpha| "\xff\xff\xff#{alpha}"}
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



5
6
7
# File 'lib/r2d/circle.rb', line 5

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



5
6
7
# File 'lib/r2d/circle.rb', line 5

def rows
  @rows
end

Instance Method Details

#to_blobObject



18
19
20
# File 'lib/r2d/circle.rb', line 18

def to_blob
  @blob
end