Guest User

Untitled

a guest
Jan 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style media="screen">
  5. html, body {
  6. height: 100%;
  7. width: 100%;
  8. margin: 0;
  9. font-size: 0;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <canvas></canvas>
  15. <script type="text/javascript">
  16. const colors = [
  17. [255, 255, 255, 255],
  18. [255, 0, 0, 255],
  19. [0, 255, 0, 255],
  20. [0, 0, 255, 255],
  21. [0, 0, 0, 255],
  22. ]
  23. const getRNGItem = arr => () => arr[Math.round(Math.random() * 10000) % arr.length]
  24. const rngColor = getRNGItem(colors)
  25.  
  26. const getImgArray = (length = length) => {
  27. const arr = new Array(length).fill(null).map(rngColor)
  28. return arr.reduce((acc, pix, idx) => {
  29. for (let i = 0; i < 4; i++) {
  30. acc[idx * 4 + i] = pix[i]
  31. }
  32. return acc
  33. }, new Uint8ClampedArray(length * 4))
  34. }
  35.  
  36. const searchSplitRX = /[\?&]/g
  37. const parseQS = search => search.split(searchSplitRX).filter(Boolean).map(token => {
  38. return token.split('=')
  39. }).reduce((res, pair) => {
  40. res[pair[0]] = pair[1]
  41. return res
  42. }, {})
  43.  
  44. const { w = 64, h = 64 } = parseQS(location.search)
  45.  
  46. const canvas = document.querySelector('canvas')
  47. const ctx = canvas.getContext('2d')
  48. canvas.height = document.body.clientHeight
  49. canvas.width = document.body.clientWidth
  50.  
  51. const fireRepaint = () => {
  52. const img = new ImageData(getImgArray(w*h), w, h)
  53. createImageBitmap(img).then(bm => {
  54. ctx.fillStyle = ctx.createPattern(bm, 'repeat')
  55. ctx.fillRect(0, 0, canvas.width, canvas.height)
  56. requestAnimationFrame(fireRepaint)
  57. })
  58. }
  59.  
  60. requestAnimationFrame(fireRepaint)
  61. </script>
  62. </body>
  63. </html>
Add Comment
Please, Sign In to add comment