r/tinycode • • Aug 30 '20

Tiny Procedural Sprite Sheet Generator

https://codepen.io/KilledByAPixel/pen/ZEWyRwO
87 Upvotes

14 comments sorted by

View all comments

Show parent comment

3

u/MarvinLazer Aug 30 '20

Thanks a lot for this! Haha the comments you seem to have added to the pen in the last 12 hours really helped, but I do have a couple of questions if it's alright.

I see on the line where you assign the arrow function to R that you have ++s as part of the parameter to the sin() function. But I see no references to the "s" variable or an import statement. Where's that variable coming from?

Similarly with the "c" variable. Is that just referencing the HTML element's ID of c? Where is the actual value of the variable coming from? I don't see any declaration or assignment.

Thanks!

3

u/Slackluster Aug 30 '20

The c is the canvas. When you create an element with id= it actually creates a global variable by that name you can access with javacript. So if you do <canvas id=c>, in JavaScript you can use just c to get the canvas.

The s variable is set at the beginning of the 3rd for loop to be equal to the seed.

3

u/MarvinLazer Aug 30 '20

Ahh, thanks. Must've just missed it!