<commit_before>package primitive

import (
	"fmt"
	"image"
	"time"

	"github.com/fogleman/gg"
)

type Model struct {
	W, H    int
	Target  *image.RGBA
	Current *image.RGBA
	Buffer  *image.RGBA
	Score   float64
	Context *gg.Context
}

func NewModel(target image.Image) *Model {
	c := averageImageColor(target)
	size := target.Bounds().Size()
	model := &Model{}
	model.W = size.X
	model.H = size.Y
	model.Target = imageToRGBA(target)
	model.Current = uniformRGBA(target.Bounds(), c)
	model.Buffer = uniformRGBA(target.Bounds(), c)
	model.Score = differenceFull(model.Target, model.Current)
	model.Context = gg.NewContext(model.W*4, model.H*4)
	model.Context.Scale(4, 4)
	model.Context.SetColor(c)
	model.Context.Clear()
	return model
}

func (model *Model) Run() {
	frame := 0
	start := time.Now()
	for {
		model.Step()
		elapsed := time.Since(start).Seconds()
		fmt.Printf("%d, %.3f, %.6f\n", frame, elapsed, model.Score)
		if frame%1 == 0 {
			path := fmt.Sprintf("out%03d.png", frame)
			// SavePNG(path, model.Current)
			model.Context.SavePNG(path)
		}
		frame++
	}
}

func (model *Model) Step() {
	// state := NewState(model, NewRandomTriangle(model.W, model.H))
	// state := NewState(model, NewRandomRectangle(model.W, model.H))
	state := NewState(model, NewRandomCircle(model.W, model.H))
	// fmt.Println(PreAnneal(state, 10000))
	state = Anneal(state, 0.2, 0.0001, 10000).(*State)<commit_msg>tweaks<commit_after>package primitive

import (
	"fmt"
	"image"
	"image/color"
	"time"

	"github.com/fogleman/gg"
)

const Scale = 4

type Model struct {
	W, H    int
	Target  *image.RGBA
	Current *image.RGBA
	Buffer  *image.RGBA
	Score   float64
	Context *gg.Context
}

func NewModel(target image.Image) *Model {
	c := averageImageColor(target)
	c = color.White
	// c = color.Black
	size := target.Bounds().Size()
	model := &Model{}
	model.W = size.X
	model.H = size.Y
	model.Target = imageToRGBA(target)
	model.Current = uniformRGBA(target.Bounds(), c)
	model.Buffer = uniformRGBA(target.Bounds(), c)
	model.Score = differenceFull(model.Target, model.Current)
	model.Context = gg.NewContext(model.W*Scale, model.H*Scale)
	model.Context.Scale(Scale, Scale)
	model.Context.SetColor(c)
	model.Context.Clear()
	return model
}

func (model *Model) Run() {
	frame := 0
	start := time.Now()
	for {
		model.Step()
		elapsed := time.Since(start).Seconds()
		fmt.Printf("%d, %.3f, %.6f\n", frame, elapsed, model.Score)
		if frame%1 == 0 {
			path := fmt.Sprintf("out%03d.png", frame)
			// SavePNG(path, model.Current)
			model.Context.SavePNG(path)
		}
		frame++
	}
}

func (model *Model) Step() {
	// state := NewState(model, NewRandomTriangle(model.W, model.H))
	// state := NewState(model, NewRandomRectangle(model.W, model.H))
	state := NewState(model, NewRandomCircle(model.W, model.H))
	// fmt.Println(PreAnneal(state, 10000))
	state = Anneal(state, 0.2, 0.0001, 50000).(*State)
{'fraction_non_alphanumeric': 0.16828929068150209, 'fraction_numerical': 0.019819193324061197, 'mean_word_length': 4.0473684210526315, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6448143', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1098, 'n_words': 223}