Skip to content

Commit

Permalink
Add animated tail effect
Browse files Browse the repository at this point in the history
  • Loading branch information
lordmauve committed Dec 3, 2018
1 parent 8b74235 commit 237f310
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 0 deletions.
Binary file added examples/basic/images/tail_hook.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/basic/images/tail_piece.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions examples/basic/tail.py
@@ -0,0 +1,35 @@
from math import sin, cos
SEGMENT_SIZE = 50
ANGLE = 2.5
PHASE_STEP = 0.3
WOBBLE_AMOUNT = 0.5
SPEED = 4.0

tail = [
Actor('tail_piece') for _ in range(10)
] + [Actor('tail_hook')]


WIDTH = 800
HEIGHT = 800

t = 0


def draw():
screen.clear()
for a in tail[::2]:
a.draw()
for a in tail[1::2]:
a.draw()

def update(dt):
global t
t += dt
x = WIDTH - SEGMENT_SIZE // 2
y = HEIGHT - SEGMENT_SIZE // 2
for seg, a in enumerate(tail):
a.pos = x, y
angle = ANGLE + WOBBLE_AMOUNT * sin(seg * PHASE_STEP + t * SPEED)
x += SEGMENT_SIZE * cos(angle)
y -= SEGMENT_SIZE * sin(angle)
171 changes: 171 additions & 0 deletions source-vectors/tail.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 237f310

Please sign in to comment.