Having Fun with AsciiCam in Wolfram Language!

Inspired on this site I tried to create a Wolfram Language version of an asciicam.

It’s cool to see how compact is the code!

char=CharacterRange[" ","~"]~Join~Map[Style[#,Bold]&,CharacterRange[" ","~"]];
w=N@Mean@Flatten@ImageData@Binarize@Rasterize@#->#&/@char;
w[[All,1]]=#~Rescale~{Min[#],Max[#]}&@w[[All,1]];
findChar=Nearest[w];

asciiIt[image_]:=Module[{img},
	img=ImageAdjust@ColorConvert[image,"Grayscale"];
	img=ImageData@ImageResize[img,80];
	img=Map[First@findChar[#,1]&,img,{-1}];
	Grid[img,Spacings->{0.1,-0.2},ItemSize->{0.4,0.4}]
]

Dynamic[asciiIt@CurrentImage[]]

So we get:

AsciiArt_WolframLanguage.gif

20 Likes

And fun this is! - thanks for sharing. Did I get this correctly - you showing a page of paper where you wrote WL to the camera?

3 Likes

Hi @Vitaliy! Cool that you liked It.
Yes, I wrote WL in a page of paper.

1 Like

Rodrigo, that’s really cool! Thanks for sharing :slight_smile:
I added color, first with ColorNegate@image and then using ImageSubtract:

 char=CharacterRange[" ","~"]~Join~Map[Style[#,Bold]&,CharacterRange[" ","~"]];
 w=N@Mean@Flatten@ImageData@Binarize@Rasterize@#->#&/@char;
 w[[All,1]]=#~Rescale~{Min[#],Max[#]}&@w[[All,1]];
 findChar=Nearest[w];
 
 asciiIt[image_]:=Module[{img},
     img=ImageAdjust@ColorConvert[ColorNegate@image,"Grayscale"];
     img=ImageData@ImageResize[img,50];
     img=Map[First@findChar[#,1]&,img,{-1}];
    Grid[img,Spacings->{0.2,-0.2},ItemSize->{0.4,0.4}]
]

width=ImageDimensions[Rasterize[asciiIt@CurrentImage[]]][[1]];
Dynamic[ImageSubtract[ImageResize[CurrentImage[], width], Rasterize[asciiIt@CurrentImage[]]]]

cam.gif

Spacings->{0.2,-0.2} gives you the right AspectRatio.

8 Likes

@Bernard very cool!.. Using green scale in your code we have a beautiful Matrix effect:

ImageSubtract[ImageResize[ImageMultiply[CurrentImage[], Green], 450],Rasterize[asciiIt@CurrentImage[]]]

3 Likes

Nice! :wink:
Matrixcam.gif

7 Likes

Recreating Neo in Wolfram Language, cool!.. @Bernart, do you have a user in StackExchange? I posted you gif image there, in the chat room.

1 Like

@Rodrigo here is my user Geonat. Let’s increase my low-level reputation with this new look. :wink:

2 Likes