automated snapshot

This commit is contained in:
sumi
2025-12-17 22:10:00 -06:00
parent 4b5f9d3c85
commit 66df6a29ff

63
main.go
View File

@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"math"
"math/rand"
"os"
"time"
@@ -38,6 +39,8 @@ func main() {
os.MkdirAll(snapshotsDir, 0755)
rng := rand.New(rand.NewSource(0))
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
storage, err := NewStorage(snapshotsDir)
@@ -58,25 +61,26 @@ func main() {
w := rl.GetRenderWidth()
h := rl.GetRenderHeight()
angles := make([]float32, 2000)
noise := opensimplex.NewNormalized(0)
r := 2.0
dtheta := 360.0/float64(len(angles))
for i := range len(angles) {
rad := float64(i) * dtheta * math.Pi / 180.0
x := r * math.Cos(rad)
y := r * math.Sin(rad)
angles[i] = float32(noise.Eval2(x, y) * 360.0)
}
sketches := []Sketch{
&Worm{
position: rl.Vector2 { X: 50, Y: 50 },
angles: angles,
angleIndex: 0,
stepSize: 1,
renderPct: 0.1,
},
sketches := make([]Sketch, 1000)
for i := range 1000 {
angles := make([]float32, 100)
noise := opensimplex.NewNormalized(int64(i))
r := 1.0
dtheta := 360.0/float64(len(angles))
for i := range len(angles) {
rad := float64(i) * dtheta * math.Pi / 180.0
x := r * math.Cos(rad)
y := r * math.Sin(rad)
angles[i] = float32(noise.Eval2(x, y) * 360.0)
}
sketches[i] =
&Worm{
position: RandRadialVec(rng, 0, 100, -180, 180),
angles: angles,
angleIndex: 0,
stepSize: 1,
renderPct: 0.80,
}
}
var camera = rl.Camera2D{
@@ -110,7 +114,7 @@ func main() {
// begin drawing
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.ClearBackground(rl.Black)
rl.BeginMode2D(camera)
t := time.Since(t0).Seconds()
@@ -149,6 +153,13 @@ func main() {
rl.CloseWindow()
}
func RandRadialVec(rng *rand.Rand, minRadius float32, maxRadius float32, loAngle float32, hiAngle float32) rl.Vector2 {
r := float64(rl.Remap(rng.Float32(), 0, 1, minRadius, maxRadius))
deg := float64(rl.Remap(rng.Float32(), 0, 1, loAngle, hiAngle))
rad := rl.Deg2rad * deg
return rl.Vector2 { X: float32(r * math.Cos(rad)), Y: float32(r * math.Sin(rad)) }
}
func updateCamera(camera *rl.Camera2D) {
// Get the world point that is under the mouse
mouseVec2 := rl.GetMousePosition()
@@ -195,11 +206,19 @@ func (w *Worm) Draw(ctx *RenderCtx) {
rl.Translatef(w.position.X, w.position.Y, 0)
lastAngle := float32(0.0)
stepCount := 0
nudged := false
for i := range w.angles {
ii := (i + w.angleIndex) % len(w.angles)
angle := w.angles[ii]
rl.Rotatef(angle - lastAngle, 0, 0, 1)
rl.DrawLine(0, 0, int32(w.stepSize), 0, rl.Black)
deltaAngle := angle - lastAngle
if !nudged {
rad := float64(deltaAngle * math.Pi / 180.0)
nudge := rl.Vector2 { X: float32(w.stepSize) * float32(math.Cos(rad)), Y: float32(w.stepSize) * float32(math.Sin(rad)) }
w.position = rl.Vector2Add(w.position, nudge)
nudged = true
}
rl.Rotatef(deltaAngle, 0, 0, 1)
rl.DrawLine(0, 0, int32(w.stepSize), 0, rl.NewColor(184, 187, 38, 50))
rl.Translatef(float32(w.stepSize), 0, 0)
lastAngle = angle
stepCount++