Class: Circle
- Inherits:
-
Object
- Object
- Circle
- Defined in:
- lib/r2d/circle.rb
Overview
circle.rb gist.github.com/661266
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(radius) ⇒ Circle
constructor
A new instance of Circle.
- #to_blob ⇒ Object
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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/r2d/circle.rb', line 5 def columns @columns end |
#rows ⇒ Object (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_blob ⇒ Object
18 19 20 |
# File 'lib/r2d/circle.rb', line 18 def to_blob @blob end |