Rhai support
I got rhai to work. It took a bit to figure out how to expect the script to return an array of 3 u8’s, but after figuring out that all rhai numbers are i64 and then figuring out how to downsize that to u8 it works!
Later I then added the current coordinates into the scope and a rand function to generate noise.
Monaco
A bare textarea element for script input is pretty bad so I switched to the monaco editor. Its the same one VSCode uses so most of us should be pretty familar with it and its keybinds. It took some time to figure out how to load monaco from CDN and not build locally. I also had some cosmetic bugs with the minimap, so I just disabled it as the scripts should be rather short and its not that useful anyways. Using localstorage the script now also persist between sessions.
Anti-Aliasing
As you can see the output isn’t clear but has these weird white lines. These do go away after running the script multiple times. This due to the browser doing some post processing like anti-aliasing on the drawn rectangles and it adds some semi-transparent pixels to the edges. This is especially bad if you pass use decimal values as coordinates to draw to the canvas, which I am doing to fit my pixels on there. I tried multiple methods to disable this post-processing for drawing filled rectangles, but nothing worked.
The solution is to use a hidden canvas, draw the output at native resolution to it and then transfer the image from that canvas to the real one. The putImage function does allow me to disable post processing and adjust the destination size. Now it works and the bare minimum is here
.
As always you can test it here! It automatically runs off of the latest commit. 
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.