VB icon

Matrix Graphic

Email
Submitted on: 1/4/2015 11:14:00 PM
By: Justin P (from psc cd)  
Level: Intermediate
User Rating: By 2 Users
Compatibility: C++ (general)
Views: 450
 
     This code is made to mimic the graphic effect seen on the move "The Matrix". I was wondering if anyone could tell me if they knew of a way which I could display the text in 256 or more colors while still writing to memory. Using the old 16 colors doesn't allow for a very interesting effect.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Matrix Graphic
//**************************************
stdio.h, stdlib.h, conio.h, string.h, and dos.h
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Matrix Graphic
// Description:This code is made to mimic the graphic effect seen on the move "The Matrix". 
I was wondering if anyone could tell me if they knew of a way which I could display the text in 256 or more colors while still writing to memory. Using the old 16 colors doesn't allow for a very interesting effect.
// By: Justin P (from psc cd)
//
// Assumes:Only that you can use pointers to write to memory instead using cprintf();.
//**************************************

/* "Matrix Program" developed to mimic the effect seen on the motion picture, "The Matrix"
 Justin Potter 01/31/03 */
#include <dos.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#define MAXY 50/* Screen height */
#define MAXX 80/* Screen width*/
#define NUMBER 80 /* Amount of strings there are*/
#define DELAY 0/* Delay variable */
#define LENGTH 500
typedef struct
	 {
	 int x;
	 int y;
	 int len;
	 char text[LENGTH];
	 int type;
	 }PLNE;
PLNE master[NUMBER];
int loop;/*Temporary place holderused for loops */
int length,current;
int far *farptr;
int memx, memy;
union REGS regs;
void init(int num)/*Sets up the array for the inputed number */
 {
 int proloop; /*Procedure loop */
 master[num].type=random(2);/* Sets color to either white */
 if(master[num].type==0)master[num].type=2;/* or greeen */
 else master[num].type=15;/**/
 master[num].x=random(MAXX-3)+1;/* Generates random x */
 master[num].y=random(MAXY-3)+1;/* and y cords*/
 master[num].len=random(LENGTH-5)+5;
 for(proloop=0;proloop<=master[num].len;proloop++)master[num].text[proloop]=(random(36))+65;
 }
void move(int num)/* Moves the array of the inputed number down one */
 {
 master[num].y++;
 if(master[num].y>MAXY+master[num].len)init(num);
 }
void write(int num,int color, int start, int end,int clear)/* Writes the inputed string in the inputed */
 { 				/* color for the inputed length */
 int tempy; //Tempy used as a temp counter
 farptr=(int far *) 0xB8000000; /*Sets pointer to write to memory, faster then cprintf();*/
 for(tempy=start;tempy<=end;tempy++)/*Writes all text that start-end allows*/
{
if(master[num].y-tempy>0&&master[num].y-tempy<MAXY) /*Only writes if on the screen*/
{
memx=(master[num].x)-1; /* These convert X&Y cords to the correct place */
memy=((master[num].y-tempy)-1)*80;/* in memory*/
if(color==2) *(farptr+memx+memy) = master[num].text[tempy] | 0x0220; /* The 0x0220 is hex decimal, turns text green */
else *(farptr+memx+memy) = master[num].text[tempy] | 0x0720; /* The hex decimal turns text white */
}
}
 if(clear==1)
{
memx=(master[num].x)-1;
memy=((master[num].y-tempy)-1)*80;
*(farptr+memx+memy) = 0x0720;
}
 }
main(void)
 {
 clrscr(); 			/* Prep of*/
 textmode(C4350);			/* screen and */
 randomize();/* textmode*/
 for(loop=0;loop<=NUMBER-1;loop++)init(loop);
 while (!kbhit())
{
current=random(NUMBER);
write(current,master[current].type,0,0,0); /*Writes first letter of the text, done to write white letters*/
write(current,2,1,(master[current].len),1);/*Writes the remaining string and "clears" the screen behind the string*/
move(current);
delay(DELAY);
}
 return 0;
 }


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.