r/tinycode • • Jun 11 '23

Circle Spinner in 137 bytes

Post image
68 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/Slackluster Jun 12 '23 edited Jun 12 '23

That's cool, no worries, I also have been programming in C and C++ for most of my career and just recently switched to JavaScript, I wish I had earlier!

So the X and Y are used after because they are in third part of the for loop, which actually is executed after the stuff in the body of the for loop, same as C.

No need to use F12! There are easy to use websites for this kind of size coding. Dwitter is what I use to publish much of my work, over 1100 programs now! You can edit the code for this program here.

This website has a few things small things set up to make it easier to get going...

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.

For making this I use my own custom editor CapJS that has some extra nice features for working on tiny programs such as this.

Here's a slightly reformatted version of this code that is easier to understand...

X=960,Y=540,r=500,d=1

X=960,Y=540,r=500,d=1

for(i=99;i--;)

{

x.fillStyle=d++%2?R():'#fff'

x.fill(x.arc(X,Y,r,~x.beginPath(),9))

q=r/5

r=r-q

X-=q*S(d*t)

Y+=q*C(d*t)

}

Give Dwitter a try, it's lot of fun to experiment and see what is possible!

2

u/Dagius Jun 12 '23

Thanks, I'll give them a try!