String Pixelater
This is a simple tool to pixelate any characters. pixelate
means to "convert a character to a two-dimensional array" so that we can deal with the tabular data for several purposes. I actually compose this and p5.js for painting generative art.
> StringPixelater 01110000000000000000000000000001100011100000000000000000 00110000000000000000000000000001100011100000000000000000 00110000000000000000000000000001100011100000000000000000 00110000000000000000000000000001100011000000000000000000 00110000000000000000000000000001100011000000000000000000 00110011111000000001111110000001100011000000011111100000 00111111111100000011111111000001100011000001111111110000 00111110011110000111000111100001100011000011110001111000 00111100001110001110000001100001100011000011100000111100 00111000000110001110000001110001100011000111000000011100 00110000000110001110000001110001100011000110000000001100 00110000000110001111111111110001100011000110000000001100 00110000000110001111111111110001100011000110000000001100 00110000000110001100000000000001100011000110000000001100 00110000000110001100000000100001100011000111000000011100 00110000000110001110000001110001100011000111000000011100 00110000000110000111000011110001100011100011110001111000 00110000000110000111111111100001100011100001111111110000 00110000000110000001111110000001100011100000111111100000
How does it work?
- It uses
<canvas>
element as a temporary canvas to render characters. - Then it extracts and parses rasterized image data.
Usage
Just install and call StringPixelater.pixelate
method with a string which you want to pixelate.
$ npm install --save string-pixelateror$ yarn add string-pixelater
Use as ES module
; const table = StringPixelater;
<script>
tag
Load through
Pixelation Options
You can change StringPixelater
's behavior with the following options.
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
fontSize | false | number |
12 |
Font size. |
fontName | false | string |
'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'メイリオ', Meiryo, Osaka, 'MS Pゴシック', 'MS PGothic' |
Font name. |
transpose | false | boolean |
false | If it's true , it transposes a result tabular. |
transpose
If you use p5.js
or something that has inverted axes, transpose
option is quite convenient.
> StringPixelater 001111111111100000 001111111111110000 001100000001111000 001100000000111000 001100000000011000 001100000000011000 001100000000111000 001100000001111000 001111111111110000 001111111111110000 001100000000111000 001100000000011100 001100000000011100 001100000000011100 001100000000011100 001100000000011100 001110000001111000 001111111111111000 001111111111100000 > StringPixelater 0000000000000000000 0000000000000000000 1111111111111111111 1111111111111111111 1100000011000000111 1100000011000000011 1100000011000000011 1100000011000000011 1100000011000000011 1100000011000000011 1100000011000000011 1110000111000000111 1111001111100000111 0111111111111111110 0011111100111111110 0000000000011111000 0000000000000000000 0000000000000000000
The latter looks correct when it's rendered with simple and intuitive loops.
// Note: This is just pseudo code! { const imageData = StringPixelater const pixelSize = 10; imageData}
This results like below:
Examples with this library
It just uses StringPixelater.pixelate('hello')
.
We can get pixelated emoji as like StringPixelater.pixelate('🐈')
.