rendered paste body/********************************/
/**********BRODEUR235's**********/
/*****Permanent Programming 2****/
/***********Version 1.0**********/
/*************7-21-07************/
/********************************/
#include <windows.h>
#include <iostream>
#include <strings.h>
#include <fstream>
using namespace std;
string undo_morse(string morse);
int main()
{
//Wait until ready
for(;;)
{
if(GetAsyncKeyState(VK_LSHIFT))
{
break;
}
}
//End Wait until ready
//Variables
HDC hdc = GetDC(NULL); // Get Device Content for entire screen
char morse[50];
int FPA[100][30]; // First Pixel Array
int PA2[50]; //Pixel Array 2
int lastwhite = 0; //Number of last white pixel
int nop; //# of pixel
int current;
int c = 0;
int y_start = 355; //Use current for I.E. Change to 375 for FireFox
int x_start = 474; //Use current for I.E. Change to 473 for FireFox
ofstream morsefile;
ofstream final_file;
fstream morsefile2;
string morse_strings[10];
string final[10];
string line;
string full;
//End Variables
//Loop thru image pixels and put them in an array
for (int y = y_start; y < 30 + y_start; y++)
{
for (int x = x_start; x < 100 + x_start; x++)
{
if (GetPixel(hdc, x, y) != 0)
{
//Pixel iss not black (so it's white)
FPA[x - x_start][y - y_start] = 1;
}
else
{
//Pixel is black
FPA[x - x_start][y - y_start] = -1;
}
}
}
//Organize data
for (int a = 0; a < 30; a++)
{
for (int b = 0; b < 100; b++)
{
if (FPA[b][a] > 0)
{
//Get the number of the pixel
nop = a * 100 + b;
//Subtract the last pixel number form this one
current = nop - lastwhite;
//Add the number onto the pixel array 2
PA2[c] = current;
//Because it's a white, Add one to counter c
c = c + 1;
//make lastwhite the current one for next time
lastwhite = nop;
}
else
{
//it's black
}
}
}
/*
//TEST SECTION 1
ofstream myfile;
myfile.open("test.txt");
for(int test = 0; test < 50; test++)
{
myfile << PA2[test] << endl;
}
myfile.close();
system("start test.txt");
//End Test Section
*/
//Turn integer values into morse
for(int d = 0; d < 50; d++)
{
morse[d]=char(PA2[d]);
}
//End Turn integer values into morse
/*
//TEST SECTION 2
ofstream myfile;
myfile.open("test.txt");
for(int test = 0; test < 50; test++)
{
myfile << morse[test];
}
myfile.close();
system("start test.txt");
*/
//write morse to file
morsefile.open("morse_file.txt");
for(int e = 0; e < 50; e++)
{
if(morse[e] != char(32))
{
morsefile << morse[e];
}
else
{
morsefile << endl;
}
}
morsefile.close();
//End Write morse to file
/*TEST
system("start morse_file.txt");
End TEST
*/
//Collect morse from file
morsefile2.open("morse_file.txt");
for(int f = 0; f < 10; f++)
{
getline(morsefile2, line);
morse_strings[f] = line;
}
//End Collect morse from file
//convert morse to characters
final_file.open("final_file.txt");
for(int g = 0; g < 10; g++)
{
final[g] = undo_morse(morse_strings[g]);
final_file << final[g];
}
final_file.close();
system("start final_file.txt");
return 0;
}
string undo_morse(string morse)
{
string nm;
if(morse == ".-")
{
nm = "a";
}
if(morse == "-...")
{
nm = "b";
}
if(morse == "-.-.")
{
nm = "c";
}
if(morse == "-..")
{
nm = "d";
}
if(morse == ".")
{
nm = "e";
}
if(morse == "..-.")
{
nm = "f";
}
if(morse == "--.")
{
nm = "g";
}
if(morse == "....")
{
nm = "h";
}
if(morse == "..")
{
nm = "i";
}
if(morse == ".---")
{
nm = "j";
}
if(morse == "-.-")
{
nm = "k";
}
if(morse == ".-..")
{
nm = "l";
}
if(morse == "--")
{
nm = "m";
}
if(morse == "-.")
{
nm = "n";
}
if(morse == "---")
{
nm = "o";
}
if(morse == ".--.")
{
nm = "p";
}
if(morse == "--.-")
{
nm = "q";
}
if(morse == ".-.")
{
nm = "r";
}
if(morse == "...")
{
nm = "s";
}
if(morse == "-")
{
nm = "t";
}
if(morse == "..-")
{
nm = "u";
}
if(morse == "...-")
{
nm = "v";
}
if(morse == ".--")
{
nm = "w";
}
if(morse == "-..-")
{
nm = "x";
}
if(morse == "-.--")
{
nm = "y";
}
if(morse == "--..")
{
nm = "z";
}
if(morse == ".----")
{
nm = "1";
}
if(morse == "..---")
{
nm = "2";
}
if(morse == "...--")
{
nm = "3";
}
if(morse == "....-")
{
nm = "4";
}
if(morse == ".....")
{
nm = "5";
}
if(morse == "-....")
{
nm = "6";
}
if(morse == "--...")
{
nm = "7";
}
if(morse == "---..")
{
nm = "8";
}
if(morse == "----.")
{
nm = "9";
}
if(morse == "-----")
{
nm = "0";
}
return nm;
}