...

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

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

     1  package main
     2  
     3  import "fmt"
     4  import "github.com/lucasb-eyer/go-colorful"
     5  import "image"
     6  import "image/draw"
     7  import "image/png"
     8  import "os"
     9  
    10  func main() {
    11  	blocks := 10
    12  	blockw := 40
    13  	img := image.NewRGBA(image.Rect(0, 0, blocks*blockw, 200))
    14  
    15  	c1, _ := colorful.Hex("#fdffcc")
    16  	c2, _ := colorful.Hex("#242a42")
    17  
    18  	// Use these colors to get invalid RGB in the gradient.
    19  	//c1, _ := colorful.Hex("#EEEF61")
    20  	//c2, _ := colorful.Hex("#1E3140")
    21  
    22  	for i := 0; i < blocks; i++ {
    23  		draw.Draw(img, image.Rect(i*blockw, 0, (i+1)*blockw, 40), &image.Uniform{c1.BlendHsv(c2, float64(i)/float64(blocks-1))}, image.Point{}, draw.Src)
    24  		draw.Draw(img, image.Rect(i*blockw, 40, (i+1)*blockw, 80), &image.Uniform{c1.BlendLuv(c2, float64(i)/float64(blocks-1))}, image.Point{}, draw.Src)
    25  		draw.Draw(img, image.Rect(i*blockw, 80, (i+1)*blockw, 120), &image.Uniform{c1.BlendRgb(c2, float64(i)/float64(blocks-1))}, image.Point{}, draw.Src)
    26  		draw.Draw(img, image.Rect(i*blockw, 120, (i+1)*blockw, 160), &image.Uniform{c1.BlendLab(c2, float64(i)/float64(blocks-1))}, image.Point{}, draw.Src)
    27  		draw.Draw(img, image.Rect(i*blockw, 160, (i+1)*blockw, 200), &image.Uniform{c1.BlendHcl(c2, float64(i)/float64(blocks-1))}, image.Point{}, draw.Src)
    28  
    29  		// This can be used to "fix" invalid colors in the gradient.
    30  		//draw.Draw(img, image.Rect(i*blockw,160,(i+1)*blockw,200), &image.Uniform{c1.BlendHcl(c2, float64(i)/float64(blocks-1)).Clamped()}, image.Point{}, draw.Src)
    31  	}
    32  
    33  	toimg, err := os.Create("colorblend.png")
    34  	if err != nil {
    35  		fmt.Printf("Error: %v", err)
    36  		return
    37  	}
    38  	defer toimg.Close()
    39  
    40  	png.Encode(toimg, img)
    41  }
    42  

View as plain text