automated snapshot

This commit is contained in:
sumi
2025-12-21 12:40:52 -06:00
parent c8229f02d0
commit deb020b5c8
2 changed files with 78 additions and 62 deletions

75
main.go
View File

@@ -13,50 +13,17 @@ import (
)
const (
screenWidth = 800
screenHeight = 600
sourceWidth = 10000
sourceHeight = 10000
displayScale = 2
targetWidth = 800
targetHeight = 600
sourceScale = 1
snapshotsDir = "snapshots"
)
func main3() {
rl.InitWindow(800, 600, "rt test")
defer rl.CloseWindow()
rt := rl.LoadRenderTexture(512, 512)
defer rl.UnloadRenderTexture(rt)
for !rl.WindowShouldClose() {
// draw into offscreen buffer
rl.BeginTextureMode(rt)
rl.ClearBackground(rl.Blank)
rl.DrawCircle(256, 256, 100, rl.Red)
rl.EndTextureMode()
// draw to screen
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
src := rl.Rectangle{
X: 0, Y: 0,
Width: float32(rt.Texture.Width),
Height: -float32(rt.Texture.Height),
}
dst := rl.Rectangle{
X: 0, Y: 0,
Width: 800,
Height: 600,
}
rl.DrawTexturePro(rt.Texture, src, dst, rl.Vector2{}, 0, rl.White)
rl.EndDrawing()
}
}
func main() {
sourceWidth := sourceScale * targetWidth
sourceHeight := sourceScale * targetHeight
os.MkdirAll(snapshotsDir, 0755)
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
storage, err := NewStorage(snapshotsDir)
@@ -64,22 +31,22 @@ func main() {
log.Printf("Error loading storage: %v\n", err)
os.Exit(1)
}
rl.SetConfigFlags(rl.FlagWindowHighdpi)
rl.InitWindow(screenWidth, screenHeight, "sumi sierpinski arrow")
rl.SetConfigFlags(rl.FlagWindowHighdpi & rl.FlagMsaa4xHint)
rl.InitWindow(targetWidth, targetHeight, "sumi sierpinski arrow")
log.Printf("screen=%dx%d render=%dx%d",
rl.GetScreenWidth(), rl.GetScreenHeight(),
rl.GetRenderWidth(), rl.GetRenderHeight(),
)
w := rl.GetRenderWidth()
h := rl.GetRenderHeight()
var camera = rl.Camera2D{
Target: rl.Vector2{X: 0, Y: 0},
Offset: rl.Vector2{X: float32(w) / 2, Y: float32(h) / 2},
Rotation: 0,
// point at source center
// put source center at center of screen
var camera = rl.Camera2D {
Target: rl.Vector2{X: float32(targetWidth) / 2, Y: float32(targetHeight) / 2},
Offset: rl.Vector2{},
Zoom: 1.0,
Rotation: 0,
}
/*
@@ -90,9 +57,7 @@ func main() {
Noise: opensimplex.NewNormalized32(0),
},
}
imgf := NewImageField("/home/d/Dropbox/art/passage/data/david.png")
imageField :=
ScaleField{
field: &imgf,
@@ -105,7 +70,7 @@ func main() {
//contourSketch := NewContourLayer(rng, &imageField)
sketch := NewSketch()
sketch.CreateLayer("testPattern", &TestPattern{}, sourceWidth, sourceHeight)
sketch.CreateLayer("testPattern", &TestPattern{}, int32(sourceWidth), int32(sourceHeight))
rl.SetTargetFPS(60)
@@ -127,8 +92,8 @@ func main() {
// set up RenderCtx
renderCtx := &RenderCtx{
TargetWidth: int32(w),
TargetHeight: int32(h),
TargetWidth: int32(targetWidth),
TargetHeight: int32(targetHeight),
SourceWidth: int32(sourceWidth),
SourceHeight: int32(sourceHeight),
Time: t,
@@ -142,14 +107,11 @@ func main() {
rl.BeginDrawing()
rl.ClearBackground(rl.Blank)
//rl.PushMatrix()
sketch.Draw(renderCtx)
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
//rl.PopMatrix()
rl.EndDrawing()
//rl.DrawCircle(0, 0, 10, rl.Green)
if rl.IsKeyDown(rl.KeySpace) {
if _, err := storage.Save(); err != nil {
@@ -243,6 +205,7 @@ func updateCamera(camera *rl.Camera2D) {
delta := rl.GetMouseDelta()
// compute the amount to move scaled by the camera zoom
delta = rl.Vector2Scale(delta, -1.0/camera.Zoom)
delta.Y = -delta.Y
camera.Target = rl.Vector2Add(camera.Target, delta)
}
// Zoom based on mouse wheel