Skip to content

Instantly share code, notes, and snippets.

@olls
Last active August 29, 2015 14:15
Show Gist options
  • Save olls/393104bbd4b5a2ce8094 to your computer and use it in GitHub Desktop.
Save olls/393104bbd4b5a2ce8094 to your computer and use it in GitHub Desktop.
Trying to golf down an animated, coloured ASCII sine wave. Usage: `python3 sine.py [width] [height]`
import math,time,sys
j,i,p=int,0,print
W,H=map(j,sys.argv[1:])
while 1:y=0;exec("x=0;exec(\"d=math.sin(x*6/W)*math.sin(i);p('\x1b[3'+str(j(abs(d)*8))+'m'+' #'[j(H/2*(1+d))==y],end='');x+=1;\"*W);p();y+=1;"*H);i+=.1;time.sleep(.1)
import math,time
i=0
while 1:i+=.3;a=math.sin(i)*4+4;print(int(a*2)*' '+'\x1b[3'+str(int(a))+'m#');time.sleep(.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment