diff --git a/pkg/anim/slime.go b/pkg/anim/slime.go index 3a17a670..7804512f 100644 --- a/pkg/anim/slime.go +++ b/pkg/anim/slime.go @@ -2,7 +2,6 @@ package anim import ( "math" - "math/rand" "time" "github.com/cfoust/cy/pkg/anim/slime" @@ -10,6 +9,7 @@ import ( ) type Slime struct { + frame int last time.Duration sim *slime.Simulator start image.Image @@ -22,29 +22,7 @@ func (f *Slime) Init(start image.Image) { f.start = start size := start.Size() - - var agents []slime.Agent - for row := 0; row < size.R; row++ { - for col := 0; col < size.C; col++ { - if start[row][col].IsEmpty() { - continue - } - agents = append(agents, slime.Agent{ - Pos: slime.Vec2{ - X: float64(col), - Y: float64(row), - }, - Dir: slime.Vec2{X: 1, Y: 0}. - Rot(rand.Float64() * 2 * math.Pi), - }) - } - } - - f.sim = slime.New( - size.R, - size.C, - agents, - ) + f.sim = slime.New(size.R, size.C) } func (f *Slime) Update(delta time.Duration) image.Image { @@ -54,11 +32,19 @@ func (f *Slime) Update(delta time.Duration) image.Image { f.last = delta - f.sim.Step(slime.Cursor{}) - size := f.start.Size() + cursor := slime.Cursor{} + if math.Sin(float64(f.frame)/50) > 0.6 { + cursor.Pressed = true + cursor.X = float64(size.C) / 2 + cursor.Y = float64(size.R) / 2 + } + + f.sim.Step(cursor) + f.current = image.New(size) f.sim.Render(f.current) + f.frame++ return f.current } diff --git a/pkg/anim/slime/module.go b/pkg/anim/slime/module.go index 0d9f8f95..0396ee24 100644 --- a/pkg/anim/slime/module.go +++ b/pkg/anim/slime/module.go @@ -134,8 +134,8 @@ func randCircle() Vec2 { } type Cursor struct { - pressed bool - x, y float64 + Pressed bool + X, Y float64 } type Simulator struct { @@ -151,7 +151,7 @@ type Simulator struct { func (s *Simulator) updateView(cursor Cursor) { var targetScale Vec2 - if cursor.pressed { + if cursor.Pressed { // Zoom in for detailed view targetScale = Vec2{Y: 1 / ASPECT, X: 1} } else if float64(s.rows)/ASPECT < float64(s.cols) { @@ -173,8 +173,8 @@ func (s *Simulator) updateView(cursor Cursor) { s.viewScale.X += 0.1 * (targetScale.X - s.viewScale.X) var targetFocus Vec2 - if cursor.pressed { - targetFocus = Vec2{Y: cursor.y / float64(s.rows), X: cursor.x / float64(s.cols)} + if cursor.Pressed { + targetFocus = Vec2{Y: cursor.Y / float64(s.rows), X: cursor.X / float64(s.cols)} } else { targetFocus = Vec2{Y: 0.5, X: 0.5} } @@ -278,11 +278,11 @@ func (s *Simulator) Render(out image.Image) { } } -func New(rows, cols int, agents []Agent) *Simulator { +func New(rows, cols int) *Simulator { chem := make([]float64, HEIGHT*WIDTH) wip := make([]float64, HEIGHT*WIDTH) - agents = make([]Agent, NUM_AGENTS) + agents := make([]Agent, NUM_AGENTS) for i := 0; i < NUM_AGENTS; i++ { agents[i] = Agent{ Pos: randCircle().