ASCII 是原始字符之一的名称编码. 字符编码将数字映射为字符形状;数字 65 是 ASCII 方案中的大写字母 A。 ASCII 仅允许大约 95 个可打印字符,并且非常以美国为中心。 但是在计算的黎明时期,在图片被发明之前,有ASCII 艺术. 通常用电传打字机在黄纸上打印,JMP 将使用蓝纸。

沃尔特迪斯尼,源图片在这里. 感谢维基媒体!
此脚本使用 JMP 13 中的功能。 第一段代码设置了一些参数;它们被移到脚本的前面,以便于调整设置。
fontsize = 6; // bigger font has more variation in pixel density but ... is bigger
fontname = "Courier New"; // monospaced fixed width is important for display
fontcolor = RGB Color( 0, 0, 0 ); // black. the characters never go completely black;
backgroundcolor = RGB Color( .75, 1, 1 ); // tinting the background helps darken the image
nlines = 100; // height of result, with big font you'll be scrolling
url = "https://upload.wikimedia.org/wikipedia/commons/d/df/Walt_Disney_1946.JPG";
// grab an image. Thanks wikipedia!
image = Open( url );
接下来,构建一个数据表,描述字体中每个字符的亮暗程度。 该表有四列,每列都是一个公式列。 这代码column 使用行号(加上 31)来生成 ASCII 码。 这字符column 通过制作代码的单元素矩阵,将其转换为二进制,然后将其转换为字符,将代码转换为可打印字符。 您将在下面看到另一个示例。 这位图column 是一个包含字符图片的表达式列。 最后,重要的n黑色column 包含字符中黑色像素的数量;它检索像素矩阵并将它们相加。 因为字符是抗锯齿的,所以结果不是整数,但这使它变得更好! 仅从位图中获取红色像素阵列,因为所有三个 r、g、b 阵列对于白色背景上的黑色文本应该是相同的。
// build a table of ascii codes, sorted by pixel density
dt = New Table( "ASCII",
Add Rows( 95 ), // space thru just before rub-out
New Column( "code", numeric, formula( Row() + 31 ) ), // space is 32
New Column( "char", Character, "Nominal", Formula( Blob To Char( Matrix To Blob( code::code, "uint", 1, "big" ) ) ) ), // num to ascii
New Column( "bitmap", Expression, formula( Text Box( char, <<SETFONTSIZE></SETFONTSIZE>
从表中删除一些行。 如果没有元音,分散注意力的字母组合可能不会出现,并且一些字符(如下划线)的所有像素权重都偏离中心,从而产生分散注意力的空白斑点。 我向后写了循环,因为我认为我会沿途删除行。 然后我弄清楚了 selectRows 和 deleteRows 是如何工作的。
// remove vowels so words don't appear, and a couple of off-center characters so empty spots don't appear
For( r = N Rows( dt ), r >= 1, r--,
If( Contains( "AEIOUYaeiouy_`", dt:char[r] ),
dt << selectrows( r )
)
);
dt << DeleteRows;
现在越来越近了。 缩放图像(上面加载),确保它是灰度,并使用每个灰度像素从表中选择一个字母。 由于在索引计算中使用了 NRows(dt),因此已删除的行将被考虑在内。 变量指标保存数据表中行号(索引)的二维矩阵。 最后一行的矩阵魔法; dt:代码[]是一维矩阵,但由二维矩阵索引。 结果是查找代码的二维矩阵。
// prepare the image, size, grayscale, look up letters for pixels
{oldx, oldy} = image << getsize; // need the old size to make a scale factor for resizing
image << scale( (nlines * 1.3) / oldx, nlines / oldy ); // stretch horz because font stretches vert
{r, g, b} = image << getPixels( "rgb" ); // in case the image isn't gray scale
gray = .30 * r + .59 * g + .11 * b; // 0..1 gray scale with 0:black and 1:white
indexes = Round( 1 + (N Rows( dt ) - 1) * gray ); // get indexes into the data table (descending needed here!)
codes = dt:code[indexes]; // the heavy lifting is in this line: get the ascii codes (still numbers)
到此图像就完成了;它只需要显示。 这将创建一个使用显示框的 JMP 窗口,这些显示框被迫保持数据表计划使用的相同固定宽度字体。 您再次看到 blobToChar/MatrixToBlob 构造,但这次对代码矩阵的一行中的多个代码/字符进行操作。 r,0表示第 r 行的所有列。
// generate the displaybox tree
vl = V List Box( Button Box( url, Web( url ), <<UNDERLINESTYLE></UNDERLINESTYLE>
就是这样。