automated snapshot

This commit is contained in:
sumi
2025-12-22 00:36:55 -06:00
parent 63fa362060
commit 57e876e40d
4 changed files with 114 additions and 76 deletions

134
main.go
View File

@@ -13,9 +13,9 @@ import (
)
const (
targetWidth = 800
targetHeight = 600
sourceScale = 10
targetWidth = 1000
targetHeight = 1000
sourceScale = 8
snapshotsDir = "snapshots"
)
@@ -42,11 +42,6 @@ func main() {
rl.SetConfigFlags(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(),
)
// point at source center
// put source center at center of screen
var camera = TextureCam {
@@ -56,36 +51,35 @@ func main() {
SourceHeight: sourceHeight,
}
/*
field :=
ScaleField {
Scale: 50.0,
Field: &SimplexNoiseField {
Noise: opensimplex.NewNormalized32(0),
},
}
imgf := NewImageField("/home/d/Dropbox/art/passage/data/david.png")
imageField :=
ScaleField{
field: &imgf,
scale: 0.5,
}
*/
//rng := rand.New(rand.NewSource(0))
//contourSketch := NewContourLayer(rng, &imageField)
sketch := NewSketch()
sketch.CreateLayer("testPattern", &TestPattern{}, int32(sourceWidth), int32(sourceHeight))
rl.SetTargetFPS(60)
t0 := time.Now()
ports := MakePorts()
/*
*/
ports["sierpinskiArrowAngle"] = Sine{
imageField := NewImageField("/home/d/Dropbox/art/passage/data/david.png")
field :=
TranslateField{
x: -float32(sourceWidth/2.0),
y: -float32(sourceHeight/2.0),
field: &ScaleField {
scale: 5.0,
field: &imageField,
},
}
rng := rand.New(rand.NewSource(0))
contourLayer := NewContourLayer(rng, &field, sourceWidth, sourceHeight)
sketch := NewSketch()
//sketch.CreateLayer("testPattern", &TestPattern{}, int32(sourceWidth), int32(sourceHeight))
//sketch.CreateLayer("actors", &contourLayer, int32(sourceWidth), int32(sourceHeight))
sketch.CreateLayer("field", &FieldLayer { field: &field, dirty: true }, int32(sourceWidth), int32(sourceHeight))
sketch.CreateLayer("contours", &contourLayer, int32(sourceWidth), int32(sourceHeight))
ports := MakePorts()
ports["sierpinskiArrowAngle"] = Sine {
Amp: 120,
Bias: 100,
Freq: 0.1,
@@ -110,20 +104,30 @@ func main() {
sketch.Update(renderCtx)
/**
MAIN DRAWING
**/
* MAIN DRAWING
*/
rl.BeginDrawing()
rl.ClearBackground(rl.Blank)
sketch.Draw(renderCtx)
if rl.IsKeyDown(rl.KeySpace) {
if _, err := storage.Save(); err != nil {
log.Printf("Error saving snapshot: %v\n", err)
}
}
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
rl.EndDrawing()
if rl.IsKeyDown(rl.KeySpace) {
if _, err := storage.Save(); err != nil {
log.Printf("Error saving snapshot: %v\n", err)
for ch := rl.GetCharPressed(); ch != 0; ch = rl.GetCharPressed() {
c := rune(ch)
if c == 'c' {
resetCamera(&camera)
} else if c >= '1' && c <= '9' {
zoom := 1 << int(ch - '0')
camera.Zoom = float32(zoom)
}
}
@@ -135,38 +139,50 @@ func main() {
rl.CloseWindow()
}
type FieldSketch struct {
Field Field
func resetCamera(cam *TextureCam) {
cam.LookAt = rl.Vector2 { X: float32(cam.SourceWidth) / 2.0, Y: float32(cam.SourceHeight) / 2.0 }
cam.Zoom = 1.0
}
/*
func (s *FieldSketch) Draw(ctx *RenderCtx) {
fmt.Printf("drawing field")
for x := range ctx.TargetWidth {
for y := range ctx.TargetHeight {
screen := rl.Vector2{X: float32(x), Y: float32(y)}
world := rl.GetScreenToWorld2D(screen, ctx.Cam)
v := s.Field.Get(world.X, world.Y)
type FieldLayer struct {
field Field
dirty bool
}
func (s *FieldLayer) Update(ctx *RenderCtx) {
;
}
func (s *FieldLayer) Draw(ctx *RenderCtx) {
for x := range ctx.SourceWidth {
for y := range ctx.SourceHeight {
v := s.field.Get(float32(x), float32(y))
clr := GrayCurve(v, 1.0)
rl.DrawPixelV(world, clr)
rl.DrawPixel(x, y, clr)
}
}
s.dirty = false
}
func (s *FieldLayer) IsDirty() bool {
return s.dirty
}
*/
type ContourLayer struct {
field Field
actors []*Actor
}
func NewContourLayer(rng *rand.Rand, field Field) ContourLayer {
func NewContourLayer(rng *rand.Rand, field Field, sourceWidth int, sourceHeight int) ContourLayer {
actors := make([]*Actor, 20000)
for i := range len(actors) {
x := rng.Int() % sourceWidth
y := rng.Int() % sourceHeight
actors[i] =
&Actor{
position: RandRadialVec(rng, 0, 500, 0, 360),
field: field,
position: rl.Vector2 { X: float32(x), Y: float32(y) },
field: field,
stepSize: 1,
color: rl.NewColor(11, 35, 176, 100),
}
@@ -177,10 +193,20 @@ func NewContourLayer(rng *rand.Rand, field Field) ContourLayer {
}
}
func (s *ContourLayer) Update(ctx *RenderCtx) {
;
}
func (s *ContourLayer) Draw(ctx *RenderCtx) {
rl.BeginBlendMode(rl.BlendAdditive)
for _, actor := range s.actors {
actor.Draw()
}
rl.EndBlendMode()
}
func (s *ContourLayer) IsDirty() bool {
return true
}
type Actor struct {