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:
- A block cursor of ASCII code 219
- Blinking of the cursor - using time
- Sequential 'visual' writing of characters - using time
- Randomization of numbers
- Pausing between events - using time
- 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.
No comments:
Post a Comment