5 ms·
Randomness in CSS using trigonometry
- moritzwarhier 3y agoTitle already makes me love the article. Whenever I got back to how fun it is to plot 2D functions, I soon started to try creating freaky images with parts of seeming chaos. Like combining trigonometric, algebraic and discontinous functions such as the floor function. Unfortunately, https://en.m.wikipedia.org/wiki/Thomae%27s_function https://en.m.wikipedia.org/wiki/Thomae%27s_function requires branching and a complex discontonuous and uncomputable (?) function in the definition :)
- petepete 3y ago[flagged]
- rappatic 3y agoAlso in Firefox on macOS
- rav 3y agoLooking at the CSS on the blog, there's some "@media (prefers-color-scheme: dark)" directives that change certain colors when dark mode is enabled - but at the same time, links are made white unconditionally. Probably the author has dark mode enabled and hasn't tested their website in light mode. In the past, and I.
- tantalor 3y agoAlso Chrome desktop
- goettingen 3y agoI like the article, but what irks me is the use of the word "pseudorandomness," which has a technical definition in TCS.
- gus_massa 3y agoIIUC this gives a random distribution between 0.0 and 1.0 but it is not a uniform distribution. There are more results near 0.0 and 1.0 than near 0.5. If you use this function twice to draw random black points on a white square, the corners will look darker than the center.
- pclmulqdq 3y agoIf you replaced the sine function with a sawtooth wave (n - floor[n]), you would have continuous, uniformly distributed "pseudorandom" numbers from this method. I think the round() function in CSS is still experimental, but you may be able to get a similar effect by intentionally underflowing a floating-point calculation. Arcsin(sin(x)) would also work, or arccos(sin(x)), but you would probably have to make an approximation of arcsin/arccos for yourself.
- gus_massa 3y agoI agree, but for a continuous function you need abs((n - floor[n])-1/2)*2 https://www.wolframalpha.com/input?i=abs%28%28n+-+floor%5Bn%5D%29-1%2F2%29*2 https://www.wolframalpha.com/input?i=abs%28%28n+-+floor%5Bn%...