automated snapshot

This commit is contained in:
sumi
2025-12-20 01:51:28 -06:00
parent b89137415c
commit c8229f02d0
4 changed files with 169 additions and 83 deletions

View File

@@ -5,21 +5,75 @@ import (
)
type Sketch struct {
layers []Layer
layerTools map[string]LayerTools
}
func (s *Sketch) Draw(ctx *RenderCtx) {
for _, layer := range s.layers {
layer.Draw(ctx)
func NewSketch() Sketch {
return Sketch {
layerTools: make(map[string]LayerTools),
}
}
func (s *Sketch) CreateLayer(name string, layer Layer, sourceWidth int32, sourceHeight int32) {
texture := rl.LoadRenderTexture(sourceWidth, sourceHeight)
s.layerTools[name] = LayerTools {
name: name,
texture: &texture,
layer: layer,
}
}
func (s *Sketch) Draw(ctx *RenderCtx) {
// render onto all layer textures
for _, instance := range s.layerTools {
layer := instance.layer
rl.BeginTextureMode(*instance.texture)
layer.Draw(ctx)
rl.EndTextureMode()
}
// composite all layers to screen
src := rl.Rectangle {
X: 0, Y: 0,
Width: float32(ctx.SourceWidth),
Height: -float32(ctx.SourceHeight),
}
dst := rl.Rectangle {
X: 0, Y: 0,
Width: float32(ctx.TargetWidth),
Height: float32(ctx.TargetHeight),
}
for _, instance := range s.layerTools {
rl.DrawTexturePro(instance.texture.Texture, src, dst, rl.Vector2{}, 0, rl.White)
}
}
type LayerTools struct {
name string
layer Layer
texture *rl.RenderTexture2D
}
/** Layer **/
type Layer interface {
Draw(ctx *RenderCtx)
}
type TestPattern struct { }
func (tp *TestPattern) Draw(ctx *RenderCtx) {
rl.DrawRectangle(0, 0, int32(ctx.SourceWidth), int32(ctx.SourceHeight), rl.Magenta)
rl.PushMatrix()
rl.Translatef(float32(ctx.SourceWidth)/2.0, float32(ctx.SourceHeight)/2.0, 0.0)
rl.DrawRectangle(-100, -100, 200, 200, rl.Green)
rl.PopMatrix()
}
/** Ports **/
type Ports map[string]Signal
@@ -42,8 +96,10 @@ func (p Ports) Eval(t float64) map[string]float64 {
/** RenderCtx **/
type RenderCtx struct {
Width int32
Height int32
TargetWidth int32
TargetHeight int32
SourceWidth int32
SourceHeight int32
Time float64
Ports map[string]float64
Cam rl.Camera2D