Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Triangle Wave solution in Creative category for Square Spiral by gyahun_dash
from math import sqrt
def triangle(t, period):
return period / 4 - abs(t % period - period / 2)
def saturate(signal, threshold):
return max(-threshold, min(threshold, signal))
def coordinate(index):
if index == 1: return (0, 0)
orbit = (sqrt(index - 1) + 1) // 2
arc = index - (2 * orbit - 1)**2
coord = (triangle(arc + shift, 8 * orbit) for shift in (-orbit, orbit))
return [saturate(z, orbit) for z in coord]
def find_distance(first, second):
firstvec, secondvec = map(coordinate, (first, second))
return sum(abs(f - s) for f, s in zip(firstvec, secondvec))
May 30, 2014
Comments: