<commit_before>package main

import (
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"

	"github.com/forestgiant/eff"
	"github.com/forestgiant/eff/sdl"
	"github.com/forestgiant/eff/util"
)

const (
	boxW = 100
	boxH = 100
)

type movingText struct {
	initialized bool
	val         int
	rect        eff.Rect
	vec         eff.Point
	color       eff.Color
	textColor   eff.Color
}

func (m *movingText) Init(c eff.Canvas) {
	rand.Seed(time.Now().UnixNano())
	font := eff.Font{
		Path: "../assets/fonts/Jellee-Roman.ttf",
	}

	err := c.SetFont(font, 24)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	m.rect = eff.Rect{
		X: rand.Intn(c.Width() - boxW),
		Y: rand.Intn(c.Height() - boxH),
		W: boxW,
		H: boxH,
	}
	m.vec = eff.Point{
		X: 1,
		Y: 1,
	}

	m.color = eff.RandomColor()
	m.textColor = eff.RandomColor()

	m.initialized = true
}

func (m *movingText) Initialized() bool {
	return m.initialized
}

func (m *movingText) Draw(c eff.Canvas) {
	c.FillRect(m.rect, m.color)
	valText := strconv.Itoa(m.val)
	valText, err := util.EllipseText(valText, m.rect.W, c)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	centeredPoint, err := util.CenterTextInRect(valText, m.rect, c)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	c.DrawText(valText, m.textColor, centeredPoint)
}

func (m *movingText) Update(c eff.Canvas) {
	m.val += 10000
	if m.val > 10000000 {
		m.val = 0
	}

	m.rect.X += m.vec.X
	if m.rect.X < 0 || m.rect.X+m.rect.W > c.Width() {
		m.vec.X *= -1
	}
	m.rect.Y += m.vec.Y
	if m.rect.Y < 0 || m.rect.Y+m.rect.H > c.Height() {
		m.vec.Y *= -1
	}

}

func main() {
	canvas := sdl.NewCanvas("Moving Text", 800, 540, eff.Color{R: 0x00, B: 0x00, G: 0x00, A: 0xFF}, 60, true)
	canvas.Run(func() {
		canvas.AddDrawable(&movingText{})
	})
}<commit_msg>Updated the moving text example to scale the text container to demonstrate the text ellipsing<commit_after>package main

import (
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"

	"github.com/forestgiant/eff"
	"github.com/forestgiant/eff/sdl"
	"github.com/forestgiant/eff/util"
)

const (
	size       = 100
	sizeChange = 50
)

type movingText struct {
	initialized bool
	val         int
	rect        eff.Rect
	vec         eff.Point
	color       eff.Color
	textColor   eff.Color
	sizeDir     int
}

func (m *movingText) Init(c eff.Canvas) {
	rand.Seed(time.Now().UnixNano())
	font := eff.Font{
		Path: "../assets/fonts/Jellee-Roman.ttf",
	}

	err := c.SetFont(font, 24)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	m.rect = eff.Rect{
		X: rand.Intn(c.Width() - size),
		Y: rand.Intn(c.Height() - size),
		W: size,
		H: size,
	}
	m.vec = eff.Point{
		X: 1,
		Y: 1,
	}

	m.color = eff.RandomColor()
	m.textColor = eff.RandomColor()

	m.sizeDir = 1
	m.initialized = true
}

func (m *movingText) Initialized() bool {
	return m.initialized
}

func (m *movingText) Draw(c eff.Canvas) {
	c.FillRect(m.rect, m.color)
	valText := strconv.Itoa(m.val)
	valText, err := util.EllipseText(valText, m.rect.W, c)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	centeredPoint, err := util.CenterTextInRect(valText, m.rect, c)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	c.DrawText(valText, m.textColor, centeredPoint)
}

func (m *movingText) Update(c eff.Canvas) {
	m.val += (100 + rand.Intn(1000))
	if m.val > 100000 {
		m.val = 0
	}

	m.rect.X += m.vec.X
	if m.rect.X < sizeChange || m.rect.X+m.rect.W > (c.Width()-(sizeChange*2)) {
		m.vec.X *= -1
	}
	m.rect.Y += m.vec.Y
	if m.rect.Y < sizeChange || m.rect.Y+m.rect.H > (c.Height()-(sizeChange*2)) {
		m.vec.Y *= -1
	}

	m.rect.W += m.sizeDir
	m.rect.H += m.sizeDir
	if m.rect.W > size+sizeChange || m.rect.W < size-sizeChange {
		m.sizeDir *= -1
	}
}

func main() {
	canvas := sdl.NewCanvas("Moving Text", 800, 540, eff.Color{R: 0x00, B: 0x00, G: 0x00, A: 0xFF}, 60, true)
	canvas.Run(func() {
		canvas.AddDrawable(&movingText{})
	})
}
{'fraction_non_alphanumeric': 0.17904269081500646, 'fraction_numerical': 0.025614489003880983, 'mean_word_length': 2.9129554655870447, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '5690114', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1709, 'n_words': 352}