Convert spiral.py to function