Forked from JohnCoates/generateRandomPastelColor.swift
Last active
March 5, 2021 21:40
Revisions
-
alexwal revised this gist
Mar 5, 2021 . 1 changed file with 14 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,18 @@ // Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 // Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro // Method randomly generates a pastel color, and optionally mixes it with another color import UIKit func randomPastelColor(mixedWith mixColor: UIColor? = nil) -> UIColor { // Mix the color let mixColor: UIColor = mixColor ?? .lightGray var mixRed: CGFloat = 0, mixGreen: CGFloat = 0, mixBlue: CGFloat = 0; mixColor.getRed(&mixRed, green: &mixGreen, blue: &mixBlue, alpha: nil) // Randomly generate number in closure let randomColor: () -> CGFloat = { CGFloat(arc4random() % 256 ) / 256 } let red = (randomColor() + mixRed) / 2; let green = (randomColor() + mixGreen) / 2; let blue = (randomColor() + mixBlue) / 2; return UIColor(red: red, green: green, blue: blue, alpha: 1) } -
JohnCoates revised this gist
Jul 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 // Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro // Method randomly generates a pastel color, and optionally mixes it with another color func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor { // Randomly generate number in closure let randomColorGenerator = { ()-> CGFloat in -
JohnCoates revised this gist
Jul 6, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ // Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 // Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro // Method generates a pastel color, and optionally mixes it with another color func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor { // Randomly generate number in closure let randomColorGenerator = { ()-> CGFloat in -
JohnCoates revised this gist
Jul 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 // Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor { // Randomly generate number in closure let randomColorGenerator = { ()-> CGFloat in -
JohnCoates renamed this gist
Jul 6, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
JohnCoates revised this gist
Jul 6, 2015 . 1 changed file with 21 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,24 @@ // Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 // Question: Algorithm to randomly generate an aesthetically-pleasing color palette Brian Gianforcaro func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor { // Randomly generate number in closure let randomColorGenerator = { ()-> CGFloat in CGFloat(arc4random() % 256 ) / 256 } var red: CGFloat = randomColorGenerator() var green: CGFloat = randomColorGenerator() var blue: CGFloat = randomColorGenerator() // Mix the color if let mixColor = mixColor { var mixRed: CGFloat = 0, mixGreen: CGFloat = 0, mixBlue: CGFloat = 0; mixColor.getRed(&mixRed, green: &mixGreen, blue: &mixBlue, alpha: nil) red = (red + mixRed) / 2; green = (green + mixGreen) / 2; blue = (blue + mixBlue) / 2; } return UIColor(red: red, green: green, blue: blue, alpha: 1) } -
JohnCoates created this gist
Jul 6, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 // Question: Algorithm to randomly generate an aesthetically-pleasing color palette Brian Gianforcaro func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor { // Randomly generate number in closure let randomColorGenerator = { ()-> CGFloat in CGFloat(arc4random() % 256 ) / 256 } var red: CGFloat = randomColorGenerator() var green: CGFloat = randomColorGenerator() var blue: CGFloat = randomColorGenerator() // Mix the color if let mixColor = mixColor { var mixRed: CGFloat = 0, mixGreen: CGFloat = 0, mixBlue: CGFloat = 0; mixColor.getRed(&mixRed, green: &mixGreen, blue: &mixBlue, alpha: nil) red = (red + mixRed) / 2; green = (green + mixGreen) / 2; blue = (blue + mixBlue) / 2; } return UIColor(red: red, green: green, blue: blue, alpha: 1) }