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.
I changed the code following a suggestion by u/KilledByAPixel who indicated that using fillStyle in a big loop slows the code a lot. And indeed, the framerate doubled. Though I had to use clearRect now. Maybe there is another solution for that? for(x.clearRect(0,0,1920,1080),j=-1;j<(w=255);i++)for(y=2*j++/w-1,i=-1;i<w;i++)k=2*i/w-1,d=Math.sqrt(k*k+y*y),a=Math.atan2(y,k),z=w*C(a)/d+t*w^w*S(a)/d+t*w,x.fillRect(420+4*i,4*j,n=(z&w)/w*4,n);
Setting the width or height of the canvas will reset the canvas. c.width+=0 will do the trick, and besides being a great golfing trick, it is also faster than clearRect
Dear @danny@hille.dk Since you answered so kindly and are obviously skilled in 'golfing' I dare to ask you one more question. I am struggeling to dweet to minify my next dweet. The original code would be: for(h=1080,b=540,c=420,d=950,g=x.createRadialGradient(d,b,0,d,b,c),g[a="addColorStop"](0,"#4BB"),g[a](1,"#005"),x.fillStyle=g,x.fillRect(c,0,h,h),i=6e3;i--;)k=d+S(i+t)*S(i*i)*c,y=b+c*C(i*i),x.fillText("◻️",k,y) But with 210 characters far to big, even compressed (149). So I tried to create the gradient drawing circles like; for(d=950,b=540,s=0,c=420,c.width+=0,i=40;i--;)x.beginPath(s+=2),x.arc(960,540,40*i,0,7),x.fillStyle=hsl(231,${s}%,${s/2}%),x.fill();for(i=6e3;i--;)k=d+S(i+t)*S(i*i)*c,y=b+c*C(i*i),x.fillText("◻️",k,y) But that only saved 7 characters and compressed still has 147. Is there still something possible?
Hi @Noel, When making a Dweet, think of best practice and do the opposite: only use variables when you need them, and wait until you need to use them the first time to initialize them. 194b, but I'm sure it can be golfed even further: for(g=x.createRadialGradient(d=950,b=540,0,d,b,e=420),g[a="addColorStop"](0,"#4BB"),(x.fillStyle=g)[a](1,"#005"),x.fillRect(e,0,h=1080,h),i=3e3;i--;)x.fillText("◻️",d+S(i+t)*S(i*i)*e,b+e*C(i*i))
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)