Final version

This commit is contained in:
Peter D. Gray 2020-01-22 10:14:42 -05:00
parent c915c2c29d
commit f5bb5df923

33
graphics/cylon.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from math import sin, pi
from collections import Counter
W = 128 # screen width
PW = 12 # width of eye
parts = 53 # of animation steps
dr = (2*pi) / parts
RW = W - PW - 1
ampl = (RW/2) + .5
offset = (W/2) - (PW/2)
rv = []
r = 0
for n in range(parts):
x = (ampl * sin(r)) + offset
x = int(x+.5)
print(f'{n:2d}: {x:3d} ' + (' '*x) + 'X')
r += dr
rv.append(x)
assert rv[0]+(PW//2) == W//2, rv[0]
assert max(rv) == W-PW, max(rv)
assert min(rv) == 0, min(rv)
# only want it to hesitate at the ends
cnt = Counter(rv).most_common()
assert max(c for x,c in cnt) == 2, repr(cnt)
print("\nResult: " + ', '.join(str(i) for i in rv))
print("\ncylon = %r" % bytes(rv))