コード例 #1
0
ファイル: chart.go プロジェクト: kutuluk/xterm-color-chart
func DrawBox(left, top, d, l int) {
	var approxer string
	switch currentComparer {
	case 0:
		approxer = "CIE76"
	case 1:
		approxer = "CIE94"
	case 2:
		approxer = "CIE2000"
	}

	r := d / 2
	for y := 0; y < d; y++ {
		for x := 0; x < d; x++ {
			a := 100.0 * float64(x-r) / float64(r)
			b := -100.0 * float64(y-r) / float64(r)
			_, c := color.Approximate(color.LabColor{float64(l), a, b}, comparers[currentComparer])
			//termbox.SetCell(x*2+left, y+top, ' ', background, termbox.Attribute(color))
			//termbox.SetCell(x*2+left+1, y+top, ' ', background, termbox.Attribute(color))
			fg := int(background)
			if y == 1 || y == 2 || y == d-2 {
				fgLab := color.XtermRGBPalette[c-17].Lab()
				if l > 50 {
					fgLab.L -= 50
					//fgLab.L = 20
				} else {
					fgLab.L += 50
					//fgLab.L = 70
				}
				_, fg = color.Approximate(fgLab, color.DeltaCIE2000{})
			}
			termbox.SetCell(x*2+left, y+top, ' ', termbox.Attribute(fg), termbox.Attribute(c))
			termbox.SetCell(x*2+left+1, y+top, ' ', termbox.Attribute(fg), termbox.Attribute(c))
		}

	}

	labLabel := "CIE L*a*b color space"
	if len(labLabel)+4 < d*2 {
		printString(left+2, top+1, labLabel)
		printString(left+2, top+2, fmt.Sprintf("Lightness = %d%%", l))
	}
	//printString(left+2, top+4, fmt.Sprintln("Press Up/Down key for change"))

	approxerLabel := fmt.Sprintf("Approximate by %s algorithm", approxer)
	if len(approxerLabel)+4 <= d*2 {
		printString(left+2, top+d-2, approxerLabel)
	}
	//printString(left+2, top+7, fmt.Sprintln("Press Left/Right key for change"))
}
コード例 #2
0
ファイル: chart.go プロジェクト: kutuluk/xterm-color-chart
func DrawCircle(left, top, r int, l float64) {

	var ch [2]rune
	point := func(xb, yb int) {
		xl := xb / r
		yl := yb / r
		distance, color := color.Approximate(color.LChColor{l, math.Sqrt(float64(xl*xl) + float64(yl*yl)), 180.0 * math.Atan2(float64(xl), float64(yl))}, comparers[currentComparer])
		//distance, color := color.Palette(color.LabColor{l, float64(xb * 120.0 / r), float64(-yb * 120.0 / r)}, color.DeltaCIE94{})
		if distance < 50 {
			ch[0] = ' '
			ch[1] = ' '
		} else {
			//ch[0] = '¤'
			//ch[1] = '¤'
			ch[0] = '('
			ch[1] = ')'
		}
		termbox.SetCell((xb+r)*2+left, yb+r+top, ch[0], termbox.Attribute(0), termbox.Attribute(color))
		termbox.SetCell((xb+r)*2+left+1, yb+r+top, ch[1], termbox.Attribute(0), termbox.Attribute(color))
	}

	// алгоритм Брезенхэма
	line := func(x, y1, y2 int) {
		for yf := y1; yf <= y2; yf++ {
			point(x, yf)
		}
	}

	x := 0
	y := r
	d := 3 - 2*r
	for x <= y {
		line(x, -y, y)
		line(-x, -y, y)
		line(y, -x, x)
		line(-y, -x, x)
		if d < 0 {
			d += 4*x + 6
		} else {
			d += 4*(x-y) + 10
			y--
		}
		x++
	}
}