Skip to content

Instantly share code, notes, and snippets.

@theoretick
Created August 21, 2017 15:38
Show Gist options
  • Save theoretick/86ea021f83280a60e5e3d4c44a9792cb to your computer and use it in GitHub Desktop.
Save theoretick/86ea021f83280a60e5e3d4c44a9792cb to your computer and use it in GitHub Desktop.
//
// NSColorHelpers.swift
// MapPointMapper
//
// Created by Lucas Charles on 2/13/15.
// Copyright (c) 2015 dmiedema. All rights reserved.
//
import Foundation
import AppKit
extension NSColor {
class func randomColor() -> NSColor {
// Change bias based on http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
let golden_ratio_conjugate: CGFloat = 0.618033988749895
var hue = CGFloat(arc4random() % 255) / 255
hue += golden_ratio_conjugate
hue %= 1
return NSColor(hue: hue, saturation: 0.5, brightness: 0.95, alpha: 1.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment