Sha256: 67b43c67e4f8f14e4b7c915fe8d103b81dc21342f2d7cf2af4f89be5b633cd19

Contents?: true

Size: 968 Bytes

Versions: 8

Compression:

Stored size: 968 Bytes

Contents

# Ruby2D::Rectangle

module Ruby2D
  class Rectangle < Quad

    def initialize(opts = {})
      @x = opts[:x] || 0
      @y = opts[:y] || 0
      @z = opts[:z] || 0
      @width = opts[:width] || 200
      @height = opts[:height] || 100
      self.color = opts[:color] || 'white'
      self.opacity = opts[:opacity] if opts[:opacity]
      update_coords(@x, @y, @width, @height)
      add
    end

    def x=(x)
      @x = @x1 = x
      @x2 = x + @width
      @x3 = x + @width
      @x4 = x
    end

    def y=(y)
      @y = @y1 = y
      @y2 = y
      @y3 = y + @height
      @y4 = y + @height
    end

    def width=(w)
      @width = w
      update_coords(@x, @y, w, @height)
    end

    def height=(h)
      @height = h
      update_coords(@x, @y, @width, h)
    end

    private

    def update_coords(x, y, w, h)
      @x1 = x
      @y1 = y
      @x2 = x + w
      @y2 = y
      @x4 = x
      @y4 = y + h
      @x3 = x + w
      @y3 = y + h
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby2d-0.9.5 lib/ruby2d/rectangle.rb
ruby2d-0.9.4 lib/ruby2d/rectangle.rb
ruby2d-0.9.3 lib/ruby2d/rectangle.rb
ruby2d-0.9.2 lib/ruby2d/rectangle.rb
ruby2d-0.9.1 lib/ruby2d/rectangle.rb
ruby2d-0.9.0 lib/ruby2d/rectangle.rb
ruby2d-0.8.1 lib/ruby2d/rectangle.rb
ruby2d-0.8.0 lib/ruby2d/rectangle.rb