automated snapshot

This commit is contained in:
sumi
2025-12-26 14:42:39 -06:00
parent 6ab7c8d7e1
commit 80d3a0fde8
3 changed files with 47 additions and 34 deletions

View File

@@ -8,14 +8,16 @@ import (
type ContourLayer struct { type ContourLayer struct {
field Field field Field
rng *rand.Rand
maxActors uint32 maxActors uint32
actors []*Actor actors []*Actor
actorIndex uint32 actorIndex uint32
actorColor rl.Color actorColor rl.Color
rng *rand.Rand loActorAngle float32
hiActorAngle float32
} }
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color rl.Color) *ContourLayer { func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color rl.Color, loActorAngle float32, hiActorAngle float32) *ContourLayer {
maxActors := 200000 maxActors := 200000
@@ -28,6 +30,8 @@ func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color rl.Color
maxActors: uint32(maxActors), maxActors: uint32(maxActors),
actorColor: color, actorColor: color,
actorIndex: 0, actorIndex: 0,
loActorAngle: loActorAngle,
hiActorAngle: hiActorAngle,
} }
return &layer return &layer
@@ -43,6 +47,8 @@ func (s *ContourLayer) AddActors(color rl.Color, n, sourceWidth, sourceHeight in
field: s.field, field: s.field,
stepSize: 1, stepSize: 1,
color: s.actorColor, color: s.actorColor,
loAngle: s.loActorAngle,
hiAngle: s.hiActorAngle,
} }
s.actors[s.actorIndex] = newActor s.actors[s.actorIndex] = newActor
s.actorIndex = (s.actorIndex + 1) % s.maxActors s.actorIndex = (s.actorIndex + 1) % s.maxActors
@@ -72,11 +78,13 @@ type Actor struct {
field Field field Field
stepSize float32 stepSize float32
color rl.Color color rl.Color
loAngle float32
hiAngle float32
} }
func (a *Actor) Draw() { func (a *Actor) Draw() {
v := a.field.Get(a.position.X, a.position.Y) v := a.field.Get(a.position.X, a.position.Y)
rad := rl.Remap(v, 0, 1, 0, 5*math.Pi) rad := rl.Remap(v, 0, 1, a.loAngle, a.hiAngle)
nextPosition := rl.Vector2{X: a.position.X + a.stepSize*float32(math.Cos(float64(rad))), Y: a.position.Y + a.stepSize*float32(math.Sin(float64(rad)))} nextPosition := rl.Vector2{X: a.position.X + a.stepSize*float32(math.Cos(float64(rad))), Y: a.position.Y + a.stepSize*float32(math.Sin(float64(rad)))}
rl.DrawLineV(a.position, nextPosition, a.color) rl.DrawLineV(a.position, nextPosition, a.color)
a.position = nextPosition a.position = nextPosition

View File

@@ -90,3 +90,36 @@ func (f *ImageField) Get(x, y float32) float32 {
c := f.pixels.Get(int(x+float32(f.offsetX)), int(y+float32(f.offsetY))) c := f.pixels.Get(int(x+float32(f.offsetX)), int(y+float32(f.offsetY)))
return Brightness(c) return Brightness(c)
} }
/** LAYER HELPERS **/
type FieldLayer struct {
field Field
loColor rl.Color
hiColor rl.Color
dirty bool
}
func (fl *FieldLayer) Update(ctx *RenderCtx) {
;
}
func (fl *FieldLayer) Draw(ctx *RenderCtx) {
rl.ClearBackground(rl.Blank)
rl.BeginBlendMode(rl.BlendAlphaPremultiply)
for x := range ctx.SourceWidth {
for y := range ctx.SourceHeight {
v := fl.field.Get(float32(x), float32(y))
clr := LerpCurve(v, 1.3, fl.loColor, fl.hiColor)
rl.DrawPixel(x, y, clr)
}
}
rl.EndBlendMode()
fl.dirty = false
}
func (fl *FieldLayer) IsDirty() bool {
return fl.dirty
}

34
main.go
View File

@@ -1,12 +1,13 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"log" "log"
"math"
"math/rand" "math/rand"
"os" "os"
"time" "time"
"flag"
g "github.com/d2fn/sumi/internal/graphics" g "github.com/d2fn/sumi/internal/graphics"
@@ -92,7 +93,7 @@ func main() {
//NewColor(11, 35, 176, 50), //NewColor(11, 35, 176, 50),
//r //r
contourLayer := NewContourLayer(&sketch, rng, field, actorColor) contourLayer := NewContourLayer(&sketch, rng, field, actorColor, -math.Pi, math.Pi)
sketch.AddLayer("contours", contourLayer) sketch.AddLayer("contours", contourLayer)
sketch.AddLayer("sierpinski-arrowhead", sierpinskiLayer) sketch.AddLayer("sierpinski-arrowhead", sierpinskiLayer)
// aurora := NewImageLayer("/home/d/Dropbox/photos/Events/2025/Aurora/Photo Nov 11 2025, 9 52 03 PM.jpg") // aurora := NewImageLayer("/home/d/Dropbox/photos/Events/2025/Aurora/Photo Nov 11 2025, 9 52 03 PM.jpg")
@@ -246,32 +247,3 @@ func main() {
rl.CloseWindow() rl.CloseWindow()
} }
type FieldLayer struct {
field Field
loColor rl.Color
hiColor rl.Color
dirty bool
}
func (fl *FieldLayer) Update(ctx *RenderCtx) {
;
}
func (fl *FieldLayer) Draw(ctx *RenderCtx) {
rl.ClearBackground(rl.Blank)
rl.BeginBlendMode(rl.BlendAlphaPremultiply)
for x := range ctx.SourceWidth {
for y := range ctx.SourceHeight {
v := fl.field.Get(float32(x), float32(y))
clr := LerpCurve(v, 1.3, fl.loColor, fl.hiColor)
rl.DrawPixel(x, y, clr)
}
}
rl.EndBlendMode()
fl.dirty = false
}
func (fl *FieldLayer) IsDirty() bool {
return fl.dirty
}