Skip to content

sozorogami/SackOfRainbows

Repository files navigation

SackOfRainbows

SackOfRainbows provides an expressive syntax for creating color generators. Chain generators in serial or parallel to easily produce gradients and complex patterns.

Installation

SackOfRainbows is written in Swift 2.0 and requires Xcode 7.

Via Cocoapods

Add the following line to your Podfile and run pod install.

pod 'SackOfRainbows'

Usage

The basics

To make a single color, use theColor(). All your favorite UIColors have been aliased for easy use.

var redGenerator = theColor(red)
redGenerator.next() // returns red
redGenerator.next() // returns nil

You can generate a bunch of colors in order using theColors() like so:

var rainbow = theColors(red, orange, yellow, green, blue,
    UIColor(red: 0.29, green: 0.0, blue: 0.51, alpha: 1), purple)
rainbow.next() // returns red
rainbow.next() // returns orange
rainbow.next() // returns yellow
// ...

Making a series of colors in a gradient is easy as well. Just indicate the start color, end color, and how many steps start to finish.

var tequilaSunrise = gradient().from(orange).to(red).steps(10)
tequilaSunrise.next() // returns orange
tequilaSunrise.next() // returns a slightly reddish orange
tequilaSunrise.next() // returns a slightly more reddish orange
// ...

basic

Chaining

To chain generators in sequence, use then().

let batman = theColors(blue, black)
let robin = theColors(yellow, green, red)
var batmanAndRobin = batman.then(robin)

To chain in parallel, use alternate().

var olympics = alternate(batman, robin)

batlympics

Repeating

Repeat a fixed number of times with times().

var doubleRainbow = rainbow.times(2)

doublerainbow

To enter a world of endless color, use forever().

let blueToWhite = gradient().from(blue).to(white).steps(10)
let whiteToBlue = gradient().from(white).to(blue).steps(10)
var allTheWayAcrossTheSky = blueToWhite.then(whiteToBlue).forever()

alltheway

License

SackOfRainbows is released under the MIT License.

About

SackOfRainbows provides an expressive syntax for creating color generators in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published