package main

import (
	"github.com/gen2brain/raylib-go/raylib"
	"math"
)

func clamp01(v float32) float32 {
	if v < 0 {
		return 0
	}
	if v > 1 {
		return 1
	}
	return v
}

func GrayCurve(v, k float32) rl.Color {
	v = float32(math.Pow(float64(clamp01(v)), float64(k))) // k < 1 boosts highlights, k > 1 boosts shadows
	c := uint8(v * 255)
	return rl.Color{R: c, G: c, B: c, A: 255}
}

func LerpCurve(v, k float32, lo rl.Color, hi rl.Color) rl.Color {
	v = float32(math.Pow(float64(clamp01(v)), float64(k))) // k < 1 boosts highlights, k > 1 boosts shadows
	return rl.ColorLerp(lo, hi, v)
}

func Brightness(c rl.Color) float32 {
	r := float32(c.R) / 255
	g := float32(c.G) / 255
	b := float32(c.B) / 255
	return 0.2126*r + 0.7152*g + 0.0722*b
}
