Tips and tricks I picked up from awesome dweets at Dwitter.
You can find my dweets here :)
credit: albertveli.wordpress.com
for(mask=0xB8,num=1,i=255;i--;console.log(num),num&1?(num>>=1,num^=mask):(num>>=1));
for(i=1920;i--;x.fillRect(960+300*C(i),540+300*S(i),4,4));
-> x = centerX + radius * cos(angle), y = centerY + radius * sin(angle)
even/odd using &
(bitwise AND)
instead of i%2==0 to get even/odd, do x&1
1&1 -> 1
2&1 -> 0
3.2&1 -> 1
2**3
==Math.pow(2,3)
1e3 -> 1000
2e4 -> 20000
3e5 -> 300000
- ...
x.font needs to have a font family set, or else it will ignore font size
x.font="6em 🤷"
'🤷' can be any character
shortest way to clear canvas using |
(bitwise OR)
not sure how this works...
c.width|=0
- edit:
c.width^=0
seem to have the same effect, interesting. bitwise XOR.
from basic dwitter guide by Xen
for(i=9;i--;second_thing)thing;
If you need to initiate a value at the beginning of the loop, like for a counter.
t||(count=0);count++
t?run:setup
(t?count++:count=0
)
The above tips and tricks are snatched from a number of dweets. Sometimes I forgot which, or I have seen the same trick used in multiple dweets by different users. As much as possible I will try to keep track on and list dweets where I got some or multiple trick from here: