• Welcome to Dark Bit Factory & Gravity.
 

ASCII - Matrix

Started by Rbz, July 12, 2006

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rbz

Here's my first entry. Hope you like it  ;D

Use Dev-Cpp to compile it, executable attached.




/*
Ã,  Ã,  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:

Clyde

Welldone mate.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

That's a very authentic version :) Well done for posting the first devc entry!
Shockwave ^ Codigos
Challenge Trophies Won:

relsoft

There is no spoon.
:||
Challenge Trophies Won:

Rbz

Thanks, glad you liked it  :)
Challenge Trophies Won:

Ghost^BHT

Nice one rbraz :)

Tetra

Cool, i really like the matrixcode :) Nice 1 rbraz
Challenge Trophies Won: