Skip to content

rippedspine/dwitter-cheat-sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

dwitter-cheat-sheet

Tips and tricks I picked up from awesome dweets at Dwitter.

You can find my dweets here :)

psuedo random number generator

credit: albertveli.wordpress.com

  • for(mask=0xB8,num=1,i=255;i--;console.log(num),num&1?(num>>=1,num^=mask):(num>>=1));

plotting an ellipse/circle

  • 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

to the power of

  • 2**3 == Math.pow(2,3)

less bits to write 1000, 20000, 300000 etc...

  • 1e3 -> 1000
  • 2e4 -> 20000
  • 3e5 -> 300000
  • ...

setting (only) fontsize

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.

for loops

from basic dwitter guide by Xen

  • for(i=9;i--;second_thing)thing;

initiate values

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)

credit is where credit's due

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:

About

My cheat sheet for writing dweets at https://dwitter.net

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published