Xmas and Javascript, part 2 · Dez 10, 18:02
I just uploaded a new version of my xmas js1k submission. It features a significant graphics upgrade and some insane optimizations. Here are the highlights:
function K(x,y,r,u,v) {
r ? a.beginPath() | a.fill(a.arc(x,y,r,u||0,v||7,0))
: a.fillStyle = '#'+'a000b4bbfff5'.substr(x,3);
return K
}
So, this function…
- sets a color or paints a circle or a segment of a circle depending on the parameters.
- can be chained like this
K(8)(90,590,E*2)(1)(145,y=24,14)by returning itself. - uses
|to concatenate function calls since using,would require parentheses. - nests function calls without parameters like
fill(). - features a total of 10 colors(of which 6 are used) by interlacing them.
p = (x|y) >> 8
This line checks whether the x and y coordinates are not in the game area (between 0 and 256).
More precisely, p is 0 if the values are valid. The coordinates can be checked in one step since the size of the area is a power of 2(2^n) and the bit representation of all valid values have 1’s only in the last n bytes(negative numbers have at least one leading 1, see Two’s complement).
— arne