...

Source file src/github.com/lucasb-eyer/go-colorful/colorgens.go

Documentation: github.com/lucasb-eyer/go-colorful

     1  // Various ways to generate single random colors
     2  
     3  package colorful
     4  
     5  import (
     6  	"math/rand"
     7  )
     8  
     9  // Creates a random dark, "warm" color through a restricted HSV space.
    10  func FastWarmColor() Color {
    11  	return Hsv(
    12  		rand.Float64()*360.0,
    13  		0.5+rand.Float64()*0.3,
    14  		0.3+rand.Float64()*0.3)
    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 WarmColor() (c Color) {
    21  	for c = randomWarm(); !c.IsValid(); c = randomWarm() {
    22  	}
    23  	return
    24  }
    25  
    26  func randomWarm() Color {
    27  	return Hcl(
    28  		rand.Float64()*360.0,
    29  		0.1+rand.Float64()*0.3,
    30  		0.2+rand.Float64()*0.3)
    31  }
    32  
    33  // Creates a random bright, "pimpy" color through a restricted HSV space.
    34  func FastHappyColor() Color {
    35  	return Hsv(
    36  		rand.Float64()*360.0,
    37  		0.7+rand.Float64()*0.3,
    38  		0.6+rand.Float64()*0.3)
    39  }
    40  
    41  // Creates a random bright, "pimpy" color through restricted HCL space.
    42  // This is slower than FastHappyColor but will likely give you colors which
    43  // have the same "brightness" if you run it many times.
    44  func HappyColor() (c Color) {
    45  	for c = randomPimp(); !c.IsValid(); c = randomPimp() {
    46  	}
    47  	return
    48  }
    49  
    50  func randomPimp() Color {
    51  	return Hcl(
    52  		rand.Float64()*360.0,
    53  		0.5+rand.Float64()*0.3,
    54  		0.5+rand.Float64()*0.3)
    55  }
    56  

View as plain text