Código Matrix By: Vector¹
+5
schnaidinha
coldlinkim
Setimuss
isaiasrj
Vector
9 participantes
Umbrella System :: Programação :: C/C#/C++ :: Tutoriais
Página 1 de 1
Código Matrix By: Vector¹
Bom Pessoal estive um pouco fora do forum pois criando esse codigo.
Bom o codigo que eu criei é o CODGIO MATRIX pra quem n sabe oque é olha o Print do Programa.
Bom vamos lah...
Adicione:
(a) 2 arquivos .H
(b) 3 arquivos .CPP
Renomeie:
OBS: Não Coloque ".h" ou ".cpp" isso foi só para mostrar como fica!
(a.1) Matrix.h
(a.2) TextControl.h
(b.1) Matrix.cpp
(b.2) TextControl.cpp
(b.3) main.cpp
Código MATRIX.H :
Código TEXTCONTROL.H :
Código MATRIX.CPP:
Código TEXTCONTROL.CPP:
Código MAIN.CPP:
Bom Pessoal é isso, o Resultado final é esse:
Video em HD:
Caso de erro ao tentar ver o vídeo aqui:
Para Assistir o Video Click em Ver no Youtubr ou click na tela preta pra ser levado ao Video!
Link Do Post Novo: (Click Aqui)Código Matrix By: Vector²
Bom o codigo que eu criei é o CODGIO MATRIX pra quem n sabe oque é olha o Print do Programa.
Bom vamos lah...
Adicione:
(a) 2 arquivos .H
(b) 3 arquivos .CPP
Renomeie:
OBS: Não Coloque ".h" ou ".cpp" isso foi só para mostrar como fica!
(a.1) Matrix.h
(a.2) TextControl.h
(b.1) Matrix.cpp
(b.2) TextControl.cpp
(b.3) main.cpp
Código MATRIX.H :
- Spoiler:
- Código:
//bY:H4CK3R C4BR
#pragma once
#include <time.h>
#include <process.h>
#include <iostream>
#include "TextControl.h"
class Matrix {
private:
bool isDefault_; // Flag to signal using default "0 to 80" width, and "0 to 25" height
bool erase_; // Flag to signal erasing of text (black matrix lines)
// Timers for each color (no alternative)
unsigned __int32 loopWhite_;
unsigned __int32 loopLgreen_;
unsigned __int32 loopDgreen_;
unsigned __int16 speed_[3]; // Delay between printing a new line
unsigned __int8 length_; // Max. length before it quits
unsigned __int8 lenCnt_; // Counter for length
COORD position_; // Position on the console
SMALL_RECT matrixBox_; // Box for the "Matrix" to be in
public:
Matrix::Matrix();
Matrix::Matrix(const SMALL_RECT);
Matrix::Matrix(const unsigned __int8, const unsigned __int8, const unsigned __int8, const unsigned __int8);
void display();
void setErase(const bool);
bool getErase();
void setSpeed(const unsigned __int16, const unsigned __int16, const unsigned __int16);
unsigned __int16 getSpeed(const unsigned __int8);
private:
void randLength();
void randSpeed();
void randPos();
void setDefault(const bool);
bool getDefault();
void setLength(const unsigned __int8);
unsigned __int8 getLength();
void setPosition(const COORD);
void setPosition(const unsigned __int8, const unsigned __int8);
COORD getPosition();
void setMatrixBox(const SMALL_RECT);
void setMatrixBox(const unsigned __int8, const unsigned __int8, const unsigned __int8, const unsigned __int8);
SMALL_RECT getMatrixBox();
};
Código TEXTCONTROL.H :
- Spoiler:
- Código:
//By:H4CK3R C4BR
#pragma once
#include <windows.h>
enum COLORS {
BLACK = 0,
DARK_BLUE = 1,
DARK_GREEN = 2,
TEAL = 3,
DARK_RED = 4,
DARK_PURPLE = 5,
GOLD = 6,
GREY = 7,
DARK_WHITE = 8,
BLUE = 9,
GREEN = 10,
CYAN = 11,
RED = 12,
PURPLE = 13,
YELLOW = 14,
WHITE = 15
};
void RemoveCursor();
void SetColor(const int);
void PlaceCursor(const int, const int);
Código MATRIX.CPP:
- Spoiler:
- Código:
//By:H4CK3R C4BR
#include "Matrix.h"
using std::cout;
Matrix::Matrix() {
// The initial seed value of the object
srand(static_cast<unsigned int>(getpid()) ^ static_cast<unsigned int>(clock()) ^ static_cast<unsigned int>(time(NULL)));
// Default constructor (no arguments)
setDefault(true);
// Default state for 'matrix lines'
setErase(false);
// 80 wide, 25 tall
setPosition((rand() % 80 + 0), (rand() % 22 + 0));
// Based on position Y
setLength((rand() % (getPosition().Y + 1) + 0));
// Speed of each letter being displayed
setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));
// Time between each iteration of a new color
loopWhite_ = GetTickCount();
loopLgreen_ = GetTickCount();
loopDgreen_ = GetTickCount();
lenCnt_ = 0;
};
Matrix::Matrix(const SMALL_RECT box) {
// The initial seed value of the object
srand(static_cast<unsigned int>(getpid()) ^ static_cast<unsigned int>(clock()) ^ static_cast<unsigned int>(time(NULL)));
// Copy the argument to class member attribute
setMatrixBox(box);
// Default constructor (no arguments)
setDefault(false);
// Default state for 'matrix lines'
setErase(false);
// 80 wide, 25 tall
setPosition((rand() % getMatrixBox().Right + getMatrixBox().Left), (rand() % getMatrixBox().Bottom + getMatrixBox().Top));
// Based on position Y
setLength((rand() % (getPosition().Y + 1) + 0));
// Speed of each letter being displayed
setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));
// Time between each iteration of a new color
loopWhite_ = GetTickCount();
loopLgreen_ = GetTickCount();
loopDgreen_ = GetTickCount();
lenCnt_ = 0;
};
Matrix::Matrix(const unsigned __int8 left, const unsigned __int8 top,
const unsigned __int8 bottom, const unsigned __int8 right) {
// The initial seed value of the object
srand(static_cast<unsigned int>(getpid()) ^ static_cast<unsigned int>(clock()) ^ static_cast<unsigned int>(time(NULL)));
// Copy the argument to class member attribute
setMatrixBox(top, bottom, left, right);
// Default constructor (no arguments)
setDefault(false);
// Default state for 'matrix lines'
setErase(false);
// 80 wide, 25 tall
setPosition((rand() % getMatrixBox().Right + getMatrixBox().Left), (rand() % getMatrixBox().Bottom + getMatrixBox().Top));
// Based on position Y
setLength((rand() % (getPosition().Y + 1) + 0));
// Speed of each letter being displayed
setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));
// Time between each iteration of a new color
loopWhite_ = GetTickCount();
loopLgreen_ = GetTickCount();
loopDgreen_ = GetTickCount();
lenCnt_ = 0;
};
void Matrix::randLength() {
setLength((rand() % (getPosition().Y + 1) + 5));
}
void Matrix::randSpeed() {
setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));
//setSpeed(0);
}
void Matrix::randPos() {
if (getDefault()) {
setPosition((rand() % 80 + 0), (rand() % 22 + 0));
} else {
setPosition((rand() % getMatrixBox().Right + getMatrixBox().Left),
(rand() % getMatrixBox().Bottom + getMatrixBox().Top));
}
}
void Matrix::display() {
unsigned int whiteDelay = getSpeed(0);
unsigned int greenDelay = getSpeed(1);
unsigned int darkGreenDelay = getSpeed(2);
if (GetTickCount() >= (loopWhite_ + whiteDelay)) {
loopWhite_ = GetTickCount();
PlaceCursor(getPosition().X, getPosition().Y);
if (!getErase()) { SetColor(WHITE); }
else { SetColor(BLACK); }
cout << (char)(rand() % 121 + 34);
if (GetTickCount() >= (loopLgreen_ + greenDelay)) {
loopLgreen_ = GetTickCount();
PlaceCursor(getPosition().X, getPosition().Y);
if (!getErase()) { SetColor(GREEN); }
else { SetColor(BLACK); }
cout << (char)(rand() % 121 + 34);
if (GetTickCount() >= (loopDgreen_ + darkGreenDelay)) {
loopDgreen_ = GetTickCount();
PlaceCursor(getPosition().X, getPosition().Y);
if (rand() % 2) {
if (!getErase()) { SetColor(DARK_GREEN); }
else { SetColor(BLACK); }
}
cout << (char)(rand() % 121 + 34);
// Move the cursor down by one
setPosition(getPosition().X, (getPosition().Y + 1));
if (lenCnt_ >= getLength()) {
randPos();
randSpeed();
randLength();
lenCnt_ = 0; // reset counter
} else { lenCnt_++; }
}
}
}
return;
}
void Matrix::setDefault(const bool setting) {
isDefault_ = setting;
}
bool Matrix::getDefault() {
return isDefault_;
}
void Matrix::setErase(const bool setting) {
erase_ = setting;
}
bool Matrix::getErase() {
return erase_;
}
void Matrix::setSpeed(const unsigned __int16 white, const unsigned __int16 light_green, const unsigned __int16 dark_green) {
speed_[0] = white;
speed_[1] = light_green;
speed_[2] = dark_green;
}
unsigned __int16 Matrix::getSpeed(const unsigned __int8 color) {
return speed_[color];
}
void Matrix::setLength(const unsigned __int8 length) {
length_ = length;
}
unsigned __int8 Matrix::getLength() {
return length_;
}
void Matrix::setPosition(const COORD position) {
position_.X = position.X;
position_.Y = position.Y;
}
void Matrix::setPosition(const unsigned __int8 X, const unsigned __int8 Y) {
position_.X = X;
position_.Y = Y;
}
COORD Matrix::getPosition() {
return position_;
}
void Matrix::setMatrixBox(const SMALL_RECT matrixBox) {
matrixBox_.Top = matrixBox.Top;
matrixBox_.Bottom = matrixBox.Bottom;
matrixBox_.Left = matrixBox.Left;
matrixBox_.Right = matrixBox.Right;
}
void Matrix::setMatrixBox(const unsigned __int8 top, const unsigned __int8 bottom,
const unsigned __int8 left, const unsigned __int8 right) {
matrixBox_.Top = top;
matrixBox_.Bottom = bottom;
matrixBox_.Left = left;
matrixBox_.Right = right;
}
SMALL_RECT Matrix::getMatrixBox() {
return matrixBox_;
}
Código TEXTCONTROL.CPP:
- Spoiler:
- Código:
//By:H4CK3R C4BR
#include "TextControl.h"
void RemoveCursor() {
/* Remove the cursor (does not work in full screen) */
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursoInfo;
CursoInfo.dwSize = 1; /* The size of caret */
CursoInfo.bVisible = false; /* Caret is visible? */
SetConsoleCursorInfo(hConsole, &CursoInfo);
return;
}
void SetColor(const int foreground) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, foreground);
return;
}
void PlaceCursor(const int x, const int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD PlaceCursorHere;
PlaceCursorHere.X = x;
PlaceCursorHere.Y = y;
SetConsoleCursorPosition(hConsole, PlaceCursorHere);
return;
}
Código MAIN.CPP:
- Spoiler:
- Código:
//By:H4CK3R C4BR
#include <iostream>
#include <vector>
#include "Matrix.h"
int main() {
RemoveCursor();
// Set the console title and double the consoles height
#if (_WIN32_WINNT == _WIN32_WINNT_WINXP)
if (!SetConsoleTitle("Matrix - Win32 Console")) {
std::cout << "SetConsoleTitle returned an error: " << GetLastError();
}
SMALL_RECT windowSize = { 0, 0, 79, 49 };
if (!SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &windowSize)) {
std::cout << "SetConsoleWindowInfo returned an error: " << GetLastError();
}
#else
// Windows Vista/7 have disabled FULL SCREEN
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
#endif
std::vector<Matrix>matrix;
/*
matrix.push_back(Matrix(0, 0, 5, 15));
matrix.push_back(Matrix(65, 0, 5, 15));
matrix.push_back(Matrix(0, 0, 5, 15));
matrix.push_back(Matrix(65, 0, 5, 15));
matrix.push_back(Matrix(0, 0, 5, 15)); matrix.back().setErase(true);
matrix.push_back(Matrix(65, 0, 5, 15)); matrix.back().setErase(true);
matrix.push_back(Matrix(0, 0, 5, 15)); matrix.back().setErase(true);
matrix.push_back(Matrix(65, 0, 5, 15)); matrix.back().setErase(true);
*/
for (int y = 0; y < 15; y++) {
matrix.push_back(Matrix());
}
for (int z = 0; z < 5; z++) {
matrix.push_back(Matrix()); matrix.at(z).setErase(true);
}
while (1) {
Sleep(1);
for (int x = 0; x < matrix.size(); x++) {
matrix.at(x).display();
}
}
return 0;
}
Bom Pessoal é isso, o Resultado final é esse:
Video em HD:
Caso de erro ao tentar ver o vídeo aqui:
Para Assistir o Video Click em Ver no Youtubr ou click na tela preta pra ser levado ao Video!
Link Do Post Novo: (Click Aqui)Código Matrix By: Vector²
Última edição por Vector em Sáb maio 12, 2012 10:37 pm, editado 1 vez(es)
Re: Código Matrix By: Vector¹
Muito bom ta de parabéns isso serve para os iniciantes que nao sabe nada estuda essa parada e aprende facio programação e so dominar as variaveis strings float boolean etc assim chega longe haha
isaiasrj- Membro
- Mensagens : 8
Agradecido : 0
Data de inscrição : 22/01/2012
Re: Código Matrix By: Vector¹
pow... cara muito legal!bem simples e um visual bem arrojado...
poderia postar um video ou uma explicação mais detalhada de como
fazer??
poderia postar um video ou uma explicação mais detalhada de como
fazer??
Setimuss- Membro
- Mensagens : 1
Agradecido : 0
Data de inscrição : 13/04/2012
Re: Código Matrix By: Vector¹
mano essa pra qual linguagem c ow c++,, e outra pq esses spoiller e pq varios deles com os codigos
?????
?????
coldlinkim- Membro
- Mensagens : 3
Agradecido : 0
Data de inscrição : 26/04/2012
Re: Código Matrix By: Vector¹
coldlinkim não entendi oq vc quis disser?
schnaidinha- Membro
- Mensagens : 103
Agradecido : 8
Data de inscrição : 05/02/2012
Localização : No PC...
Re: Código Matrix By: Vector¹
mano é q eu uso Dev-c++ e num intendi o q vc fez pq diviu os códigos em varios lá em cima?ficou loko e tal o código mas queria fazer isso no progama q tenho e num intendi esses spoiler.
coldlinkim- Membro
- Mensagens : 3
Agradecido : 0
Data de inscrição : 26/04/2012
Re: Código Matrix By: Vector¹
Arquivos .h quero dizer Header Files(.h)
Arquivos .cpp quero dizer CPP Files(.cpp)
Eu Usei o Microsoft Visual C++ Professional Edition,mas tem o Express Edition tbem, nunca usei o Dev C++.
Arquivos .cpp quero dizer CPP Files(.cpp)
Eu Usei o Microsoft Visual C++ Professional Edition,mas tem o Express Edition tbem, nunca usei o Dev C++.
Re: Código Matrix By: Vector¹
parceiro, tentei compilar o codigo que vc passou, tentei compilar o main.cpp! mas ta dando erro nessa linha:
- Código:
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
gabrielloren- Membro
- Mensagens : 1
Agradecido : 0
Data de inscrição : 07/05/2012
Re: Código Matrix By: Vector¹
era mas facil colocar os codigos para baixar!
abelha- Membro
- Mensagens : 1
Agradecido : 0
Data de inscrição : 08/05/2012
Re: Código Matrix By: Vector¹
Não, Pois assim vocês só compilavam o programa e ficavam com os créditos!
Re: Código Matrix By: Vector¹
Cara quanta coisa da pra fazer em C++ hein, fiquei impressionado, pelo fato de ser iniciante ainda, cara ta de parabens....eu chego lá....so seu FAN daqui pra frente rsrs......
oO>Kssio<Oo™- Membro
- Mensagens : 163
Agradecido : 2
Data de inscrição : 25/04/2012
Idade : 33
Localização : MT.ROO
Re: Código Matrix By: Vector¹
Muito Legal mas
Para que fiz é usado isso?
Para que fiz é usado isso?
pDevice- Moderador
- Mensagens : 77
Agradecido : 2
Data de inscrição : 10/05/2012
Idade : 26
Tópicos semelhantes
» Código Matrix By: Vector²
» Código Matrix By: Vector²
» [Lançamento] Código - 01
» Código Fonte - Jogo Snake
» Código Matrix By: Vector²
» [Lançamento] Código - 01
» Código Fonte - Jogo Snake
Umbrella System :: Programação :: C/C#/C++ :: Tutoriais
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos