Author
Travis Kirton


Colors & Locations

You can change the colors and locations of a gradient.

Colors

By default, a gradient has the following 2 colors:

[C4Pink, C4Blue]

This implies that the gradient will draw C4Pink from it’s start point to C4Blue at its end point.

You can change this value by setting the colors variable with an array of at least 2 Color objects.

gradient.colors = [C4Blue, C4Grey, C4Pink, C4Purple]

Locations

By default, a gradient has the following 2 locations:

[0, 1]

These “normalized” values map to the start and end points of the gradient. If you have more than 2 colors you will need to also specify an array of locations that have the same count as the colors array.

gradient.locations = [0, 0.33, 0.66, 1.0]

Example

let g = Gradient(frame: canvas.frame)
g.colors = [C4Blue, C4Grey, C4Pink, C4Purple]
g.locations = [0, 0.33, 0.66, 1.0]
canvas.add(g)