<commit_before>package cozely_test

import (
	"math/rand"

	"github.com/cozely/cozely"
	"github.com/cozely/cozely/color"
	"github.com/cozely/cozely/input"
	"github.com/cozely/cozely/pixel"
)

// Declarations ////////////////////////////////////////////////////////////////

var (
	quit  = input.Digital("Quit")
	start = input.Digital("Start")
)

var bindings = input.Bindings{
	"Default": {
		"Start": {"Space", "Mouse Left", "Button A"},
		"Quit":  {"Escape", "Button Back"},
	},
}

var (
	canv       = pixel.Canvas(pixel.Resolution(160, 100))
	logo       = pixel.Picture("graphics/cozely")
	monochrome = color.PaletteFrom("graphics/cozely")
	colorful   = color.Palette()
)

var started = false

var reverse = false

type loop2 struct{}

// Initialization //////////////////////////////////////////////////////////////

func Example_interactive() {
	defer cozely.Recover()

	input.Load(bindings)
	cozely.Configure(cozely.UpdateStep(1.0 / 3))
	err := cozely.Run(loop2{})
	if err != nil {
		panic(err)
	}
	// Output:
}

func (loop2) Enter() {
	monochrome.Activate()
	shufflecolors()
}

func (loop2) Leave() {
}

// Game Loop ///////////////////////////////////////////////////////////////////

func (loop2) React() {
	if start.Started(input.Any) {
		started = !started
	}
	if quit.Started(input.Any) {
		cozely.Stop(nil)
	}
}

func (loop2) Update() {
	if started {
		shufflecolors()
	}
}

func shufflecolors() {
	dark := [12]bool{
		true, false, true, false, true, false,
		false, true, false, true, false, true,
	}
	reverse = !reverse
	for i := 2; i < 14; i++ {
		g := 0.2 + 0.8*rand.Float32()
		r := 0.2 + 0.8*rand.Float32()
		b := 0.2 + 0.8*rand.Float32()
		if dark[i-2] != reverse {
			colorful.Set(uint8(i), color.SRGB{r, g, b})
		} else {
			colorful.Set(uint8(i), color.LRGB{r, g, b})
		}
	}
}

func (loop2) Render() {
	canv.Clear(0)

	if started {
		colorful.Activate()
	} else {
		monochrome.Activate()
	}

	o := canv.Size().Minus(logo.Size()).Slash(2)
	canv.Picture(logo, 0, o)

	canv.Display()
}
<commit_msg>Tweak example<commit_after>package cozely_test

import (
	"math/rand"

	"github.com/cozely/cozely"
	"github.com/cozely/cozely/color"
	"github.com/cozely/cozely/input"
	"github.com/cozely/cozely/pixel"
)

// Declarations ////////////////////////////////////////////////////////////////

var (
	quit = input.Digital("Quit")
	play = input.Digital("Play")
)

var bindings = input.Bindings{
	"Default": {
		"Play": {"Space", "Mouse Left", "Button A"},
		"Quit": {"Escape", "Button Back"},
	},
}

var (
	canvas2    = pixel.Canvas(pixel.Resolution(160, 100))
	logo       = pixel.Picture("graphics/cozely")
	monochrome = color.PaletteFrom("graphics/cozely")
	colorful   = color.Palette()
)

type loop2 struct {
	playing bool
}

// Initialization //////////////////////////////////////////////////////////////

func Example_interactive() {
	defer cozely.Recover()

	input.Load(bindings)
	cozely.Configure(cozely.UpdateStep(1.0 / 3))
	err := cozely.Run(&loop2{})
	if err != nil {
		panic(err)
	}
	// Output:
}

func (l *loop2) Enter() {
	monochrome.Activate()
	l.shufflecolors()
}

func (loop2) Leave() {
}

// Game Loop ///////////////////////////////////////////////////////////////////

func (l *loop2) React() {
	if play.Started(input.Any) {
		l.playing = !l.playing
	}
	if quit.Started(input.Any) {
		cozely.Stop(nil)
	}
}

func (l *loop2) Update() {
	if l.playing {
		l.shufflecolors()
	}
}

func (l *loop2) shufflecolors() {
	for i := 2; i < 14; i++ {
		g := 0.2 + 0.7*rand.Float32()
		r := 0.2 + 0.7*rand.Float32()
		b := 0.2 + 0.7*rand.Float32()
		colorful.Set(uint8(i), color.SRGB{r, g, b})
	}
}

func (l *loop2) Render() {
	canvas2.Clear(0)

	if l.playing {
		colorful.Activate()
	} else {
		monochrome.Activate()
	}

	o := canvas2.Size().Minus(logo.Size()).Slash(2)
	canvas2.Picture(logo, 0, o)

	canvas2.Display()
}

{'fraction_non_alphanumeric': 0.26739640344018767, 'fraction_numerical': 0.02397706541568934, 'mean_word_length': 2.3258232235701906, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5075262', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1479, 'n_words': 275}