Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tween fix #23

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions library/piglow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import division

import atexit
import operator
import time
from sys import exit

Expand Down Expand Up @@ -248,18 +251,19 @@ def tween(duration, end, start=None):
steps = int(duration / fps)

if start is None:
start = _values
start = _values.copy()

deltas = map(operator.sub, end, start)
deltas_per_frame = [d / steps for d in deltas]

new = start
for x in range(steps):
new = []
for y in range(18):
s = start[y]
e = end[y]
c = float(e - s)
b = s + ((c / float(steps)) * (x + 1))
new.append(int(b))
_set(0, new)
show()
new = list(map(operator.add, new, deltas_per_frame))
new_ints = [round(n) for n in new]
_set(0, new_ints)
# avoid double write
if not auto_update:
show()
time.sleep(fps)


Expand Down