Class: Dieses::Application::Pen::Draw

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Elements, Movements
Defined in:
lib/dieses/application/pen.rb

Defined Under Namespace

Modules: Elements, Movements

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Movements

#cross, #down, #left, #move, #right, #up

Methods included from Elements

#cline, #hline, #rect, #square, #vline

Constructor Details

#initialize(pen, ruler, pos: Undefined) ⇒ Draw

Returns a new instance of Draw.



27
28
29
30
31
32
# File 'lib/dieses/application/pen.rb', line 27

def initialize(pen, ruler, pos: Undefined)
  @pen    = pen
  @pos    = Undefined.default(pos, Geometry::Point::Mutable.cast(canvas.position))
  @ruler  = ruler
  @buffer = Set.new
end

Class Method Details

.call(pen, ruler, &block) ⇒ Object



23
24
25
# File 'lib/dieses/application/pen.rb', line 23

def self.call(pen, ruler, &block)
  Draw.new(pen, ruler).(&block)
end

Instance Method Details

#call(&block) ⇒ Object



48
49
50
51
# File 'lib/dieses/application/pen.rb', line 48

def call(&block)
  instance_exec(&block)
  put
end

#repeat(count = nil, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dieses/application/pen.rb', line 34

def repeat(count = nil, &block)
  self.class.new(pen, ruler, pos: pos.dup).instance_exec do
    1.step(count) do
      prev = pos.dup
      instance_exec(&block)
      put

      break if pos == prev || perfect.outside?(pos)
    rescue Offsite
      break
    end
  end
end