Assignment 4

For this assignment, I wanted to recreate the Matrix movie’s Neo sees the matrix for the first time in the scene, in which we see everything in green from Neo’s perspective.

I wanted to create the scene using the transcript of the movie itself. So, I quickly downloaded the transcript from open source. While looking for any tutorials online, I found Daniel Shiffman’s tutorial on creating images with ASCII text. I followed this tutorial only to complete the assignment. Following the tutorial, I started with creating the still image attached to this post with the movie transcript. I quickly realized that due to the presence of unwanted characters (numbers, :, etc.),  the visualization was not looking great. I decided to clean up the transcript according to my needs. I used p5.js to remove any unwanted characters from the data. However, following the tutorial, I could not replicate the brightness using empty/smaller ASCII text, as I was using sentences to create the visualization. So, I decided to manipulate the brightness of the text itself, and it worked. However, moving into the video loop, the code was not working smoothly. I realized that as I was using a large string (3300 lines), the array became too big to loop and refresh in the draw loop. I had to cut down the data to the first 70 lines of the transcript to accommodate that.

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// draw function
function draw() {
background(0); // setting background as black
let charIndex = startIndex;
// calculating the width and height of the cells
let w = width / capture.width;
let h = height / capture.height;
// load the pixels of the webcam capture
capture.loadPixels();
// loops to iterate over each pixel of the webcam capture
for (let j = 0; j < capture.height; j++) {
for (let i = 0; i < capture.width; i++) {
// calculate the pixel index
const pixelIndex = (i + j * capture.width) * 4;
// rgb component of the pixel
const r = capture.pixels[pixelIndex + 0];
const g = capture.pixels[pixelIndex + 1];
const b = capture.pixels[pixelIndex + 2];
// calculating brightness
const brightness = (r + g + b) / 3;
// Adjust the fill color based on brightness
// map brightness to green color range
let fillColor = map(brightness, 225, 0, 225, -150);
fill(0, fillColor, 0);
textSize(w * 1.3);
textAlign(CENTER, CENTER);
// retrieve a character from the matrixText string based on charIndex
let textChar = matrixText.join('').charAt(charIndex % matrixText.join('').length);
if (random(1) < 0.05) {
textChar = matrixText.join('').charAt(floor(random(matrixText.join('').length)));
}
text(textChar, i * w + w / 2, j * h + h / 2);
charIndex += rainSpeed;
}
}
}
// draw function function draw() { background(0); // setting background as black let charIndex = startIndex; // calculating the width and height of the cells let w = width / capture.width; let h = height / capture.height; // load the pixels of the webcam capture capture.loadPixels(); // loops to iterate over each pixel of the webcam capture for (let j = 0; j < capture.height; j++) { for (let i = 0; i < capture.width; i++) { // calculate the pixel index const pixelIndex = (i + j * capture.width) * 4; // rgb component of the pixel const r = capture.pixels[pixelIndex + 0]; const g = capture.pixels[pixelIndex + 1]; const b = capture.pixels[pixelIndex + 2]; // calculating brightness const brightness = (r + g + b) / 3; // Adjust the fill color based on brightness // map brightness to green color range let fillColor = map(brightness, 225, 0, 225, -150); fill(0, fillColor, 0); textSize(w * 1.3); textAlign(CENTER, CENTER); // retrieve a character from the matrixText string based on charIndex let textChar = matrixText.join('').charAt(charIndex % matrixText.join('').length); if (random(1) < 0.05) { textChar = matrixText.join('').charAt(floor(random(matrixText.join('').length))); } text(textChar, i * w + w / 2, j * h + h / 2); charIndex += rainSpeed; } } }
// draw function
function draw() {
  background(0); // setting background as black

  let charIndex = startIndex;
  // calculating the width and height of the cells
  let w = width / capture.width; 
  let h = height / capture.height;

  // load the pixels of the webcam capture
  capture.loadPixels();
  
  // loops to iterate over each pixel of the webcam capture
  for (let j = 0; j < capture.height; j++) {
    for (let i = 0; i < capture.width; i++) {
      // calculate the pixel index
      const pixelIndex = (i + j * capture.width) * 4;
      // rgb component of the pixel
      const r = capture.pixels[pixelIndex + 0];
      const g = capture.pixels[pixelIndex + 1];
      const b = capture.pixels[pixelIndex + 2];
      
      // calculating brightness 
      const brightness = (r + g + b) / 3;
      
      // Adjust the fill color based on brightness
      // map brightness to green color range
      let fillColor = map(brightness, 225, 0, 225, -150);
      fill(0, fillColor, 0);
      
      textSize(w * 1.3);
      textAlign(CENTER, CENTER);
      
      // retrieve a character from the matrixText string based on charIndex
      let textChar = matrixText.join('').charAt(charIndex % matrixText.join('').length);
      if (random(1) < 0.05) {
        textChar = matrixText.join('').charAt(floor(random(matrixText.join('').length)));
      }
      text(textChar, i * w + w / 2, j * h + h / 2);
      charIndex += rainSpeed;
    }
  }
}

 

I still could not replicate the rain sequence in the visuals as expected. I hope to improve that in the future.

 

Leave a Reply