Show HN: Shiny.js simulates reflections on the web for mobile devices
github.com
github.com
https://www.theverge.com/2012/6/13/3082329/ios-6-button-tilt...
Apparently Apple has a patent pending.
Bob below has build what you describe above, so he might receive a letter from Apple in the near future ;)
Commit with code: https://github.com/webuildsg/geekbrunch.sg/commit/b995205094...
Now the site no longer uses this effect, but using another (much) cooler effect.
I'm looking at switching to GPU accelerated transforms instead but that brings a couple of new challenges.
The website says it is untested on android and it shows how weird and inconsistent browsers are.
On android firefox it looks like the iPhone example but the light movement is very choppy (maybe hardware acceleration is missing or something like that).
On chrome the movement is smooth but the markup is not rendered correctly.
It's doing some seriously slow stuff behind the scenes. For example, when the library initialises it creates a 64 * pixelDensity square canvas and then loops through all the pixels in it one by one using a randomly generated transparent color value to draw a 1x1 rectangle to each one (See the 'generateNoise()' function in https://github.com/rikschennink/shiny/blob/master/src/index....). That's just slooooow. HTML5's canvas API has a putImageData method that is much faster because all you're really doing when you fill an image is assigning values to a UINT8 typed array with 4 values per pixel.
It'd be relatively straightforward to achieve this effect using WebGL and a quad to overlay the element, and just pass in the orientation data as a vec2 uniform. That's how some of the effects in my React Neon library work (https://react-neon.ooer.com/) for mouse coordinates. Although, that said, Neon is Chrome-only because it relies on ResizeObserver at the moment. One day I'll fix that...
What is most likely causing the chopiness is that it's animating background gradients. There is a lot of room for improvement there, instead of animating the background gradient we could transform a layer instead.
Anyway, PR's are always welcome.
Using Firefox 64.0 on KDE Neon 18.04, the contents of this page shows up for a brief moment but then goes white.
Once I went to demo website on my mobile phone everything made perfect sense!
Maybe the gif should be an actual screenvideo?