automated snapshot

This commit is contained in:
sumi
2025-12-23 22:23:04 -06:00
parent 312d9895f5
commit b5a0015e16
2 changed files with 30 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"math" "math"
"math/rand" "math/rand"
"github.com/gen2brain/raylib-go/raylib" "github.com/gen2brain/raylib-go/raylib"
@@ -8,21 +9,27 @@ import (
type ContourLayer struct { type ContourLayer struct {
field Field field Field
maxActors uint32
actors []*Actor actors []*Actor
actorIndex uint32
rng *rand.Rand rng *rand.Rand
} }
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field) *ContourLayer { func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field) *ContourLayer {
actors := make([]*Actor, 0) maxActors := 200000
actors := make([]*Actor, maxActors)
layer := ContourLayer { layer := ContourLayer {
rng: rng, rng: rng,
field: field, field: field,
actors: actors, actors: actors,
maxActors: uint32(maxActors),
actorIndex: 0,
} }
layer.AddActors(1, sketch.sourceWidth, sketch.sourceHeight) //layer.AddActors(1, sketch.sourceWidth, sketch.sourceHeight)
return &layer return &layer
} }
@@ -38,18 +45,22 @@ func (s *ContourLayer) AddActors(n, sourceWidth, sourceHeight int32) {
stepSize: 1, stepSize: 1,
color: rl.NewColor(11, 35, 176, 50), color: rl.NewColor(11, 35, 176, 50),
} }
s.actors = append(s.actors, newActor) s.actors[s.actorIndex] = newActor
s.actorIndex = (s.actorIndex + 1) % s.maxActors
} }
} }
func (s *ContourLayer) Update(ctx *RenderCtx) { func (s *ContourLayer) Update(ctx *RenderCtx) {
s.AddActors(100, ctx.SourceWidth, ctx.SourceHeight) s.AddActors(100, ctx.SourceWidth, ctx.SourceHeight)
fmt.Printf("num actors = %d\n", len(s.actors))
} }
func (s *ContourLayer) Draw(ctx *RenderCtx) { func (s *ContourLayer) Draw(ctx *RenderCtx) {
rl.BeginBlendMode(rl.BlendAdditive) rl.BeginBlendMode(rl.BlendAdditive)
for _, actor := range s.actors { for _, actor := range s.actors {
actor.Draw() if actor != nil {
actor.Draw()
}
} }
rl.EndBlendMode() rl.EndBlendMode()
} }

View File

@@ -90,22 +90,28 @@ func (s *Sketch) AddColorLayer(name string, c rl.Color) {
s.AddLayer(name, colorLayer) s.AddLayer(name, colorLayer)
} }
func (s *Sketch) Draw(ctx *RenderCtx) { func (s *Sketch) Redraw(ctx *RenderCtx) {
// render onto all layer textures // render onto all layer textures
for _, instance := range s.layerToolsOrdered { for _, instance := range s.layerToolsOrdered {
layer := instance.layer layer := instance.layer
layer.Update(ctx) // ignore this layer entirely unless it's visible
if instance.layer.IsDirty() { if instance.config.visible {
rl.BeginTextureMode(instance.texture) layer.Update(ctx)
rl.PushMatrix() // re-render to texture if dirty
layer.Draw(ctx) if instance.layer.IsDirty() {
rl.PopMatrix() rl.BeginTextureMode(instance.texture)
rl.EndTextureMode() rl.PushMatrix()
layer.Draw(ctx)
rl.PopMatrix()
rl.EndTextureMode()
}
} }
} }
}
// composite all layers to screen func (s *Sketch) Draw(ctx *RenderCtx) {
s.Redraw(ctx)
// copy from full texture for compositing, with vertical flipping // copy from full texture for compositing, with vertical flipping
src := rl.Rectangle { src := rl.Rectangle {
@@ -122,7 +128,6 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
viewport := s.CalcViewport(ctx) viewport := s.CalcViewport(ctx)
rl.BeginTextureMode(s.composite) rl.BeginTextureMode(s.composite)
//rl.ClearBackground(rl.Black)
for _, instance := range s.layerToolsOrdered { for _, instance := range s.layerToolsOrdered {
config := instance.config config := instance.config
if config.visible { if config.visible {