dwitter.net

+ New dweet
function u(t) {
} //
122/140


Please log in (or register) to post a dweet (copy-paste the code somewhere safe to save it meanwhile)


u(t) is called 60 times per second. t: Elapsed time in seconds. S: Shorthand for Math.sin. C: Shorthand for Math.cos. T: Shorthand for Math.tan. R: Function that generates rgba-strings, usage ex.: R(255, 255, 255, 0.5) c: A 1920x1080 canvas. x: A 2D context for that canvas.
show FPS hide FPS share fullscreen

function u(t) {

}//
113/140


Please log in (or register) to post as a new dweet (copy-paste code somewhere safe to save it meanwhile).

  • The Patient Square
  • u/danny@hille.dk
    Arrow functions can be simplified, if you only have one argument you don't need parentheses, and if your result can be expressed as a a single line you don't need curly brackets and return
  • u/danny@hille.dk
    so r can be simplified to: r=_=>Math.random()*400
  • u/danny@hille.dk
    Since you are using the custom random function more than four times, you can go even further with the golf. You can use a trick where you override the valueOf on an object; normally, you need to create an object, but since you don't use the trigonometric function T, you can use it like this: T.valueOf=_=>400*Math.random() x.fillStyle=R(T,T,T) x.fillRect(960+S(T)*400,500+C(t*3)*T,1,5)
  • u/danny@hille.dk
    u/magna used this trick in d/22152
  • u/_louis
    Thank you for the advice, Danny! ;-)

Please log in (or register) to comment.

u(t) is called 60 times per second. t: elapsed time in seconds. c: A 1920x1080 canvas. x: A 2D context for that canvas. S: Math.sin C: Math.cos T: Math.tan R: Generates rgba-strings, ex.: R(255, 255, 255, 0.5)