Class: Browser::Canvas::Gradient

Inherits:
Object
  • Object
show all
Includes:
Native
Defined in:
opal/browser/canvas/gradient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, *args, &block) ⇒ Gradient

Returns a new instance of Gradient.


8
9
10
11
12
13
14
15
16
17
18
# File 'opal/browser/canvas/gradient.rb', line 8

def initialize(context, *args, &block)
  @context = context

  super(case args.length
    when 4 then `#{@context.to_n}.createLinearGradient.apply(self, args)`
    when 6 then `#{@context.to_n}.createRadialGradient.apply(self, args)`
    else raise ArgumentError, "don't know where to dispatch"
  end)

  instance_eval(&block)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


6
7
8
# File 'opal/browser/canvas/gradient.rb', line 6

def context
  @context
end

Instance Method Details

#add(position, color) ⇒ Object


20
21
22
23
24
# File 'opal/browser/canvas/gradient.rb', line 20

def add(position, color)
  `#{@context.to_n}.addColorStop(position, color)`

  self
end