summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorTom Black <[email protected]>2018-09-20 21:09:43 -0700
committerTom Black <[email protected]>2018-09-20 21:09:43 -0700
commit23fea974a4369282905abf36f051bbbfc7e36863 (patch)
treeebd90209392aa4930647f02d7450bb5c3d8523c6 /lib
parent35a1c94eeef017413d0a20e68082441d2cd13264 (diff)
downloadruby2d-23fea974a4369282905abf36f051bbbfc7e36863.tar.gz
ruby2d-23fea974a4369282905abf36f051bbbfc7e36863.zip
Add `Circle` class
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d.rb1
-rw-r--r--lib/ruby2d/circle.rb28
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/ruby2d.rb b/lib/ruby2d.rb
index 823512f..6dc72dc 100644
--- a/lib/ruby2d.rb
+++ b/lib/ruby2d.rb
@@ -7,6 +7,7 @@ require 'ruby2d/window'
require 'ruby2d/dsl'
require 'ruby2d/quad'
require 'ruby2d/line'
+require 'ruby2d/circle'
require 'ruby2d/rectangle'
require 'ruby2d/square'
require 'ruby2d/triangle'
diff --git a/lib/ruby2d/circle.rb b/lib/ruby2d/circle.rb
new file mode 100644
index 0000000..4f87828
--- /dev/null
+++ b/lib/ruby2d/circle.rb
@@ -0,0 +1,28 @@
+# circle.rb
+
+module Ruby2D
+ class Circle
+ include Renderable
+
+ attr_reader :color
+ attr_accessor :x, :y, :radius, :sectors
+
+ def initialize(opts = {})
+ @x = opts[:x] || 25
+ @y = opts[:y] || 25
+ @radius = opts[:radius] || 25
+ @sectors = opts[:sectors] || 20
+ @z = opts[:z] || 0
+ self.color = opts[:color] || 'white'
+ add
+ end
+
+ def color=(c)
+ @color = Color.from(c)
+ end
+
+ def contains?(x, y)
+ Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
+ end
+ end
+end