automated snapshot
This commit is contained in:
@@ -8,14 +8,16 @@ import (
|
||||
|
||||
type ContourLayer struct {
|
||||
field Field
|
||||
rng *rand.Rand
|
||||
maxActors uint32
|
||||
actors []*Actor
|
||||
actorIndex uint32
|
||||
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
|
||||
|
||||
@@ -28,6 +30,8 @@ func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color rl.Color
|
||||
maxActors: uint32(maxActors),
|
||||
actorColor: color,
|
||||
actorIndex: 0,
|
||||
loActorAngle: loActorAngle,
|
||||
hiActorAngle: hiActorAngle,
|
||||
}
|
||||
|
||||
return &layer
|
||||
@@ -43,6 +47,8 @@ func (s *ContourLayer) AddActors(color rl.Color, n, sourceWidth, sourceHeight in
|
||||
field: s.field,
|
||||
stepSize: 1,
|
||||
color: s.actorColor,
|
||||
loAngle: s.loActorAngle,
|
||||
hiAngle: s.hiActorAngle,
|
||||
}
|
||||
s.actors[s.actorIndex] = newActor
|
||||
s.actorIndex = (s.actorIndex + 1) % s.maxActors
|
||||
@@ -72,11 +78,13 @@ type Actor struct {
|
||||
field Field
|
||||
stepSize float32
|
||||
color rl.Color
|
||||
loAngle float32
|
||||
hiAngle float32
|
||||
}
|
||||
|
||||
func (a *Actor) Draw() {
|
||||
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)))}
|
||||
rl.DrawLineV(a.position, nextPosition, a.color)
|
||||
a.position = nextPosition
|
||||
|
||||
33
field.go
33
field.go
@@ -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)))
|
||||
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
34
main.go
@@ -1,12 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
"flag"
|
||||
|
||||
g "github.com/d2fn/sumi/internal/graphics"
|
||||
|
||||
@@ -92,7 +93,7 @@ func main() {
|
||||
//NewColor(11, 35, 176, 50),
|
||||
|
||||
//r
|
||||
contourLayer := NewContourLayer(&sketch, rng, field, actorColor)
|
||||
contourLayer := NewContourLayer(&sketch, rng, field, actorColor, -math.Pi, math.Pi)
|
||||
sketch.AddLayer("contours", contourLayer)
|
||||
sketch.AddLayer("sierpinski-arrowhead", sierpinskiLayer)
|
||||
// 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()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user