r/programming • • Dec 20 '10

A Christmas Tree in 1k of Javascript

http://www.romancortes.com/blog/how-i-did-the-1kb-christmas-tree/
1.1k Upvotes

221 comments sorted by

View all comments

13

u/abeliangrape Dec 20 '10

Can some explain to me how using cos(angle+11) for sin(angle) saves space?

15

u/majoris Dec 20 '10 edited Dec 20 '10

Paraphrasing his code, here is how it looks with and without the trick:

M=Math;T=M.sin;T(a);T(a);T(a);T(a);T(a);T(a-11);T(a-11)
M=Math;T=M.sin;S=M.cos;T(a);T(a);T(a);T(a);T(a);S(a);S(a)

edit: who gave me upvotes without checking my solution!

6

u/cnk Dec 20 '10

in the 2nd line you don't need the "-11"s