Skip to content

Commit

Permalink
feat: kinda working animations
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 27, 2023
1 parent 7015c53 commit ff6dff8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="https://cfoust.github.io/cy/cy.gif" alt="cy main gif">
<img src="https://cfoust.github.io/cy/images/main.gif" alt="cy main gif">
</p>

> the time traveling terminal multiplexer
Expand Down
4 changes: 2 additions & 2 deletions cmd/stories/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ func main() {
initial := createInitial(geom.DEFAULT_SIZE)

for name, animation := range anim.Animations {
func(a anim.Animation) {
func(a anim.Creator) {
stories.Register(
fmt.Sprintf("animation/%s", name),
func(ctx context.Context) mux.Screen {
animator := anim.NewAnimator(
ctx,
a,
a(),
initial.Clone(),
23,
)
Expand Down
4 changes: 2 additions & 2 deletions docs/storybook.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def transform_chapter(chapter):
Hide
Type "./stories -s {command} && clear"
Enter
Sleep 2s
Sleep 500ms
Show
Sleep 10s
Sleep 8s
"""
elif filename.endswith(".png"):
script = f"""
Expand Down
6 changes: 4 additions & 2 deletions pkg/anim/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Animation interface {
Update(delta time.Duration) image.Image
}

type Creator func() Animation

func RandomAnimation() Animation {
anims := []Animation{
&Collapse{},
Expand All @@ -23,8 +25,8 @@ func RandomAnimation() Animation {
return anims[rand.Int()%len(anims)]
}

var Animations = map[string]Animation{}
var Animations = map[string]Creator{}

func registerAnimation(name string, animation Animation) {
func registerAnimation(name string, animation Creator) {
Animations[name] = animation
}
4 changes: 3 additions & 1 deletion pkg/anim/collapse.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ func (c *Collapse) Update(delta time.Duration) image.Image {
}

func init() {
registerAnimation("collapse", &Collapse{})
registerAnimation("collapse", func() Animation {
return &Collapse{}
})
}
4 changes: 3 additions & 1 deletion pkg/anim/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,7 @@ func (c *Conway) Update(delta time.Duration) image.Image {
}

func init() {
registerAnimation("conway", &Conway{})
registerAnimation("conway", func() Animation {
return &Conway{}
})
}
4 changes: 3 additions & 1 deletion pkg/anim/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ func (c *Cyform) Update(delta time.Duration) image.Image {
}

func init() {
registerAnimation("cy", &Cyform{})
registerAnimation("cy", func() Animation {
return &Cyform{}
})
}
4 changes: 3 additions & 1 deletion pkg/anim/midjo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ func (mid *Midjo) Update(delta time.Duration) image.Image {
}

func init() {
registerAnimation("midjo", &Midjo{})
registerAnimation("midjo", func() Animation {
return &Midjo{}
})
}

0 comments on commit ff6dff8

Please sign in to comment.