Exemple #1
0
func print_json(palette vibrant.Palette) {
	out := map[string]interface{}{}
	for name, sw := range palette.ExtractAwesome() {
		if output_rgb {
			r, g, b := sw.Color.RGB()
			out[name] = map[string]int{"r": r, "g": g, "b": b}
		} else {
			out[name] = swatch{sw.Color.RGBHex(), sw.Color.TitleTextColor().RGBHex()}
		}
	}
	var b []byte
	var err error
	if output_compress {
		b, err = json.Marshal(out)
	} else {
		b, err = json.MarshalIndent(out, "", "  ")
	}
	checkErr(err)

	str := string(b)
	if output_lowercase {
		str = strings.ToLower(str)
	}
	fmt.Println(str)
}
Exemple #2
0
func print_css(palette vibrant.Palette) {
	sp := " "
	lf := "\n"
	tb := "  "
	sc := ";"
	if output_compress {
		sp = ""
		lf = ""
		tb = ""
		sc = ""
	}
	for name, sw := range palette.ExtractAwesome() {
		var bgcolor string
		var fgcolor string
		if output_rgb {
			bgcolor = rgb(sw.Color.RGB())
			fgcolor = rgb(sw.Color.TitleTextColor().RGB())
		} else {
			bgcolor = sw.Color.RGBHex()
			fgcolor = sw.Color.TitleTextColor().RGBHex()
		}
		if output_lowercase {
			name = strings.ToLower(name)
			bgcolor = strings.ToLower(bgcolor)
			fgcolor = strings.ToLower(fgcolor)
		}
		if output_compress && !output_rgb {
			bgcolor = shorthex(bgcolor)
			fgcolor = shorthex(fgcolor)
		}
		fmt.Printf(".%s%s{%s", name, sp, lf)
		fmt.Printf("%sbackground-color:%s%s;%s", tb, sp, bgcolor, lf)
		fmt.Printf("%scolor:%s%s%s%s}%s", tb, sp, fgcolor, sc, lf, lf)
	}
}
Exemple #3
0
func print_plain(palette vibrant.Palette) {
	for name, sw := range palette.ExtractAwesome() {
		fmt.Printf("% 12s: %s, population: %d\n", name, sw.Color.RGBHex(), sw.Population)
	}
}