Function Repository Resource:

 TextToKaleidoscope

Source Notebook

Create a square-symmetric image from a long string of text

Contributed by: Daniel Lichtblau

ResourceFunction["TextToKaleidoscope"][str]

converts the string str into a square image with rotational and reflectional symmetries.

ResourceFunction["TextToKaleidoscope"][str,level]

converts the string str into a square image of dimensions 2level×2level.

Details and Options

ResourceFunction["TextToKaleidoscope"] uses an encoding of text characters to generate an image.
Characters become five-digit numbers in base 2, with the first two determining where to increment a pixel value (via the "Frequency Chaos Game Representation") and the last three encoding the color channels to be updated.
The dimension exponent must be a whole number in the range 2–10, and the default value is 7.
Setting Symmetrized→False gives an image without rotational and reflectional symmetries.
ColorScheme can be set to an integer to seed the random generator, Automatic (so a random seed will be selected automatically) or any of prebuilt schemes "K1", "K2", …, "K9".

Examples

Basic Examples (1) 

Create an image from a modern English version of Beowulf:

In[1]:=
texB = ExampleData[{"Text", "BeowulfModern"}];
ResourceFunction["TextToKaleidoscope"][texB]
Out[2]=

Scope (2) 

Here are the prebuilt color schemes, as applied to Alice in Wonderland:

In[3]:=
texA = ExampleData[{"Text", "AliceInWonderland"}];
schemes = Map["K" ~~ ToString[#] &, Range[9]];
GraphicsGrid[
 Partition[
  Table[ResourceFunction["TextToKaleidoscope"][texA, 5, ColorScheme -> s], {s, schemes}], 3]]
Out[5]=

A similar but more detailed set of images is shown at pixelation level 9:

In[6]:=
GraphicsGrid[
 Partition[
  Table[ResourceFunction["TextToKaleidoscope"][texA, 9, ColorScheme -> s], {s, schemes}], 3]]
Out[6]=

Options (3) 

Here is an unsymmetrized image computed from Beowulf:

In[7]:=
ResourceFunction["TextToKaleidoscope"][texB, 8, Symmetrized -> False]
Out[7]=

TextToKaleidoscope will automatically create a random color scheme if so desired:

In[8]:=
ResourceFunction["TextToKaleidoscope"][texA, 9, ColorScheme -> Automatic]
Out[8]=

TextToKaleidoscope does not change the internal state of the random generators, so repeating the above results in the same image:

In[9]:=
ResourceFunction["TextToKaleidoscope"][texA, 9, ColorScheme -> Automatic]
Out[9]=

Explicitly change the internal random state to get a new randomized color scheme:

In[10]:=
RandomInteger[10^6];
ResourceFunction["TextToKaleidoscope"][texA, 9, ColorScheme -> Automatic]
Out[11]=

Possible Issues (3) 

By default, TextToKaleidoscope will produce very dark images if given a short text:

In[12]:=
ResourceFunction[
 "TextToKaleidoscope"]["Now is the time for all good seasons of our discontent to gather round the campfire and roast celebrities by the marsh meadows (or words to that effect)"]
Out[12]=

Using a lower pixelation value for short text can produce brighter images:

In[13]:=
ResourceFunction[
 "TextToKaleidoscope"]["Now is the time for all good seasons of our discontent to gather round the campfire and roast celebrities by the marsh meadows (or words to that effect)", 3]
Out[13]=

Images can be lightened explicitly using Lighter:

In[14]:=
Lighter[ResourceFunction["TextToKaleidoscope"][
  "Sometimes I live in the country, sometimes I live in the town, and sometimes I take a great notion, to jump in the river and drown (from 'Goodnight Irene' by Huddie Ledbetter)", 4], .9]
Out[14]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 13 February 2019

Source Metadata

License Information