Ilysa by Example: Sequence - Context

ctx.Sequence() is basically a fancy loop that sets values on ctx that are useful for creating lighting effects. This example shows some of the more commonly used values.

package main
import (
    "fmt"
    "github.com/shasderias/ilysa"
    "github.com/shasderias/ilysa/beatsaber"
    "github.com/shasderias/ilysa/context"
    "github.com/shasderias/ilysa/timer"
)
func main() {
    m, _ := beatsaber.NewMockMap(beatsaber.EnvironmentOrigins, 120, "[]")
    p := ilysa.New(m)
    p.Sequence(timer.Seq([]float64{0, 1.5, 2.5, 3, 4}, 6), func(ctx context.Context) {

Within a ctx.Sequence():

ctx.B() returns the current beat.

ctx.T() returns the current position in the sequence, on a 0 to 1 scale.

ctx.Ordinal() returns the ordinal number of the current beat, i.e. 0, 1, 2, 3… etc.

ctx.SeqNextBOffset() returns the number of beats to the next beat in the current sequence. As a special case, when using timer.Seq() to specify a sequence, on the last beat, ctx.SeqNextBOffset() returns the difference between the last beat and the ghost beat.

        fmt.Printf("%4.2f %4.2f %1d %4.2f %t\n",
            ctx.B(), ctx.T(), ctx.Ordinal(), ctx.SeqNextBOffset(), ctx.Last())
    })
}
$ go run sequence-context.go
0.00 0.00 0 1.50 false
1.50 0.25 1 1.00 false
2.50 0.50 2 0.50 false
3.00 0.75 3 1.00 false
4.00 1.00 4 2.00 true

Next example: Range.