Author Topic: ASCII - Matrix  (Read 7524 times)

0 Members and 1 Guest are viewing this topic.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2748
  • Karma: 492
    • View Profile
    • http://www.rbraz.com/
ASCII - Matrix
« on: July 12, 2006 »
Here's my first entry. Hope you like it  ;D

Use Dev-Cpp to compile it, executable attached.



Code: [Select]
/*
  Â  ASCII Matrix
  Â  Code: Rbraz - 2006
*/

#include <stdio.h>
#include <conio.h>
#include <windows.h>

using namespace std;

//------------------------------------------------------------------------------

#define MAX_CODE 70
#define MAX_LENGTH 25
typedef struct {
  Â  int  Â x;
  Â  float y;
  Â  float speed;
  Â  int  Â length;
  Â  char  ch[MAX_LENGTH];
}
matrixcode;
matrixcode mtxcode[MAX_CODE];


float Random(float min, float max)
{
  return ((float)rand())/RAND_MAX * (max-min) + min;
}

void gotoxy(int x, int y)
{
  Â  HANDLE hConsoleOutput;
  Â  COORD dwCursorPosition;
  Â  dwCursorPosition.X = x;
  Â  dwCursorPosition.Y = y;
  Â  hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  Â  SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}

void textcolor (int color, int bgcolor)
{
  Â  static int __BACKGROUND = bgcolor;
  Â  static int __FOREGROUND = color;
  Â  
  Â  SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
  Â  color + (__BACKGROUND << 4));
}

void initconsole()
{
SetConsoleTitle("ASCII Matrix by Rbraz - Press Alt+Enter for FullScreen");

COORD wh = {80,50};
  Â  SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), wh);
  Â  
SMALL_RECT rect1={1,1,80,50};
  Â SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &rect1);
  Â
CONSOLE_CURSOR_INFO cursor = {10,FALSE};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor);Â  Â  
}

void plotchar(char *ch, int x, int y, int color, int bgcolor)
{Â  Â
  Â  if( ((x < 79) & (x > 1)) & ((y < 49) & (y > 1)) ) {
  Â  Â  Â  gotoxy(x, y);
  Â  Â  Â  textcolor(color,bgcolor);
  Â  Â  Â  printf(ch);
  Â  }
}

void initMatrix()
{
  Â  int i,j;
  Â  int length;
  Â  
  Â  for(i=0; i<MAX_CODE; i++) {
  Â  Â  Â  mtxcode[i].x = 1 + rand()%78;
  Â  Â  Â  mtxcode[i].y = (float)(1 + rand()%48);
  Â  Â  Â  mtxcode[i].speed = Random(0.4f, 1.0f);
  Â  Â  Â  
  Â  Â  Â  for(j=0; j<MAX_LENGTH; j++) mtxcode[i].ch[j] = 0;
  Â  Â  Â  
  Â  Â  Â  mtxcode[i].length = rand()%MAX_LENGTH;
  Â  Â  Â  
  Â  Â  Â  for(j=0; j<mtxcode[i].length; j++) {
  Â  Â  Â  Â  Â  mtxcode[i].ch[j] = 33 + rand()%222;
  Â  Â  Â  }
  Â  Â  Â  
  Â  }  
}

void plotMatrix()
{
  Â  int i,j;
  Â  char tmp[2];

  Â  for(i=0; i<2; i++) tmp[i] = 0;
  Â  
  Â  for(i=0; i<MAX_CODE; i++) {
  Â  Â  Â  
  Â  Â  Â  for(j=0; j<mtxcode[i].length+2; j++) {
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  tmp[0] = 33 + rand()%222;  Â //mtxcode[i].ch[j];
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  if(j >= mtxcode[i].length-1) {
  Â  Â  Â  Â  Â  Â  Â  plotchar(" ", mtxcode[i].x, (int)mtxcode[i].y, 0, 0);
  Â  Â  Â  Â  Â  Â  Â  plotchar(tmp, mtxcode[i].x, (int)mtxcode[i].y+j, 10, 0);
  Â  Â  Â  Â  Â  }
  Â  Â  Â  Â  Â  else {
  Â  Â  Â  Â  Â  Â  Â  plotchar(" ", mtxcode[i].x, (int)mtxcode[i].y, 0, 0);
  Â  Â  Â  Â  Â  Â  Â  plotchar(tmp, mtxcode[i].x, (int)mtxcode[i].y+j, 2, 0);
  Â  Â  Â  Â  Â  }
  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  
  Â  Â  Â  }
  Â  Â  Â  
  Â  Â  Â  mtxcode[i].y += mtxcode[i].speed;
  Â  Â  Â  
  Â  Â  Â  if(mtxcode[i].y > 49) {
  Â  Â  Â  Â  Â  mtxcode[i].x = 1 + rand()%78;
  Â  Â  Â  Â  Â  mtxcode[i].y = (float)-mtxcode[i].length;
  Â  Â  Â  Â  Â  mtxcode[i].speed = Random(0.4f, 1.0f);
  Â  Â  Â  }
  Â  Â  Â  Â  Â  
  Â  }
}

//------------------------------------------------------------------------------

int main(int argc, char *argv[])
{
  Â  int i;
  Â  
  Â  srand(GetTickCount());  Â
  Â  Â
  Â  initconsole();  Â  

  Â  initMatrix();
  Â  Â  Â
  Â  do
  Â  {  Â  Â
  Â  Â  Â  plotMatrix();
  Â  }
  Â  while (!kbhit());
}
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: ASCII - Matrix
« Reply #1 on: July 12, 2006 »
Welldone mate.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17390
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: ASCII - Matrix
« Reply #2 on: July 12, 2006 »
That's a very authentic version :) Well done for posting the first devc entry!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: ASCII - Matrix
« Reply #3 on: July 12, 2006 »
There is no spoon.
 :||
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2748
  • Karma: 492
    • View Profile
    • http://www.rbraz.com/
Re: ASCII - Matrix
« Reply #4 on: July 12, 2006 »
Thanks, glad you liked it  :)
Challenge Trophies Won:

Offline Ghost^BHT

  • Clueless and Happy
  • ^GVY
  • Pentium
  • ******
  • Posts: 931
  • Karma: 49
  • BYTE ME!
    • View Profile
Re: ASCII - Matrix
« Reply #5 on: July 12, 2006 »
Nice one rbraz :)

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: ASCII - Matrix
« Reply #6 on: July 12, 2006 »
Cool, i really like the matrixcode :) Nice 1 rbraz
Challenge Trophies Won: