Skip to content

Instantly share code, notes, and snippets.

@petfactory
Last active August 29, 2015 14:27
Show Gist options
  • Save petfactory/9ecb87f7905dd79fd5df to your computer and use it in GitHub Desktop.
Save petfactory/9ecb87f7905dd79fd5df to your computer and use it in GitHub Desktop.
import math
grid_size = 20
#oldMin, newMin, oldMax, newMax
def lerp(x0, y0, x1, y1, x):
return y0+(y1-y0)*(x-x0)/(x1-x0)
# t: current time, b: begInnIng value, c: change In value, d: duration
def easeInOutCubic(t, b, c, d):
t /= d/2
if t < 1:
return c/2*t*t*t + b
t -= 2
return c/2*(t*t*t + 2) + b
#val = [math.pow((x/(grid_size-1.0)), 2.2) for x in range(grid_size)]
#val = [lerp(0,0,1,1,(x/(grid_size-1.0))) for x in range(grid_size)]
#val = [easeInOutCubic( (x/(grid_size-1.0)), 1,1,1) for x in range(grid_size)]
val = []
for time in range(grid_size):
t = float(time)/(grid_size-1)
b = 0.0
c = t
#print(t, c)
d = 1.0
val.append(easeInOutCubic(t, b, c, d))
#print(val)
#val.reverse()
#print(val)
index_list = [int(round(x*(grid_size-1))) for x in val]
for u in range(grid_size):
s = ''
for v in range(grid_size):
s += '.' if v == index_list[u] else ' '
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment