Turning images into ASCII art

calendar_today

24.06.2022

label

VEX, Rendering

mouse

Houdini 19.0

Description

Various methods to convert images into a grid of letters.

1 Image to text console

After applying an image to a grid of rows using attribute from map, we loop through each line point by point to convert the luminance to a set of characters with increasing visual density:
. : - = + * # % @. Then we print it to the console using \n for line breaks and optionally disable the commenting for reverse(chars) to invert the image.

CPP
        string chars[] = array(' ','.',':','-','=','+','*','#','%','@');
//chars = reverse(chars);
int prims[] = expandprimgroup(0, '*');
foreach(int pr; prims){
    int pts[] = primpoints(0, pr);
    foreach(int pt; pts){
        float a = point(0, 'a', pt);
        int index = int(a * 9);
        printf('%g', chars[index]);
    }
    printf('\n');
}
printf('\n');
    

2 Image to SOP fonts

Transforming image brightness into characters by using the variant attribute on the copy to points-node.

Centering letters on top of each other before copying is done by index with VEX:

C
        int index = prim(0, 'textindex', i@primnum);
string grp = '@textindex==' + itoa(index);
vector center = getbbox_center(0, grp);

v@P.x -= center.x;
    

3 Raycasted meshes attributes to text in 2D volumes

Raycasting mesh attributes and adding depth blur into a 2D volume.

Posterized colors values val are turned into text indices by counting the number of unique indices nuniqueval from the font SOP on second input.

C
        string a = chs('attribute');
float val = point(0, a, i@ptnum);
int num = nuniqueval(1, 'prim', 'textindex');
i@textindex = int(val * (num - 1));
    

The blur mask is created based on the remapped distance gathered from the Ray node.

download

Downloads

smart_display

Videos

ASCII 3D Art – Houdini Tutorial

link

Related articles

favorite

416

label

VEX

Attribute to match across inputs

favorite

13

label

VEX

Curves from Ramp Parameters

favorite

309

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

327

label

VEX

Deintersecting spheres with Voronoi

favorite

366

label

VEX

Fitting Planes to Point Clouds

favorite

360

label

VEX

How to Analyze VEX Code