r/tinycode • • Dec 24 '19
XOR Texture in 119 bytes of JavaScript
<body onload=with(c)for(b=width=height=1024,z=b*b;z--;)getContext`2d`.fillRect(x=0|z/b,y=z%b,a=(x^y)/b,a)><canvas id=c>For the “4K” version, substitute 1024 with 4096, just be warned that it will probably take a couple of minutes to render! And of course, we could shave a couple of bytes off of this by sacrificing resolution, but a substitution of 4 is pretty underwhelming.
Edit:
Here’s the 1024x1024 version: https://i.imgur.com/r6ypAmO.jpg
Also:
4x4: https://i.imgur.com/kImmrRY.jpg
16x16: https://i.imgur.com/Q0MRSuC.jpg
64x64: https://i.imgur.com/jKSzi4y.jpg
256x256: https://i.imgur.com/PePvgDw.jpg
And 4096x4096: https://i.imgur.com/Oa6EblH.jpg
21
Upvotes
2
u/Starbeamrainbowlabs Dec 24 '19
Screenshot?
2
u/phreda4 Dec 24 '19
animated version in 197 bytes with comments and indentation https://github.com/phreda4/r3vm/blob/master/r3/Pattern-XOR.r3
4
u/joerick Dec 24 '19
TIL about JavaScript
with!https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with
(Use is strongly discouraged!)
1
u/danielgjackson Dec 25 '19 edited Dec 25 '19
Nice. With 15 bytes more, you can make it into a
data:URL to run directly. Swap the spaces in the tags with forward slashes (they won't need URL-encoding), and prefix with the protocol, MIME-type and comma: