pouët.net

JS1k, 1k Javascript demo contest

category: code [glöplog]
po1: your entry is unbelieveable. Awesome.
added on the 2010-08-06 15:58:21 by auld auld
THANKS!

rez: A bit ? I'll try to help you 112 bytes and more! Can you send me a link or script at my nick @opera.com ?
added on the 2010-08-06 16:24:08 by p01 p01
p01 won.
added on the 2010-08-06 16:28:14 by xernobyl xernobyl
p01: Unbelievable indeed!
added on the 2010-08-06 17:00:02 by mrdoob mrdoob
p01: WTF

Now, when do we vote? :)
added on the 2010-08-06 17:38:55 by Zplex Zplex
awesomely great
added on the 2010-08-06 17:42:24 by flure flure
@p01: mail sent :)
added on the 2010-08-06 22:13:13 by rez rez
rotating 3D wireframe cube + oldschool fire effect
http://js1k.com/demo/76
p01
added on the 2010-08-06 22:52:04 by Pirx Pirx
rez: Looking at it...

  • :\ you didn't use the template page provided on the contest page. The HTML markup is FIXED, and your JS code is shoved directly into a SCRIPT tag. No need for onload or other stuff like that.

  • check the code of a couple of entries to see how people get a hold of the canvas, width and height of the page, etc...

  • you wrote many functions that are either used only once, or in single context, or simply replicating the exact behavior of the native JavaScript functions.

  • use alias variables for things like Math, Math.sin, ...

  • the first argument of setTimeout and setInterval is either a function handle or a string of JavaScript code to parse and evaluate. That means that things like: setInterval( "functionName()", 10 ); are just bad and should be replaced by setInterval( functionName, 10 ); or setInterval( "/* a shit load of code */", 10 ); if you run out of space for the contest and need to save the few bytes used for the function declaration.

  • use and abuse one letter variable and function names

  • don't even use a variable for things you use only once, just shove the expression directly where you actually need the result.

Applying these simple techniques will trim a solid 400 bytes to the code you sent me.

Also running your code more or less as is through Google Closure Compiler does bring it under the 1k.


Hope the tips above will help you and others write nice and tiny prods ;)
added on the 2010-08-06 23:48:50 by p01 p01
Thanks guys! Such feedback is motivating!

Zplex: So far the jury is made of 3 web developers, and the JS1K contest is not about the demoscene but about javascript demo. So god knows what the jury will go for. I REALLY really hope they won't fall for something super cheesy or that was done 8 years ago at the5k or the 256b.htm contests or that has been done in 256b or less.
added on the 2010-08-07 00:30:01 by p01 p01
I predict the mario one will win ;)
added on the 2010-08-07 01:15:19 by mrdoob mrdoob
p01 - i think your fractal is too technical to impress. anyone not knowning what it is will take it as a moving turd. that said, you're awesome :)
rasmus: True! I got much much much better feedback from demoscene savvy people than from the more general crowd.
added on the 2010-08-07 12:38:57 by p01 p01
p01: was it a rule to go fullscreen? i think most people of the "general crowd" won't like the blurry low-resolution look. maybe using 1:1 monitor resolution by downsizing the output canvas would help... ?
added on the 2010-08-07 13:02:26 by hcdlt hcdlt
don't get me wrong btw: it's my clear winner by a long shot!
added on the 2010-08-07 13:03:11 by hcdlt hcdlt
added on the 2010-08-07 16:47:21 by rez rez
doesn't run in firefox 3.6 here: "p is null"
yeah, when p01 touches your code it only runs on opera ;)
added on the 2010-08-07 16:55:35 by xernobyl xernobyl
Hey, i have seen that by MrDoob on asm tv. Great product!
added on the 2010-08-07 17:20:35 by [ej] [ej]
rez: but you completely overlooked the 1st, 3rd and 4th tips I gave above. u______U

Code:function mc(e){return m.cos(e)}function ms(e){return m.sin(e)}function mr(e){return m.ceil(e)}function mu(){return m.random(0,1)}
can be replaced by
Code:C=m.cos;S=m.sin;R=m.ceil;U=m.random
-> 122 bytes saved


Your alias variable for window is unecessary since window is the global scope.
-> 13 bytes saved

(...)


xernobyl: Thanks, but I touched the code yesterday when looking at it and it worked in all four browsers and was 400 bytes smaller. But then there's no point passing that to Rez like this because it actually became MY code. I'd much rather give him hints and tips to optimize his code.


Sorry if I sound sour but I'm in a rush right now and I have a feeling I wasted my time analyzing the code last night :(


added on the 2010-08-07 17:22:03 by p01 p01
po1: ho, I read everything and use ALL your advice to reduce the size :(

just i didn't know that it was possible to replace m.cos too :|

and for the "window", i copy them from another compo entry (one of your advice), i will remove it :)
added on the 2010-08-07 17:32:10 by rez rez
well, PLASMA updated!

969 bytes and working under firefox now :)

I added the <body> tag to make it working...
added on the 2010-08-07 17:41:36 by rez rez
UPDATED a last time, 895 bytes!

Thank a lot for your help here (p01!) and on irc (LLB,Msk,Kernel_error...) ^_^
added on the 2010-08-07 19:18:06 by rez rez
I've played with Rez plasma and managed to shrink it to 763 bytes using some dirty tricks. I haven't read contest rules, so no idea if it's valid or not. I have tested it on Firefox and Opera.

http://www.ctrl-alt-test.fr/misc/plasma.html

(Rez, feel free to copy/reuse my optimizations)
added on the 2010-08-07 19:46:38 by LLB LLB

login