...

Source file src/github.com/mazznoer/csscolorparser/example_test.go

Documentation: github.com/mazznoer/csscolorparser

     1  package csscolorparser_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/mazznoer/csscolorparser"
     7  )
     8  
     9  func Example_namedColor() {
    10  	c, err := csscolorparser.Parse("gold")
    11  
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f\n", c.R, c.G, c.B, c.A)
    17  	fmt.Println(c.RGBA255())
    18  	fmt.Println(c.HexString())
    19  	fmt.Println(c.RGBString())
    20  	// Output:
    21  	// R:1.000, G:0.843, B:0.000, A:1.000
    22  	// 255 215 0 255
    23  	// #ffd700
    24  	// rgb(255,215,0)
    25  }
    26  
    27  func Example_rgbColor() {
    28  	c, err := csscolorparser.Parse("rgba(100%, 0%, 0%, 0.5)")
    29  
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  
    34  	fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f\n", c.R, c.G, c.B, c.A)
    35  	fmt.Println(c.RGBA255())
    36  	fmt.Println(c.HexString())
    37  	fmt.Println(c.RGBString())
    38  	// Output:
    39  	// R:1.000, G:0.000, B:0.000, A:0.500
    40  	// 255 0 0 128
    41  	// #ff000080
    42  	// rgba(255,0,0,0.5)
    43  }
    44  

View as plain text