Class: Dcr::Program
- Inherits:
-
Object
- Object
- Dcr::Program
- Includes:
- Glimmer::DataBinding::ObservableModel
- Defined in:
- app/models/dcr/program.rb
Overview
A DCR program that takes text (representing commands) and board width/height for drawing polygons It has a current location (x/y) and angle. Angle is clockwise, with 0 being upward (north).
Constant Summary collapse
- STICK_FIGURE_SIZE =
30
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#canvas_height ⇒ Object
Returns the value of attribute canvas_height.
-
#canvas_width ⇒ Object
Returns the value of attribute canvas_width.
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#expanded_commands ⇒ Object
Returns the value of attribute expanded_commands.
-
#location_x ⇒ Object
Returns the value of attribute location_x.
-
#location_y ⇒ Object
Returns the value of attribute location_y.
-
#polygons ⇒ Object
array of polygon objects including array of point arrays and color to be drawn/filled in GUI.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text: '', canvas_width: 800, canvas_height: 600) ⇒ Program
constructor
A new instance of Program.
- #new_polygon! ⇒ Object
- #reset! ⇒ Object
-
#reset_angle! ⇒ Object
Resets angle (0 means upward / north).
- #reset_location! ⇒ Object
- #reset_next_color_index! ⇒ Object
- #reset_polygons! ⇒ Object
Constructor Details
#initialize(text: '', canvas_width: 800, canvas_height: 600) ⇒ Program
Returns a new instance of Program.
38 39 40 41 42 43 44 |
# File 'app/models/dcr/program.rb', line 38 def initialize(text: '', canvas_width: 800, canvas_height: 600) @commands = [] @canvas_width = canvas_width @canvas_height = canvas_height reset! self.text = text end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def angle @angle end |
#canvas_height ⇒ Object
Returns the value of attribute canvas_height.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def canvas_height @canvas_height end |
#canvas_width ⇒ Object
Returns the value of attribute canvas_width.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def canvas_width @canvas_width end |
#commands ⇒ Object
Returns the value of attribute commands.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def commands @commands end |
#expanded_commands ⇒ Object
Returns the value of attribute expanded_commands.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def @expanded_commands end |
#location_x ⇒ Object
Returns the value of attribute location_x.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def location_x @location_x end |
#location_y ⇒ Object
Returns the value of attribute location_y.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def location_y @location_y end |
#polygons ⇒ Object
array of polygon objects including array of point arrays and color to be drawn/filled in GUI
36 37 38 |
# File 'app/models/dcr/program.rb', line 36 def polygons @polygons end |
#text ⇒ Object
Returns the value of attribute text.
33 34 35 |
# File 'app/models/dcr/program.rb', line 33 def text @text end |
Instance Method Details
#new_polygon! ⇒ Object
94 95 96 |
# File 'app/models/dcr/program.rb', line 94 def new_polygon! @polygons << Polygon.new(location_x, location_y) end |
#reset! ⇒ Object
71 72 73 74 75 76 |
# File 'app/models/dcr/program.rb', line 71 def reset! reset_location! reset_angle! reset_next_color_index! reset_polygons! end |
#reset_angle! ⇒ Object
Resets angle (0 means upward / north). Angle value is clockwise.
85 86 87 |
# File 'app/models/dcr/program.rb', line 85 def reset_angle! self.angle = 0 # means pointing upward (north) end |
#reset_location! ⇒ Object
78 79 80 81 82 |
# File 'app/models/dcr/program.rb', line 78 def reset_location! # also set stick_figure_location_x and stick_figure_location_y, which is slightly different self.location_x = (canvas_width - STICK_FIGURE_SIZE) / 2.0 self.location_y = (canvas_height - STICK_FIGURE_SIZE) / 2.0 end |
#reset_next_color_index! ⇒ Object
98 99 100 |
# File 'app/models/dcr/program.rb', line 98 def reset_next_color_index! Command::Color.reset_next_color_index! end |