Initial commit

This commit is contained in:
ChaoticByte 2025-08-21 18:16:10 +02:00
commit b3f3a77fc7
No known key found for this signature in database
8 changed files with 242 additions and 0 deletions

57
main.go Normal file
View file

@ -0,0 +1,57 @@
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/ChaoticByte/xels/simulation"
)
type Application struct {
simulation simulation.Simulation
}
func (a *Application) Update() error {
a.simulation.Update()
return nil
}
func (a *Application) Draw(screen *ebiten.Image) {
// create image from xel grid
pixels := make([]byte, 4 * screen.Bounds().Dx() * screen.Bounds().Dy())
for i := range len(a.simulation.Grid.Xels) {
xel := a.simulation.Grid.Xels[i]
var v byte = 0
if xel.Energy > 0 {
v = byte(max(0, min(255, xel.Energy * 2 + 38)))
}
// r
pixels[i * 4] = v
// g
pixels[(i*4) + 1] = v
// b
pixels[(i*4) + 2] = v
// a
pixels[(i*4) + 3] = 255
}
screen.WritePixels(pixels)
}
func (a *Application) Layout(outsideWidth int, outsideHeight int) (int, int) {
return CanvasWidth, CanvasHeight
}
func main() {
ebiten.SetWindowSize(CanvasWidth, CanvasHeight)
ebiten.SetWindowTitle("Pixels - Main Window")
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
ebiten.MaximizeWindow()
ebiten.SetTPS(MaxTps)
app := &Application{
simulation: *simulation.NewSimulation(CanvasWidth, CanvasHeight),
}
InitGrid(app.simulation.Grid)
err := ebiten.RunGame(app)
if err != nil { panic(err) }
}