Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

CMD Matrix effect (very simple!)

Finished making your own program (thats not part of the practicing forums) ? Show it off here

CMD Matrix effect (very simple!)

Postby wabe on Tue Oct 20, 2009 11:31 am

This is very simple example of matrix effect (lol). Tell me what do you think? I would like to see if somebody has done / can do this better?
As you can see this is not the most efficient peace of code :) I could not even get this work with a function.
It is possible to draw something there with white spaces " " and thats why i tried to remove those "bad characters" like . , ' - etc.
Dont get confused because of my comments. I am not sure if I commented it right.

It should compile fine with VC++ 2008 Express Edition.


Code: Select all
#include "stdafx.h"
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
   //green color for text
   system("color 0a");

   //random seed
   srand(time(0));

   char random_char = ((rand() % 127));
   bool going = true, checking = true;
   
   while (going = true)
   {
      //draw row of characters (38 characters)
      for (int x = 0; x < 38; x++)
      {
         //generate first char
         random_char = ((rand() % 127) + 50);
         checking = true;
         while (checking)
         {
            if  ( //check for:
               // Bad/Small characters.
                  (random_char == 32) || (random_char == 39) || (random_char == 46) ||
                  (random_char == 44) || (random_char == 34) || (random_char == 45) ||
                  (random_char == 58) || (random_char == 59) || (random_char == 94) ||
                  (random_char == 95) || (random_char == 96) || (random_char == 126)
               // If bad character is generated -> generate new random character and check if it is bad
                )
            random_char = ((rand() % 127) + 50);
            
            //Good character found -> Continue to print it
            else break;
         }
         //Print character + white space
         cout << random_char << " ";
      }
      //Full row of characters successfully printed -> continue for next row
      cout << endl;

      //Delay
      Sleep(20);
   }
   system("pause");
   return 0;
}
User avatar
wabe
 
Posts: 6
Joined: Sat Oct 17, 2009 2:35 pm
Location: Finland

Re: CMD Matrix effect (very simple!)

Postby glinka57 on Tue Oct 20, 2009 12:21 pm

very very nice, Ill make a version of it
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm

Re: CMD Matrix effect (very simple!)

Postby noobgrammer on Tue Oct 20, 2009 12:31 pm

here I wrote this in about a minute nothing pretty but a little closer to the look

its on a infinite loop so either control break or just close to stop it

Code: Select all
#include <ctime>
   
    #include <iostream>
    #include <windows.h>
int main()
{
   system("color 0a");
   srand((unsigned)time(0));

   char text;
   
   while(1)
   {
      text = rand() + 255;

      if (text < 20 || text == 33 )
         std::cout<< " ";
      else
      std::cout<< (char)text;
      Sleep(1);
   }
}


what was this for?
Code: Select all
//#include <cstdlib>
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: CMD Matrix effect (very simple!)

Postby glinka57 on Tue Oct 20, 2009 1:38 pm

Ok half hour later.

Code: Select all
#include "stdafx.h"
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;


char d[256];
bool going = true;
int X=0, Y=0;
int CurrentChar=64;
void gotoxy ( short x, short y )
{
  COORD coord = {x, y};
  SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}






int main()
{   
   system("color 0a"); //green color for text
   
   for(int x=0;x<255;x++)d[x]=x;

 
   srand(time(0));  //random seed

     
   while (going = true)
   {
      // 64-94
      
       Y=0;
      X=(rand() % 80);
        for (; Y < 24; Y++)
        {
         CurrentChar=(rand() % 30+94);
         gotoxy(X,Y);
          cout<< d[CurrentChar];
          Sleep(10);
          gotoxy(X,Y);
          cout<<" ";       
   
       }         
       
   }
   system("pause");
   return 0;
}
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm

Re: CMD Matrix effect (very simple!)

Postby wabe on Tue Oct 20, 2009 2:24 pm

Awesome! Nice job guys!
User avatar
wabe
 
Posts: 6
Joined: Sat Oct 17, 2009 2:35 pm
Location: Finland

Re: CMD Matrix effect (very simple!)

Postby noobgrammer on Tue Oct 20, 2009 3:20 pm

yours turned out better than mine glinka

I just came across something interesting with this program and that is I went back to my program I'm working on and when I went to run it and to my surprise all the text was still green.

I don't know if it is because its using the system call or because I have to break out of it so it doesn't close right :?

EDIT: what ever the hell happened it changed the properties in my command prompt properties now if I could figure out how that happen I would change other properties that I need that way
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: CMD Matrix effect (very simple!)

Postby Vevix on Tue Oct 20, 2009 4:23 pm

Using system isn't such a great idea for anything - use the method for color text i posted in the other thread.

glinka57:

Nice, but those variables should be locally declared not globally.
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup
User avatar
Vevix
 
Posts: 142
Joined: Sat Oct 10, 2009 9:24 pm
Location: kernel32.dll

Re: CMD Matrix effect (very simple!)

Postby thefreakk on Sun Nov 22, 2009 1:46 pm

nice code guys..
thefreakk
 
Posts: 6
Joined: Sun Nov 22, 2009 1:42 pm

Re: CMD Matrix effect (very simple!)

Postby elmasmalo1 on Sat Nov 28, 2009 12:09 am

Hey i just wanted to give u a reak nice style looking to your program and so decided to make a little nice cool icon and stick it up with ur program and they are so cool united :D :P well here it is it.

PS: i used LiquidIcon to draw icon, plus that program has feature to extract icons to :P, but the one i put in ur program i made it :) ehehee

http://www.virustotal.com/analisis/32ec ... 1259381434
Attachments
Matrix.rar
your program with my icon :) enjoy
(10.48 KiB) Downloaded 8 times
Image
Image
Image
G04L5:
[ ]LEARN C++!!!
[ ]start making hacks for online games
elmasmalo1
 
Posts: 5
Joined: Fri Nov 27, 2009 11:47 pm


Return to Full programs

Who is online

Users browsing this forum: No registered users and 0 guests