Cool Crack
  • Home
  • Contact Us

Tuesday, December 21, 2010

A Christmas Tree in 1k of Javascript

Posted by Fiona at 6:48 AM Labels: Bizzare
Share this
Tweet


JS1k is a really nice contest for coding tiny 1 kb Javascript programs and try to do something nice in that few available space.



















Finally, some size optimization tricks

Used several tricks to make the code fit in 1 kb. The most of them are the usual tricks for reducing Javascript code size, like renaming variables to single character names, removing white spaces, unnecesary semi-colons and so on.

It is also very common to assign functions you use more than one time to variables to avoid the repetition. For example, if I do r=Math.random;, I can call r() each time I need a random number.

Used some few math tricks, like using cos(angle+11) to approximate sin(angle) and modular arithmetic.

Finally, used some other tricks like reusing functions. A function does different things depending on if it received parameters or not. This saves some few bytes from writing again “function”.

Writing code for limited size competitions is mostly like a puzzle or logical game. In the most of the cases there is not a common rule to do it, but just thinking and trying different ways to achieve the same goal in less space. It is usually possible to fit 5 or 6 kb of normal code in 1 kb if you try it and don’t give up.
Newer Post Older Post

No comments :

Post a Comment

Subscribe to: Post Comments ( Atom )

Popular Posts

  • Mother with no prior offenses sentenced to TWELVE YEARS in prison for $31 marijuana offense
    Mom of 4 reflects on first year in prison for $31 pot sale Patricia Spottedcrow has served one year of her prison sentence. Listen to ...
  • Animated Timeline of North American Colonization
  • An American homeless family (30 Pics)
    Photographer Lucy Nicholson documented the plight of Benita Guzman, 40, and her niece Angelica Cervantes, 36, who are homeless with eleven c...
  • Boy constructed a suicide helmet that fired 9 shotgun shells into his head simultaneously
     Suicide Helmet - side view A young man constructed a suicide helmet 40+ years old that fired eight shotgun shells into his head simult...
  • Yes, People Really Google These Things Every Day
  • Life of Terrorists In the Forest
    What if a person has to live far from civilization, somewhere in the forest? The main problem becomes hygiene. Sooner or later you becom...
  • Sir Ian McKellan’s Favorite Breakfast Recipe (10 gifs)
    The actor is best known for his role as Gandalf in the “Lord of the Rings” film series but he can also make a really mean breakfast as he d...
  • Very Rare German SS Belt Buckle (24 pics)
    This is a very rare Nazi multi-shot 5.6mm (.22 cal) belt buckle gun invented y Louis Marquis while in a WWI POW Camp and received a patent f...
  • 24 Most Iconic Movie Dresses of All TIme
    Custom design in the movie can surely define the identity of the same and decide if the movie will have a dress trade mark. Through out ...
  • School Lunches in Different Countries (40 pics)
    Let's see what school lunches in different countries consist of. Japan Korea France Sweden Czech Republic Italy Si...
Powered by Blogger.

Labels

Amazing Bizzare Cool Funny News Pictures Wierd

Blog Archive

© Cool Crack 2014 .