Class: Shape
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#fill ⇒ Object
Returns the value of attribute fill.
-
#height ⇒ Object
Returns the value of attribute height.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#layer ⇒ Object
Returns the value of attribute layer.
-
#position ⇒ Object
Returns the value of attribute position.
-
#stroke ⇒ Object
Returns the value of attribute stroke.
-
#stroke_color ⇒ Object
Returns the value of attribute stroke_color.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.rectangle(position:, width:, height:, color: Color.palette.black, stroke_color: nil, stroke: 0) ⇒ Object
rubocop:enable Metrics/ParameterLists.
Instance Method Summary collapse
- #destroy ⇒ Object
- #draw ⇒ Object
-
#initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil) ⇒ Shape
constructor
rubocop:disable Metrics/ParameterLists.
Methods included from UserInputs
#on_click, #on_click_do, #on_cursor_down, #on_cursor_down_do, #on_cursor_left, #on_cursor_left_do, #on_cursor_right, #on_cursor_right_do, #on_cursor_up, #on_cursor_up_do, #on_mouse_button_left, #on_mouse_button_left_do, #on_space_bar, #on_space_bar_do
Constructor Details
#initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil) ⇒ Shape
rubocop:disable Metrics/ParameterLists
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fantasy/shape.rb', line 9 def initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil) @kind = kind @position = position @width = width @height = height @stroke = stroke @color = color @fill = fill @stroke_color = stroke_color @layer = 1 Global.shapes << self end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def color @color end |
#fill ⇒ Object
Returns the value of attribute fill.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def fill @fill end |
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def height @height end |
#kind ⇒ Object
Returns the value of attribute kind.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def kind @kind end |
#layer ⇒ Object
Returns the value of attribute layer.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def layer @layer end |
#position ⇒ Object
Returns the value of attribute position.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def position @position end |
#stroke ⇒ Object
Returns the value of attribute stroke.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def stroke @stroke end |
#stroke_color ⇒ Object
Returns the value of attribute stroke_color.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def stroke_color @stroke_color end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/fantasy/shape.rb', line 6 def width @width end |
Class Method Details
.rectangle(position:, width:, height:, color: Color.palette.black, stroke_color: nil, stroke: 0) ⇒ Object
rubocop:enable Metrics/ParameterLists
24 25 26 |
# File 'lib/fantasy/shape.rb', line 24 def self.rectangle(position:, width:, height:, color: Color.palette.black, stroke_color: nil, stroke: 0) Shape.new(kind: "rectangle", position: position, width: width, height: height, color: color) end |
Instance Method Details
#destroy ⇒ Object
37 38 39 |
# File 'lib/fantasy/shape.rb', line 37 def destroy Global.shapes.delete(self) end |
#draw ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/fantasy/shape.rb', line 28 def draw case @kind when "rectangle" draw_rectangle else raise "Shape.kind not supported: '#{@kind}'. Supported kinds: 'rectangle'" end end |