Igis Documentation Beta

Class Gradient

public class Gradient : CanvasIdentifiedObject 

A Gradient is used to create a FillStyle for filling various objects.

Gradients have two flavors:

  1. Linear
  2. Radial

Usage:

There are several steps required to use a gradient:

  1. Create the Gradient object
  2. Add two or more ColorStops
  3. Setup the Gradient object
  4. Use the Gradient to initialize a StrokeStyle or FillStyle
  5. Because the Gradient is a CanvasIdentifiedObject, be sure it isReady prior to rendering
  6. Render the associated FillStyle prior to the object(s) to be filled with the gradient

Example:

var gradient : Gradient

init() {
    gradient = Gradient(mode:.linear(start:Point(x:0, y:60), end:Point(x:320, y:60)))
    gradient.addColorStop(ColorStop(position:0.0, color:Color(.red)))
	gradient.addColorStop(ColorStop(position:0.25, color:Color(.yellow)))
    gradient.addColorStop(ColorStop(position:0.5, color:Color(.green)))
    gradient.addColorStop(ColorStop(position:0.5, color:Color(.green)))
    gradient.addColorStop(ColorStop(position:0.5, color:Color(.green)))
}

override func setup(canvas:Canvas) {
    canvas.setup(gradient) 
}

override func render(canvas:Canvas) {
    if gradient.isReady {
	    let fillStyle = FillStyle(gradient:gradient)
	    canvas.render(fillStyle, rectangle)
	}
}
%161 Gradient Gradient CanvasIdentifiedObject CanvasIdentifiedObject Gradient->CanvasIdentifiedObject

Nested Types

Gradient.Mode

The Mode is used to determine whether this is a linear or radial Gradient.

Superclass

CanvasIdentifiedObject

Initializers

init(mode:​)

public init(mode:Mode) 

Creates a new Gradient

Parameters

mode Mode

Specifies the Gradient mode (linear or radial)

Properties

mode

public let mode : Mode

color​Stops

public private(set) var colorStops : [ColorStop]

Maintains a list of colorStops for this Gradient.

NB: This cannot be changed after setup() has been invoked.

Methods

add​Color​Stop(_:​)

public func addColorStop(_ colorStop:ColorStop) 

Adds a ColorStop to the Gradient.

Parameters

color​Stop Color​Stop

The ColorStop to be added