Sha256: 579fb06dfc11adf003a91af21067792cf52c2d793ab9baee726332b2f08772ad

Contents?: true

Size: 701 Bytes

Versions: 1

Compression:

Stored size: 701 Bytes

Contents

# image.rb

module Ruby2D
  class Image
    include Renderable

    attr_accessor :x, :y, :width, :height, :data
    attr_reader :path, :color

    def initialize(opts = {})
      @path = opts[:path]

      unless RUBY_ENGINE == 'opal'
        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

      self.color = opts[:color] || 'white'

      ext_image_init(@path)
      add
    end

    def color=(c)
      @color = Color.new(c)
    end

    def contains?(x, y)
      @x < x and @x + @width > x and @y < y and @y + @height > y
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby2d-0.4.0 lib/ruby2d/image.rb