Class: Ruby2D::Square

Inherits:
Rectangle show all
Defined in:
lib/ruby2d/square.rb

Overview

A square

Instance Attribute Summary collapse

Attributes inherited from Quad

#x1, #x2, #x3, #x4, #y1, #y2, #y3, #y4

Attributes included from Renderable

#color, #height, #width, #x, #y, #z

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rectangle

#contains?, #height=, #width=, #x=, #y=

Methods inherited from Quad

#color=, #contains?

Methods included from Renderable

#add, #contains?, #remove

Constructor Details

#initialize(x: 0, y: 0, size: 100, z: 0, color: nil, colour: nil, opacity: nil) ⇒ Square

Create an square

Parameters:

  • x (Numeric) (defaults to: 0)
  • y (Numeric) (defaults to: 0)
  • size (Numeric) (defaults to: 100)

    is width and height

  • z (Numeric) (defaults to: 0)
  • color (String, Array) (defaults to: nil)

    A single colour or an array of exactly 4 colours

  • opacity (Numeric) (defaults to: nil)

    Opacity of the image when rendering

Raises:

  • (ArgumentError)

    if an array of colours does not have 4 entries



18
19
20
21
22
# File 'lib/ruby2d/square.rb', line 18

def initialize(x: 0, y: 0, size: 100, z: 0, color: nil, colour: nil, opacity: nil)
  @size = size
  super(x: x, y: y, width: size, height: size, z: z,
        color: color, colour: colour, opacity: opacity)
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/ruby2d/square.rb', line 8

def size
  @size
end

Class Method Details

.draw(x:, y:, size:, color:) ⇒ Object



29
30
31
32
33
# File 'lib/ruby2d/square.rb', line 29

def self.draw(x:, y:, size:, color:)
  super(x: x, y: y,
        width: size, height: size,
        color: color)
end