Class: Vamp::Graphic::Dotter

Inherits:
Object
  • Object
show all
Defined in:
lib/vamp/graphic/dotter.rb

Overview

basis class for graphic implementations you have to implement :dot, :undot, :clear and :screen

Direct Known Subclasses

TextDotter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ Dotter

Returns a new instance of Dotter.



9
10
11
12
13
# File 'lib/vamp/graphic/dotter.rb', line 9

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

Instance Attribute Details

#heightObject (readonly)

number of dots in y direction



7
8
9
# File 'lib/vamp/graphic/dotter.rb', line 7

def height
  @height
end

#widthObject (readonly)

number of dots in x direction



6
7
8
# File 'lib/vamp/graphic/dotter.rb', line 6

def width
  @width
end

Instance Method Details

#check(x, y) ⇒ Object

check if (x, y) is on the screen, fails if not



47
48
49
50
# File 'lib/vamp/graphic/dotter.rb', line 47

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

#clearObject

clear screen of all dots



33
34
35
# File 'lib/vamp/graphic/dotter.rb', line 33

def clear
  self
end

#dot(x, y) ⇒ Object

put dot at x, ys



16
17
18
19
# File 'lib/vamp/graphic/dotter.rb', line 16

def dot(x, y)
  check(x, y)
  self
end

#dot?(x, y) ⇒ Boolean

is there a dot at x, y

Returns:

  • (Boolean)


22
23
24
# File 'lib/vamp/graphic/dotter.rb', line 22

def dot?(x, y)
  check(x, y)
end

#in?(x, y) ⇒ Boolean

check if (x, y) is on the screen

Returns:

  • (Boolean)


42
43
44
# File 'lib/vamp/graphic/dotter.rb', line 42

def in?(x, y)
  (0...width)  === x && (0...height) === y
end

#screenObject

return complete screen as string representation



38
39
# File 'lib/vamp/graphic/dotter.rb', line 38

def screen
end

#undot(x, y) ⇒ Object

remove dot at x, y



27
28
29
30
# File 'lib/vamp/graphic/dotter.rb', line 27

def undot(x, y)
  check(x, y)
  self
end