Saturday, March 26, 2022

The Matrix
A Programming Adventure
Movie Intro Clip

Call Trans opt: received.

The Matrix has been my favorite movie since the first time I viewed it.  I loved the movie so much that I visited the theater approximately eight times; I know what you're thinking. I just could not get enough of it.  The whole movie is fantastic from end-to-end.  On a side-note, I was saddened that other releases were not of the same qualifications.  Anyway, for the past few days I've been wanting to revisit the movie in order to look at the introduction and in turn try to emmulate the sequence.  The "Call trans opt: received." that introduces the movie is just a cool scene to see.

 I decided to give this a go.  I was motivated enough with a previous program I was working on which would display data on the console char-by-char at specific intervals of time.  I turned on my DVD player, threw in the movie and replayed the scene a few times to get a good understanding of how the tracer worked.  Once I was ready, I began to code along-side it.  I was glad I did.

Trace program: running

The scene is composed of Trinity speaking on the phone with Cipher.  As they converse the call is intercepted and a trace is begun.  As the camera comes in we see the trace program actually running.  A few numbers are shown as they run in random order and as the trace succeeds with each number, the trace program shortens; the trace continues until complete.  We don't completely see the trace program complete it's trace, but we know that a trace has occurred by the time the camera comes into full frame of the next scene.  A complete clip is found here:



My Version

Obviously, the guys at Warner Bros had quite a bit of resources at their disposal; so the tracer program is far more complex visually than my console version.  My version of the trace program is a bit shorter and finishes at the point where the trace is begun with random numbers running.  Additionally, the fontface and incredibly luminescent display is not recreated or the method which the numbers tumble (which is from top-to-bottom each line independent of the other).   I thought it would be best to emulate the intro and simply let the program run in a loop as somewhat of a screen-saver.

Implementation

The main idea behind the program is time.   And there is quite a fair amount of time intervals that are required to pass in order for all things to be displayed in certain order.  I divided the program into a few components after analysis of how I believed the movie version worked.  The division was in terms of the following:

  1. A block cursor of ASCII code 219
  2. Blinking of the cursor - using time
  3. Sequential 'visual' writing of characters - using time
  4. Randomization of numbers
  5. Pausing between events - using time
  6. Color - Matrix green

The very first thing we see within the scene of a blinking cursor using a block.  This is implemented as ASCII code 219 (block).  To emulate the blink itself is basically a process of showing the block, then removing the block.  This is done by showing the block, moving back to it's location, then replacing it with a white space, then moving back for the next iteration.  To allow this show/remove to be seen, we show it, wait a certain interval of time, remove it and wait another interval of time.  To allow it to blink a few times, I wrapped this into a loop with a 'pass' value.  In other words, if we want to see it blink 8 times, we specify 8 passes.  Here is the code:

void cursorblink(int pass){
 while(pass-- != 0){
  printf("%c\b", cursor);
  fflush(stdout);
  pause(400);
  printf("%c\b", ' ');
  fflush(stdout);
  pause(400);
 }
}

This type of activity happens quite frequently.  The next set of events occur with the writing of characters that occurs quickly but with a noticeable speed.  Additionally, we see the cursor also display while the characters are being written.  This is a cool detail.  To implement this behavior, it follows the same process as that of the blink where we move back and replace the block.  In this case, we replace it with a character but when we write the block, we always move one step ahead of the previously written character.  Here is the code:

void run(char type[]){
 int i = 0;
 while(type[i] != '\0'){
  printf("%c", cursor);
  fflush(stdout);
  pause(15);
  printf("\b%c", type[i]);
  fflush(stdout);
  pause(10);
  i++;
 }
 cursorblink(4);
}

The function here, receives a string (array) of characters, reads each character and while it hasn't reached the end, performs the slow writing between each character.

The final event is writing the random values to show some kind of trace being performed.   This particular area isn't following anything special and it's simply using rand() to show 10 columns of random values scrolling downward.  I also added a "trace complete" at the end.  

Saturday, March 19, 2022

Why Programming is ALMOST Impossible in 2022

It appears as though programming has become ubiquitous; to the point where there is very little that can be characterized of an individual within the process. These times, it is not essential but highly qualitative for no single individual be concerned with the details of the systems and software being built. Through this, the systems become complex, to the point where no specific individual can be pointed to for the beauty and elegance and equally the "greatness" of a system in development. 

 A single programmer may in process qualify his works as great, but not so in the face of the total contributions of other minds. In this there is no knowledge, but lack of it; as individuals, lacking knowledge, act merely in ignorance typically following the purposes of others. The only objective view that can be assessed is one where the individual simply adds small fragments of work which when quantified with the equally small fragments of others, a whole is achieved. However, costly and not particularly interesting in the end. 

 An evolution takes place within this "system" as the work is not important within a few, only when they are considerably added together. The reasoning that programming is almost impossible, is primarily because any significantly useful system requires a certain amount of user and programmer contributions, often lead by business requirements and day-to-day needs. And these needs and business driven behaviors must all mesh with each other seemlessly. 

 You cannot create another Operating System like the one humbly ignorant Linus built in the 80s, such a system would be considered "throw-away" as a general concensus would dictate the system too young to be useful, even if the core concepts and technology make it "better" in some sense from current ones. No one programmer can do what is needed of an OS, today. Such a programmer must undergo the process of themselves merely contributing a small portion of a system feature, remaining ignorant to the whole and whose addition is nothing of wonder or award.

Programming is ALMOST impossible in 2022.