Method: Ruby2D::Line#initialize

Defined in:
lib/ruby2d/line.rb

#initialize(x1: 0, y1: 0, x2: 100, y2: 100, z: 0, width: 2, color: nil, colour: nil, opacity: nil) ⇒ Line

Create an Line

Parameters:

  • x1 (Numeric) (defaults to: 0)
  • y1 (Numeric) (defaults to: 0)
  • x2 (Numeric) (defaults to: 100)
  • y2 (Numeric) (defaults to: 100)
  • width (Numeric) (defaults to: 2)

    The width or thickness of the line

  • 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



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby2d/line.rb', line 22

def initialize(x1: 0, y1: 0, x2: 100, y2: 100, z: 0,
               width: 2, color: nil, colour: nil, opacity: nil)
  @x1 = x1
  @y1 = y1
  @x2 = x2
  @y2 = y2
  @z = z
  @width = width
  self.color = color || colour || 'white'
  self.color.opacity = opacity unless opacity.nil?
  add
end