【其他技术】牛人1kb写的动画
来源:互联网 发布:war3数据库 编辑:程序博客网 时间:2024/06/05 14:38
How I did the 1kb Christmas Tree
15 de Diciembre del 2010JS1k is a really nice contest for coding tiny 1 kb Javascript programs and try to do something nice in that few available space. In its second edition, all the entries must be Christmas themed.
My contribution to the contest has been a 3D Christmas tree (note it doesn’t work in IE, and works slow in any current browser except in Chrome). I’m really lazy to write articles explaining how I do my visual effects, but in this case a lot of people are asking me to do it, so let’s try it in a visual way:
Finally, some size optimization tricks
I 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.
I used some few math tricks, like using cos(angle+11) to approximate sin(angle) and modular arithmetic.
Finally, I’ve 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.
- 【其他技术】牛人1kb写的动画
- 计算机中KB与Kb的技术差别详解
- KB Kb kB 大小写的区别
- 用 MASM32 写的 4.5KB 的 netstat--NetView
- Kb 和 KB 的区别
- Kb 和 KB 的区别
- Kb和KB的区别
- 烦人的 1KB 1KB文件夹快捷方式病毒专杀
- 实现DIV的其他动画效果
- kb和KB和kbps的区别
- kb、kB、kbps、kBps的区别
- kb、KB、Kbps、KBps的区别
- 宽带中KB与Kb的区别
- KB、kb和MB、Mb的区别
- 找工作遇到的其他技术问题及解答(1)
- 看Struts2技术内幕,对于书中提出的问题,参考其他前辈的文章所写
- 关于写动画的心得
- Java写的动画gif
- 类的继承
- 使用C#格式化字符串 ~
- Android 使用到的名词解析
- strcpy与memcpy以及strncpy
- Linux下的makefile编写详解
- 【其他技术】牛人1kb写的动画
- 痛风的饮食分类
- C#编程的好习惯
- getopt()函数的使用方法
- 更改Zend Studio/Eclipse代码风格主题
- C#有关Split 方法有6个重载函数
- 提高C#编程的50个要点
- hdu1496
- 第3章、第一个“Hello,world!”之Android App(从零开始学Android)