Class: EduDraw::AnimationPen
Overview
An AnimatedPen is a special Pen that is used for drawing animated shapes
Instance Attribute Summary
Attributes inherited from Pen
#angle, #color, #shapes, #x, #y
Instance Method Summary collapse
-
#draw_frame(&block) ⇒ Object
Defines what the pen needs to draw every frame.
-
#each_frame(&block) ⇒ Object
Defines what needs to be done every frame before drawing.
-
#initialize(x, y, angle, color) ⇒ AnimationPen
constructor
Creates a new AnimationPen.
- #update ⇒ Object
Methods inherited from Pen
#angle_in_rad, #down!, #down?, #fill, #move, #turn_left, #turn_right, #up!, #up?
Constructor Details
#initialize(x, y, angle, color) ⇒ AnimationPen
Creates a new AnimationPen
9 10 11 12 13 |
# File 'lib/edu_draw/animation_pen.rb', line 9 def initialize(*args) super @update_block = -> {} @draw_block = -> {} end |
Instance Method Details
#draw_frame(&block) ⇒ Object
Every Pen#move outside this block will draw only in the first frame
Remember to set the state of the pen so that it can start drawing the next frame. In the given example the last ‘pen.turn_right 90` is not neccessary for the shape, but without it, the pen would draw the rectangle in a different direction on the next frame. Maybe, this is what you need, but it is still recommended to do these changes in the #each_frame-block.
Defines what the pen needs to draw every frame
48 49 50 |
# File 'lib/edu_draw/animation_pen.rb', line 48 def draw_frame &block @draw_block = block end |
#each_frame(&block) ⇒ Object
Defines what needs to be done every frame before drawing
22 23 24 |
# File 'lib/edu_draw/animation_pen.rb', line 22 def each_frame &block @update_block = block end |
#update ⇒ Object
53 54 55 56 57 |
# File 'lib/edu_draw/animation_pen.rb', line 53 def update empty_shapes @update_block.call @draw_block.call end |