🧪 JEX Part 3: Two-Color Pixel Editor Exports to JEX Data (each byte stores 3 values) in Sharable URL
JEX is a URL friendly Base 69 data storage method I created. JEX is a name that combines the names JavaScript and Hexidecimal.
All JEX characters: ()*+,-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~
NOTE: I was about to publish the format before realizing that twitter hates single quotes because they force it to be encoded. I really wanted to keep it at 70, I SWEAR!
These characters are all in order by charCodeAt
and skips URL unsafe characters: &/:;=? @#<>[]{}|\^%\
I reserved ~
tilda as a reserved value to indicate that the data is compressed.
It's the value pair of storing how many times a value is repeated and what that value is.
🖌️ Mini 2-Color Pixel Editor is the editor I created to use JEX.
I based the editor on this project miniPixelArt by xem
const num2Jex=n=>String.fromCharCode(n+40+(n>7?1:0)+(n>17?7:0)+(n>43?6:0));
const jex2Num=s=>(n=s.charCodeAt()-40,n-(n>7?1:0)-(n>18?7:0)-(n>51?6:0));
// three values 0-3 into one integer value
const threeIntoNum = (arr, i=0) => (
0b0000000 + (arr[i] || 0) + ((arr[i+1] || 0) << 2) + (((arr[i+2] || 0) << 4))
);
const numToThree = n => [n & 3, (n >> 2) & 3, (n >> 4) & 3];
These methods are mostly just integrated into my editor code to use less text.
Put them together and you can get this to convert the data.
const extractData = str => {
const output = [];
[...str].map(c => output.push(...numToThree(jex2Num(c)));
return output;
};
The pixel editor features:
- Changing the image dimensions.
- Switching between two colors.
- Changing 2-color palettes I got from lospec.
- Right-click erases
- The "export" button:
- URL is updated with pallete and pixel data
- Minimal code to draw this data
- Bookmarklet that can be run in your addressbar
- Readable and reusable code for drawing the pixel image
This will render the art into a canvas for faster drawing. This will be a more streamlined method for canvas drawing.