Class: Vamp::Graphic::Dotter
- Inherits:
-
Object
- Object
- Vamp::Graphic::Dotter
- 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
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
number of dots in y direction.
-
#width ⇒ Object
readonly
number of dots in x direction.
Instance Method Summary collapse
-
#check(x, y) ⇒ Object
check if (x, y) is on the screen, fails if not.
-
#clear ⇒ Object
clear screen of all dots.
-
#dot(x, y) ⇒ Object
put dot at x, ys.
-
#dot?(x, y) ⇒ Boolean
is there a dot at x, y.
-
#in?(x, y) ⇒ Boolean
check if (x, y) is on the screen.
-
#initialize(width, height) ⇒ Dotter
constructor
A new instance of Dotter.
-
#screen ⇒ Object
return complete screen as string representation.
-
#undot(x, y) ⇒ Object
remove dot at x, y.
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
#height ⇒ Object (readonly)
number of dots in y direction
7 8 9 |
# File 'lib/vamp/graphic/dotter.rb', line 7 def height @height end |
#width ⇒ Object (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 |
#clear ⇒ Object
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
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
42 43 44 |
# File 'lib/vamp/graphic/dotter.rb', line 42 def in?(x, y) (0...width) === x && (0...height) === y end |
#screen ⇒ Object
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 |