Magic numbers. Magic numbers everywhere. Recommended would be to store certain numbers into variables to provide missing yet essential context, e.g. storing 40 in the variable line_spacing. The...
Magic numbers. Magic numbers everywhere. Recommended would be to store certain numbers into variables to provide missing yet essential context, e.g. storing 40 in the variable line_spacing. The author states "Changing the size and reducing the number of circles lead to interesting effects. Enjoy fooling your brain!", but the code in its current form doesn't facilitate this sort of experimentation without a great deal of effort.
Don't get me wrong, it's pretty neat to see something like this. I just feel the urge to do a refactor :)
constfloatPI=3.14159265359;constfloatn_stripes=25.0;// 0..constfloatstripe_width=0.2;// 0..1mat2rotate2d(floatangle){returnmat2(cos(angle),-sin(angle),sin(angle),cos(angle));}voidmainImage(outvec4fragColor,invec2fragCoord){// Convert coord from pixels to units of screen height - also compensates for aspect ratio.// Then rotate by 45 degrees.vec2uv=(fragCoord/vec2(iResolution.y))*rotate2d(PI/4.0);// These names are a bit dishonest when the image is rotated.// vert and horiz could be computed in a single expression, but for code that will be toyed with// keeping them separate improves the hackability.floatvert=((mod(uv.x,1.0/n_stripes)*n_stripes)<stripe_width)?0.5:0.0;floathoriz=((mod(uv.y,1.0/n_stripes)*n_stripes)<stripe_width)?0.5:0.0;fragColor=vec4(vec3(vert+horiz),1.0);}
Magic numbers. Magic numbers everywhere. Recommended would be to store certain numbers into variables to provide missing yet essential context, e.g. storing
40
in the variableline_spacing
. The author states "Changing the size and reducing the number of circles lead to interesting effects. Enjoy fooling your brain!", but the code in its current form doesn't facilitate this sort of experimentation without a great deal of effort.Don't get me wrong, it's pretty neat to see something like this. I just feel the urge to do a refactor :)
Here's a similar one in GLSL:
https://www.shadertoy.com/view/tslSRS
Edit: Added a few comments to the code