jsgoller1 / sprawl

2D Game Engine
GNU General Public License v3.0
0 stars 0 forks source link

Create Matrix-text picture converter #60

Open jsgoller1 opened 1 year ago

jsgoller1 commented 1 year ago

Here's a fun effect. This image is an N-by-M grid of 1s and 0s, each with shades of green: Digital Portrait

To create this, we can do the following:

  1. Select a source image to convert.
  2. Create "grid image"; this is an N-by-M grid of randomly selected 1s and 0s such that the grid image dimensions are equal to those of the source image.
  3. Select k-many shades of green g_1, g_2, ..., g_k ordered from darkest to lightest. (k = 3 or 4 in the above),
  4. Convert the source image to greyscale.
  5. Pick k values between 0x00 (black) and 0xff (white) called c_1, c_2, ..., c_k ordered from darkest to lightest, and each c_i to g_i.
  6. Go pixel by pixel through both the grid image and the source image simultaneously.
  7. If the pixel falls outside a 1 or 0, set it to black in the grid image.
  8. Else, examine the color of the pixel in the source image, called c_sp. Select the maximum c_i value less than c_sp. Set the pixel in the snapshot to g_i.

Note that we could create a GIF with "matrix style text animation" by creating N-many grid images, each with the grid rotated downwards once (then doing the above procedure on each and combining the resulting images into a GIF).