diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/image.rb | 19 | ||||
| -rw-r--r-- | lib/ruby2d/line.rb | 15 | ||||
| -rw-r--r-- | lib/ruby2d/quad.rb | 17 | ||||
| -rw-r--r-- | lib/ruby2d/rectangle.rb | 15 | ||||
| -rw-r--r-- | lib/ruby2d/square.rb | 15 | ||||
| -rw-r--r-- | lib/ruby2d/text.rb | 21 | ||||
| -rw-r--r-- | lib/ruby2d/triangle.rb | 16 |
7 files changed, 74 insertions, 44 deletions
diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb index 2691f78..cfab0b6 100644 --- a/lib/ruby2d/image.rb +++ b/lib/ruby2d/image.rb @@ -7,19 +7,24 @@ module Ruby2D attr_accessor :x, :y, :width, :height, :data attr_reader :path, :color - def initialize(x, y, path, z=0) + def initialize(opts = {}) + @path = opts[:path] unless RUBY_ENGINE == 'opal' - unless File.exists? path - raise Error, "Cannot find image file `#{path}`" + unless File.exists? @path + raise Error, "Cannot find image file `#{@path}`" end end + @x = opts[:x] || 0 + @y = opts[:y] || 0 + @z = opts[:x] || 0 + @type_id = 4 - @x, @y, @path = x, y, path - @z = z - @color = Color.new([1, 1, 1, 1]) - ext_image_init(path) + + self.color = opts[:color] || 'white' + + ext_image_init(@path) add end diff --git a/lib/ruby2d/line.rb b/lib/ruby2d/line.rb index 769c37f..7d1645c 100644 --- a/lib/ruby2d/line.rb +++ b/lib/ruby2d/line.rb @@ -5,12 +5,17 @@ module Ruby2D include Renderable attr_accessor :x1, :x2, :y1, :y2, :color, :width - def initialize(x1, y1, x2, y2, width=2, c='white', z=0) + def initialize(opts = {}) @type_id = 3 - @x1, @y1, @x2, @y2 = x1, y1, x2, y2 - @width = width - @z = z - self.color = c + + @x1 = opts[:x1] || 0 + @y1 = opts[:y1] || 0 + @x2 = opts[:x2] || 100 + @y2 = opts[:y2] || 100 + @width = opts[:width] || 2 + @z = opts[:z] || 0 + self.color = opts[:color] || 'white' + add end diff --git a/lib/ruby2d/quad.rb b/lib/ruby2d/quad.rb index 4fac328..cb72c31 100644 --- a/lib/ruby2d/quad.rb +++ b/lib/ruby2d/quad.rb @@ -15,12 +15,21 @@ module Ruby2D attr_reader :color - def initialize(x1=0, y1=0, x2=100, y2=0, x3=100, y3=100, x4=100, y4=100, c='white', z=0) + def initialize(opts = {}) @type_id = 2 - @x1, @y1, @x2, @y2, @x3, @y3, @x4, @y4 = x1, y1, x2, y2, x3, y3, x4, y4 - @z = z - self.color = c + @x1 = opts[:x1] || 0 + @y1 = opts[:y1] || 0 + @x2 = opts[:x2] || 100 + @y2 = opts[:y2] || 0 + @x3 = opts[:x3] || 100 + @y3 = opts[:y3] || 100 + @x4 = opts[:x4] || 0 + @y4 = opts[:y4] || 100 + + @z = opts[:z] || 0 + + self.color = opts[:color] || 'white' add end diff --git a/lib/ruby2d/rectangle.rb b/lib/ruby2d/rectangle.rb index db54b46..392c217 100644 --- a/lib/ruby2d/rectangle.rb +++ b/lib/ruby2d/rectangle.rb @@ -5,13 +5,18 @@ module Ruby2D attr_reader :x, :y, :width, :height - def initialize(x=0, y=0, w=200, h=100, c='white', z=0) + def initialize(opts = {}) @type_id = 2 - @x, @y, @width, @height = x, y, w, h - @z = z - update_coords(x, y, w, h) - self.color = c + @x = opts[:x] || 0 + @y = opts[:y] || 0 + @z = opts[:z] || 0 + @width = opts[:width] || 200 + @height = opts[:height] || 100 + + update_coords(@x, @y, @width, @height) + + self.color = opts[:color] || 'white' add end diff --git a/lib/ruby2d/square.rb b/lib/ruby2d/square.rb index 26a929d..187d48d 100644 --- a/lib/ruby2d/square.rb +++ b/lib/ruby2d/square.rb @@ -5,14 +5,17 @@ module Ruby2D attr_reader :size - def initialize(x=0, y=0, s=100, c='white', z=0) + def initialize(opts = {}) @type_id = 2 - @x, @y = x, y - @width = @height = @size = s - @z = z - update_coords(x, y, s, s) + @x = opts[:x] || 0 + @y = opts[:y] || 0 + @z = opts[:z] || 0 + @width = @height = @size = opts[:size] || 100 + + self.color = opts[:color] || 'white' + + update_coords(@x, @y, @size, @size) - self.color = c add end diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index c036a92..f9d46a2 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -7,19 +7,18 @@ module Ruby2D attr_accessor :x, :y, :data attr_reader :text, :size, :width, :height, :font, :color - def initialize(x=0, y=0, text="Hello World!", size=20, font=nil, c='white', z=0) + def initialize(opts = {}) + @type_id = 6 - # if File.exists? font - @font = font - # else - # @font = resolve_path(font) - # end + @x = opts[:x] || 0 + @y = opts[:y] || 0 + @z = opts[:z] || 0 + @text = (opts[:text] || "Hello World!").to_s + @size = opts[:size] || 20 - @type_id = 6 - @x, @y, @size = x, y, size - @z = z - @text = text.to_s - self.color = c + @font = opts[:font] + + self.color = opts[:color] || 'white' ext_text_init add end diff --git a/lib/ruby2d/triangle.rb b/lib/ruby2d/triangle.rb index e3b091b..255b19c 100644 --- a/lib/ruby2d/triangle.rb +++ b/lib/ruby2d/triangle.rb @@ -9,14 +9,18 @@ module Ruby2D :x3, :y3, :c3 attr_reader :color, :type_id - def initialize(x1=50, y1=0, x2=100, y2=100, x3=0, y3=100, c='white', z=0) + def initialize(opts= {}) @type_id = 1 - @x1, @y1 = x1, y1 - @x2, @y2 = x2, y2 - @x3, @y3 = x3, y3 - @z = z - self.color = c + @x1 = opts[:x1] || 50 + @y1 = opts[:y1] || 0 + @x2 = opts[:x2] || 100 + @y2 = opts[:y2] || 100 + @x3 = opts[:x3] || 0 + @y3 = opts[:y3] || 100 + @z = opts[:z] || 0 + + self.color = opts[:color] || 'white' add end |
