1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
#include <iostream>
#include <ctime>
#include <sstream>
#include <functional>
#include <windows.h>
using namespace std;
enum Names{COMMA = 10, PERIOD = 11};
struct Clock{int hours; int mins;int secs;};
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void draw(char Output[][7], int number);
void create_output(char chars[][7][7], char Output[][7], Clock clock);
void Split(int nums[], int hrs, int mins, int secs);
void MoveCursor(int x, int y );
int main()
{
//system vars
tm * timeinfo;
bool done = false;
Clock clock;
char Output[56][7] = {0}; //array output will be put into
char characters[12][7][7] = {{{0,0,0,0,0,0,0},
{1,1,1,1,1,1,1},
{1,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,1,1,1,1,1,1},
{0,0,0,0,0,0,0}},
{{0,0,0,0,0,0,0},
{0,0,0,0,0,0,1},
{0,1,0,0,0,0,1},
{1,1,1,1,1,1,1},
{0,0,0,0,0,0,1},
{0,0,0,0,0,0,1},
{0,0,0,0,0,0,0}},
{{0,0,0,0,0,0,0},
{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
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,1,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}}};
do //main loop
{
//get time
time_t rawtime;
time ( &rawtime );
timeinfo = localtime( &rawtime );
clock.hours = timeinfo->tm_hour;
clock.secs = timeinfo->tm_sec;
clock.mins = timeinfo->tm_min;
//draw clock
create_output(characters, Output, clock);
draw(Output, clock.hours);
//move back cursor
MoveCursor(0,0);
Sleep(1000);
} while(true);
return 0;
}
void draw(char Output[][7], int num)
{
for (int y = 0; y < 7; y++)
{
for (int x = 0; x < 56; x++)
{
if (Output[x][y] == 1)
cout << "\xFE";
else
cout << " ";
}
cout << endl;
}
}
void create_output(char chars[][7][7], char Output[][7], Clock clock)
{
int offset = 0;
int num = 0;
int numbers[6] = {0};
Split(numbers, clock.hours, clock.mins, clock.secs);
for (int i = 0; i < 8; i++)
{
switch (i)
{
case 0:
num = numbers[0];
break;
case 1:
num = numbers[1];
break;
case 2:
case 5:
num = COMMA;
break;
case 3:
num = numbers[2];
break;
case 4:
num = numbers[3];
break;
case 6:
num = numbers[4];
break;
case 7:
num = numbers[5];
break;
}
for (int y = 0; y < 7; y ++)
{
for (int x = 0; x < 7; x++)
{
Output[x+offset][y] = chars[num][x][y];
}
}
offset+=7;
}
}
void Split(int nums[], int hrs, int mins, int secs)
{
ostringstream converthrs;
ostringstream convertmins;
ostringstream convertsecs;
string num;
if (hrs < 10)
{
nums[0] = 0;
nums[1] = hrs;
}
else
{
converthrs << hrs;
num = converthrs.str();
istringstream(num.substr(0,1)) >> nums[0];
istringstream(num.substr(1,1)) >> nums[1];
}
if (mins < 10)
{
nums[2] = 0;
nums[3] = mins;
}
else
{
convertmins << mins;
num = convertmins.str();
istringstream(num.substr(0,1)) >> nums[2];
istringstream(num.substr(1,1)) >> nums[3];
}
if (secs < 10)
{
nums[4] = 0;
nums[5] = secs;
}
else
{
convertsecs << secs;
num = convertsecs.str();
istringstream(num.substr(0,1)) >> nums[4];
istringstream(num.substr(1,1)) >> nums[5];
}
}
void MoveCursor(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
|