| 1 |
// Various ways to generate single random colors |
| 2 |
|
| 3 |
package colorful |
| 4 |
|
| 5 |
// Creates a random dark, "warm" color through a restricted HSV space. |
| 6 |
func FastWarmColorWithRand(rand RandInterface) Color { |
| 7 |
return Hsv( |
| 8 |
rand.Float64()*360.0, |
| 9 |
0.5+rand.Float64()*0.3, |
| 10 |
0.3+rand.Float64()*0.3) |
| 11 |
} |
| 12 |
|
| 13 |
func FastWarmColor() Color { |
| 14 |
return FastWarmColorWithRand(getDefaultGlobalRand()) |
| 15 |
} |
| 16 |
|
| 17 |
// Creates a random dark, "warm" color through restricted HCL space. |
| 18 |
// This is slower than FastWarmColor but will likely give you colors which have |
| 19 |
// the same "warmness" if you run it many times. |
| 20 |
func WarmColorWithRand(rand RandInterface) (c Color) { |
| 21 |
for c = randomWarmWithRand(rand); !c.IsValid(); c = randomWarmWithRand(rand) { |
| 22 |
} |
| 23 |
return |
| 24 |
} |
| 25 |
|
| 26 |
func WarmColor() (c Color) { |
| 27 |
return WarmColorWithRand(getDefaultGlobalRand()) |
| 28 |
} |
| 29 |
|
| 30 |
func randomWarmWithRand(rand RandInterface) Color { |
| 31 |
return Hcl( |
| 32 |
rand.Float64()*360.0, |
| 33 |
0.1+rand.Float64()*0.3, |
| 34 |
0.2+rand.Float64()*0.3) |
| 35 |
} |
| 36 |
|
| 37 |
// Creates a random bright, "pimpy" color through a restricted HSV space. |
| 38 |
func FastHappyColorWithRand(rand RandInterface) Color { |
| 39 |
return Hsv( |
| 40 |
rand.Float64()*360.0, |
| 41 |
0.7+rand.Float64()*0.3, |
| 42 |
0.6+rand.Float64()*0.3) |
| 43 |
} |
| 44 |
|
| 45 |
func FastHappyColor() Color { |
| 46 |
return FastHappyColorWithRand(getDefaultGlobalRand()) |
| 47 |
} |
| 48 |
|
| 49 |
// Creates a random bright, "pimpy" color through restricted HCL space. |
| 50 |
// This is slower than FastHappyColor but will likely give you colors which |
| 51 |
// have the same "brightness" if you run it many times. |
| 52 |
func HappyColorWithRand(rand RandInterface) (c Color) { |
| 53 |
for c = randomPimpWithRand(rand); !c.IsValid(); c = randomPimpWithRand(rand) { |
| 54 |
} |
| 55 |
return |
| 56 |
} |
| 57 |
|
| 58 |
func HappyColor() (c Color) { |
| 59 |
return HappyColorWithRand(getDefaultGlobalRand()) |
| 60 |
} |
| 61 |
|
| 62 |
func randomPimpWithRand(rand RandInterface) Color { |
| 63 |
return Hcl( |
| 64 |
rand.Float64()*360.0, |
| 65 |
0.5+rand.Float64()*0.3, |
| 66 |
0.5+rand.Float64()*0.3) |
| 67 |
} |