Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CombineLayersIntoFirst(bool firstLayer[PictureWidth][PictureHeight], bool secondLayer[PictureWidth][PictureHeight])
- {
- for (int x = 0; x < PictureWidth; x++)
- {
- for (int y = 0; y < PictureHeight; y++)
- {
- if (firstLayer[x][y] || secondLayer[x][y])
- {
- firstLayer[x][y] = true;
- }
- }
- }
- }
- //2
- void ClearLayer(bool layer[PictureWidth][PictureHeight])
- {
- for (int x = 0; x < PictureWidth; x++)
- {
- for (int y = 0; y < PictureHeight; y++)
- {
- layer[x][y] = false;
- }
- }
- }
- // 3
- void PrintClock(bool clockFrameLayer[PictureWidth][PictureHeight], bool clockNumbersLayer[PictureWidth][PictureHeight], bool hoursHandLayer[PictureWidth][PictureHeight], bool minutesHandLayer[PictureWidth][PictureHeight], bool secondsHandLayer[PictureWidth][PictureHeight], bool centerPointLayer[PictureWidth][PictureHeight])
- {
- //
- system("color 0F");
- //
- for (int y = 0; y < PictureHeight; y++)
- {
- for (int x = 0; x < PictureWidth; x++)
- {
- //
- if (secondsHandLayer[x][y] || minutesHandLayer[x][y] || hoursHandLayer[x][y] || clockNumbersLayer[x][y] || clockFrameLayer[x][y] || centerPointLayer[x][y])
- {
- //
- if (centerPointLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x04); //
- else if (secondsHandLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F); //
- else if (minutesHandLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x09); //
- else if (hoursHandLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02); //
- else if (clockNumbersLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x08); //
- else if (clockFrameLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F); //
- cout << char(symbolChar) << char(symbolChar); //
- }
- else
- {
- cout << char(emptyChar) << char(emptyChar); //
- }
- }
- //
- cout << endl;
- }
- }
- // included libraries
- #include <iostream>
- #include <Windows.h>
- #include <cmath>
- #include <stdio.h>
- #include <ctime>
- // Define Constants
- #define PI (22.0/7.0)
- #define PictureWidth 27
- #define PictureHeight 27
- // Frames Variables
- const int targetedFPS = 1;
- const float idealDurationPerFrame = 1000.0f / targetedFPS;
- float nextFrameAfter = 1, duration = 0;
- clock_t startTime;
- unsigned int framesCounter = 0;
- // Characters To Draw Circle
- char symbolChar = 219;
- char emptyChar = 32;
- using namespace std;
- //
- void ClearLayer(bool layer[PictureWidth][PictureHeight])
- {
- for (int x = 0; x < PictureWidth; x++)
- {
- for (int y = 0; y < PictureHeight; y++)
- {
- layer[x][y] = false;
- }
- }
- }
- // Draw Circle
- void DrawCircle(bool layer[PictureWidth][PictureHeight])
- {
- layer[0][10] = true;
- layer[0][11] = true;
- layer[0][12] = true;
- layer[0][13] = true;
- layer[0][14] = true;
- layer[0][15] = true;
- layer[0][16] = true;
- layer[1][8] = true;
- layer[1][9] = true;
- layer[1][17] = true;
- layer[1][18] = true;
- layer[2][6] = true;
- layer[2][7] = true;
- layer[2][19] = true;
- layer[2][20] = true;
- layer[3][5] = true;
- layer[3][21] = true;
- layer[4][4] = true;
- layer[4][22] = true;
- layer[5][3] = true;
- layer[5][23] = true;
- layer[6][2] = true;
- layer[6][24] = true;
- layer[7][2] = true;
- layer[7][24] = true;
- layer[8][1] = true;
- layer[8][25] = true;
- layer[9][1] = true;
- layer[9][25] = true;
- layer[10][0] = true;
- layer[10][26] = true;
- layer[11][0] = true;
- layer[11][26] = true;
- layer[12][0] = true;
- layer[12][26] = true;
- layer[13][0] = true;
- layer[13][26] = true;
- layer[14][0] = true;
- layer[14][26] = true;
- layer[15][0] = true;
- layer[15][26] = true;
- layer[16][0] = true;
- layer[16][26] = true;
- layer[17][1] = true;
- layer[17][25] = true;
- layer[18][1] = true;
- layer[18][25] = true;
- layer[19][2] = true;
- layer[19][24] = true;
- layer[20][2] = true;
- layer[20][24] = true;
- layer[21][3] = true;
- layer[21][23] = true;
- layer[22][4] = true;
- layer[22][22] = true;
- layer[23][5] = true;
- layer[23][21] = true;
- layer[24][6] = true;
- layer[24][7] = true;
- layer[24][20] = true;
- layer[24][19] = true;
- layer[25][8] = true;
- layer[25][9] = true;
- layer[25][18] = true;
- layer[25][17] = true;
- layer[26][10] = true;
- layer[26][11] = true;
- layer[26][12] = true;
- layer[26][13] = true;
- layer[26][14] = true;
- layer[26][15] = true;
- layer[26][16] = true;
- }
- // Draw Clock Numbers
- void DrawClockNumbers(bool layer[PictureWidth][PictureHeight])
- {
- //12
- layer[11][2] = true;
- layer[11][3] = true;
- layer[11][4] = true;
- layer[11][5] = true;
- layer[11][6] = true;
- layer[13][2] = true;
- layer[14][2] = true;
- layer[15][2] = true;
- layer[15][3] = true;
- layer[13][4] = true;
- layer[14][4] = true;
- layer[15][4] = true;
- layer[13][5] = true;
- layer[13][6] = true;
- layer[14][6] = true;
- layer[15][6] = true;
- //3
- layer[22][11] = true;
- layer[23][11] = true;
- layer[24][11] = true;
- layer[24][12] = true;
- layer[22][13] = true;
- layer[23][13] = true;
- layer[24][13] = true;
- layer[24][14] = true;
- layer[22][15] = true;
- layer[23][15] = true;
- layer[24][15] = true;
- //6
- layer[12][20] = true;
- layer[13][20] = true;
- layer[14][20] = true;
- layer[12][21] = true;
- layer[12][22] = true;
- layer[13][22] = true;
- layer[14][22] = true;
- layer[12][23] = true;
- layer[14][23] = true;
- layer[12][24] = true;
- layer[13][24] = true;
- layer[14][24] = true;
- //9
- layer[2][11] = true;
- layer[3][11] = true;
- layer[4][11] = true;
- layer[2][12] = true;
- layer[4][12] = true;
- layer[2][13] = true;
- layer[3][13] = true;
- layer[4][13] = true;
- layer[4][14] = true;
- layer[2][15] = true;
- layer[3][15] = true;
- layer[4][15] = true;
- //dot as the following numbers (1, 2, 4, 5, 7, 8, 10, 11)
- //1
- layer[17][4] = true;
- layer[17][5] = true;
- layer[18][4] = true;
- layer[18][5] = true;
- //2
- layer[21][7] = true;
- layer[21][8] = true;
- layer[22][7] = true;
- layer[22][8] = true;
- //4
- layer[21][18] = true;
- layer[21][19] = true;
- layer[22][18] = true;
- layer[22][19] = true;
- //5
- layer[17][21] = true;
- layer[17][22] = true;
- layer[18][21] = true;
- layer[18][22] = true;
- //7
- layer[8][21] = true;
- layer[8][22] = true;
- layer[9][21] = true;
- layer[9][22] = true;
- //8
- layer[4][18] = true;
- layer[4][19] = true;
- layer[5][18] = true;
- layer[5][19] = true;
- //10
- layer[4][7] = true;
- layer[4][8] = true;
- layer[5][7] = true;
- layer[5][8] = true;
- //11
- layer[8][4] = true;
- layer[8][5] = true;
- layer[9][4] = true;
- layer[9][5] = true;
- }
- //
- void CombineLayersIntoFirst(bool firstLayer[PictureWidth][PictureHeight], bool secondLayer[PictureWidth][PictureHeight])
- {
- for (int x = 0; x < PictureWidth; x++)
- {
- for (int y = 0; y < PictureHeight; y++)
- {
- if (firstLayer[x][y] || secondLayer[x][y])
- {
- firstLayer[x][y] = true;
- }
- }
- }
- }
- // Display Clock
- void PrintClock(bool clockFrameLayer[PictureWidth][PictureHeight], bool clockNumbersLayer[PictureWidth][PictureHeight], bool hoursHandLayer[PictureWidth][PictureHeight], bool minutesHandLayer[PictureWidth][PictureHeight], bool secondsHandLayer[PictureWidth][PictureHeight], bool centerPointLayer[PictureWidth][PictureHeight])
- {
- //
- system("color 0F");
- //
- for (int y = 0; y < PictureHeight; y++)
- {
- for (int x = 0; x < PictureWidth; x++)
- {
- //
- if (secondsHandLayer[x][y] || minutesHandLayer[x][y] || hoursHandLayer[x][y] || clockNumbersLayer[x][y] || clockFrameLayer[x][y] || centerPointLayer[x][y])
- {
- //
- if (centerPointLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x04); //
- else if (secondsHandLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F); //
- else if (minutesHandLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x09); //
- else if (hoursHandLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02); //
- else if (clockNumbersLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x08); //
- else if (clockFrameLayer[x][y]) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F); //
- cout << char(symbolChar) << char(symbolChar); //
- }
- else
- {
- cout << char(emptyChar) << char(emptyChar); //
- }
- }
- //
- cout << endl;
- }
- }
- // Draw Arrows Of Clock
- void DrawClockHand(bool handLayer[PictureWidth][PictureHeight], float degree, float length)
- {
- //
- if (length > 1) return;
- //
- double StartPointx = PictureWidth / 2.0;
- double StartPointy = PictureHeight / 2.0;
- //
- double LineLengthx = StartPointx * length;
- double LineLengthy = StartPointy * length;
- //
- double LineLength = sqrt(LineLengthx * LineLengthx + LineLengthy * LineLengthy);
- //
- double deltaT = min(LineLengthx, LineLengthy) / max(LineLengthx, LineLengthy);
- //
- int x, y;
- for (double t = 0; t <= LineLength; t += deltaT)
- {
- //
- x = int(StartPointx + t * cos((degree - 0.25) * 2.0 * PI));
- y = int(StartPointy + t * sin((degree - 0.25) * 2.0 * PI));
- //
- handLayer[x][y] = true;
- }
- }
- // Draw & Set Center Of Clock
- void DrawCenterPoint(bool layer[PictureWidth][PictureHeight])
- {
- layer[PictureWidth / 2][PictureHeight / 2] = true;
- }
- // Convert Actual Time Ti Ticks
- float ConvertTimeToDegree(int time, int ticks, int timeFraction = 0, int timeFractionTicks = 1)
- {
- return float(time) / float(ticks) + float(timeFraction) / (float(timeFractionTicks) * float(ticks));
- }
- // Display Clock In Actual Time
- void PrintDigitalClock(int seconds, int minutes, int hours)
- {
- cout << "Clock: " << hours << ":" << minutes << ":" << seconds << endl;
- }
- // Display Frame Counter & Its Duration
- void PrintFramesLog()
- {
- cout << "frame #" << framesCounter << "; " << "frame duration: " << duration << " ms; " << "sleep period: " << (idealDurationPerFrame - duration) << " ms; running at: " << (1000.0f / (duration + max(0, (idealDurationPerFrame - duration)))) << " fps; next frame after: " << nextFrameAfter << "; " << endl;
- }
- // get the time from the local system
- void UpdateClockToCurrentTime(int& hours, int& minutes, int& seconds)
- {
- time_t t = time(0); // get time now
- struct tm* now = new tm; // intialize a struc
- localtime_s(now, &t); // Converts a time_t time value to a tm structure, and corrects for the local time zone.
- // store the time in the var.
- seconds = now->tm_sec;
- minutes = now->tm_min;
- hours = now->tm_hour;
- //cout << (now->tm_year + 1900) << '-'
- // << (now->tm_mon + 1) << '-'
- // << now->tm_mday
- // << endl;
- }
- int main()
- {
- // Function Call
- bool circleLayer[PictureWidth][PictureHeight];
- bool numbersLayer[PictureWidth][PictureHeight];
- bool secondsHandLayer[PictureWidth][PictureHeight];
- bool minutesHandLayer[PictureWidth][PictureHeight];
- bool hoursHandLayer[PictureWidth][PictureHeight];
- bool centerPointLayer[PictureWidth][PictureHeight];
- // Variable Declaration
- int seconds = 0;
- int minutes = 0;
- int hours = 0;
- // loop for ever
- while (true)
- {
- // get the time at the start
- startTime = clock();
- // process the frame
- {
- //
- ClearLayer(circleLayer);
- ClearLayer(numbersLayer);
- ClearLayer(centerPointLayer);
- ClearLayer(secondsHandLayer);
- ClearLayer(minutesHandLayer);
- ClearLayer(hoursHandLayer);
- // Update Clock To Current Time
- UpdateClockToCurrentTime(hours, minutes, seconds);
- // Function Call To Draw Circle, Clock Numbers, Center Of Clock, Clock Arrows in seconds, minutes & Hours
- DrawCircle(circleLayer);
- DrawClockNumbers(numbersLayer);
- DrawCenterPoint(centerPointLayer);
- DrawClockHand(secondsHandLayer, ConvertTimeToDegree(seconds, 60), 0.5f);
- DrawClockHand(minutesHandLayer, ConvertTimeToDegree(minutes, 60, seconds, 60), 0.4f);
- DrawClockHand(hoursHandLayer, ConvertTimeToDegree(hours, 12, minutes, 60), 0.3f);
- // Clear Screen
- system("cls");
- // Display & Output Clock
- PrintClock(circleLayer, numbersLayer, hoursHandLayer, minutesHandLayer, secondsHandLayer, centerPointLayer);
- // Function Call To Display Clock In Actual Time
- PrintDigitalClock(seconds, minutes, hours);
- }
- // find duration of the processed frame
- duration = (clock() - startTime);
- // find the next targeted frame
- nextFrameAfter = (duration / 1000.0f) + 1;
- // increase the frame counter
- framesCounter += nextFrameAfter;
- //
- PrintFramesLog();
- // frame process duration finished too early based on the targeted frames per seconds so sleep
- while (duration < idealDurationPerFrame)
- {
- duration = (clock() - startTime);
- }
- }
- // Exit Program
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement