Sha256: 5c31dd82249db1ba4bb36d618a4826f1f60bc88f0b06191d9779e2320d14d550

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

module Vamp
  module Graphic
    # basis class for graphic implementations
    # you have to implement :dot, :undot, :clear and :screen
    class Dotter
      attr_reader :width        # number of dots in x direction
      attr_reader :height       # number of dots in y direction

      def initialize(width, height)
        @width = width
        @height = height
        clear
      end

      # put dot at x, ys
      def dot(x, y)
        check(x, y)
        self
      end

      # is there a dot at x, y
      def dot?(x, y)
        check(x, y)
      end

      # remove dot at x, y
      def undot(x, y)
        check(x, y)
        self
      end

      # clear screen of all dots
      def clear
        self
      end

      # return complete screen as string representation
      def screen
      end

      # check if (x, y) is on the screen
      def in?(x, y)
        (0...width)  === x && (0...height) === y
      end

      # check if (x, y) is on the screen, fails if not
      def check(x, y)
        fail "for (#{x}, #{y}}: x not in [0, #{width}["  unless (0...width)  === x
        fail "for (#{x}, #{y}}: y not in [0, #{height}[" unless (0...height) === y
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vamp-0.2.0 lib/vamp/graphic/dotter.rb
vamp-0.1.8 lib/vamp/graphic/dotter.rb
vamp-0.1.7 lib/vamp/graphic/dotter.rb
vamp-0.1.6 lib/vamp/graphic/dotter.rb
vamp-0.1.5 lib/vamp/graphic/dotter.rb
vamp-0.1.4 lib/vamp/graphic/dotter.rb