Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Color Unique String support
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo082 committed May 23, 2017
1 parent 8610cc3 commit d0363dc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Core/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ public static function fromHex(string $hex): Color {
return new Color($r, $g, $b, 1);
}

/**
* Unique color from string
* @param string $string
* @param int $delta
* @return Color
*/
public static function fromString(string $string, int $delta = 0): Color {
$delta = min(16777215 - 1, $delta);
$hash = crc32($string) % (16777215 - $delta) + $delta;
$hex = dechex($hash);
$hex = str_pad($hex, 6 - count($hex), "0", STR_PAD_LEFT);
return self::fromHex("#".$hex);
}

/**
* @param Color $color
* @param int $delta
Expand Down

0 comments on commit d0363dc

Please sign in to comment.