Ilysa by Example: Light - Gradient

Ilysa supports gradients.

package main
import (
    "fmt"
    "github.com/shasderias/ilysa"
    "github.com/shasderias/ilysa/beatsaber"
    "github.com/shasderias/ilysa/colorful"
    "github.com/shasderias/ilysa/colorful/gradient"
    "github.com/shasderias/ilysa/context"
    "github.com/shasderias/ilysa/ease"
    "github.com/shasderias/ilysa/evt"
    "github.com/shasderias/ilysa/light"
    "github.com/shasderias/ilysa/timer"
    "github.com/shasderias/ilysa/transform"
)

Define a few colors.

var (
    Red   = colorful.MustParseHex("#FF0000")
    Green = colorful.MustParseHex("#00FF00")
    Blue  = colorful.MustParseHex("#0000FF")
)

gradient.New() defines a gradient with the specified colors equidistant from each other.

var (
    RGBGrad = gradient.New(Red, Blue, Green)
    RBGrad  = gradient.New(Red, Blue)
)

Gradients with specific positions can be defined like so. The positions must be sorted, the first position must be 0.0 and the last position must be 1.0.

var RGBSkewedGrad = gradient.Table{
    {Col: Red, Pos: 0.0},
    {Col: Green, Pos: 0.3},
    {Col: Blue, Pos: 1.0},
}
func main() {
    m, _ := beatsaber.NewMockMap(beatsaber.EnvironmentOrigins, 120, "[]")
    p := ilysa.New(m)

Once you have a gradient, you can get the color at a position by calling the Lerp method.

    fmt.Println(RBGrad.Lerp(0.5))

From here, changing the color of a light through a gradient is trivial. This fades the back lasers from red to green to blue.

    p.Range(timer.Rng(0, 1, 10, ease.Linear), func(ctx context.Context) {
        ctx.NewRGBLighting(
            evt.WithLight(evt.BackLasers),
            evt.WithColor(RGBSkewedGrad.Lerp(ctx.T())),
        )
    })

As is displaying a gradient over a light.

    l := transform.Light(light.NewBasic(p, evt.BackLasers),
        transform.DivideSingle(),
    )

ctx.LightIDT() is only defined within a ctx.Light() context, it is like ctx.T() but for light ID sequences.

    p.Sequence(timer.Beat(2), func(ctx context.Context) {
        ctx.Light(l, func(ctx context.LightContext) {
            ctx.NewRGBLighting(
                evt.WithColor(RGBGrad.Lerp(ctx.LightIDT())),
            )
        })
    })
    p.Dump()
}
$ go run light-gradient.go
{0.2637342897946341 0.08657167566646633 0.3628242653977132 1}
[
    {"_customData":{"_color":[1,0,0,1]},"_time":0,"_type":0,"_value":5},
    {"_customData":{"_color":[0.75,0.273,0,1]},"_time":0.11111,"_type":0,"_value":5},
    {"_customData":{"_color":[0.364,0.656,0,1]},"_time":0.22222,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.933,0.052,1]},"_time":0.33333,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.725,0.222,1]},"_time":0.44444,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.541,0.385,1]},"_time":0.55556,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.377,0.543,1]},"_time":0.66667,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.234,0.697,1]},"_time":0.77778,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.109,0.849,1]},"_time":0.88889,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0,1,1]},"_time":1,"_type":0,"_value":5},
    
    {"_customData":{"_color":[1,0,0,1],"_lightID":1},"_time":2,"_type":0,"_value":5},
    {"_customData":{"_color":[0.13,0.076,0.54,1],"_lightID":2},"_time":2,"_type":0,"_value":5},
    {"_customData":{"_color":[0,0.247,0.682,1],"_lightID":3},"_time":2,"_type":0,"_value":5},
    {"_customData":{"_color":[0,1,0,1],"_lightID":4},"_time":2,"_type":0,"_value":5}
]

Next example: FX - Gradient.