Created
July 28, 2020 18:59
-
-
Save Erendis42/58eedd8921aee2821a1cdcb745ecc369 to your computer and use it in GitHub Desktop.
Hello 2D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<windows.h> | |
#include<iostream> | |
#include <cmath> | |
#include <conio.h> | |
using namespace std; | |
int main() | |
{ | |
//Get a console handle | |
HWND myconsole = GetConsoleWindow(); | |
//Get a handle to device context | |
HDC mydc = GetDC(myconsole); | |
RECT ConsoleRect; | |
GetWindowRect(myconsole, &ConsoleRect); | |
MoveWindow(myconsole, ConsoleRect.left, ConsoleRect.top, 800, 600, TRUE); | |
int pixel = 0; | |
//Choose any color | |
COLORREF COLOR = RGB(255, 255, 255); | |
int xPad = 10; | |
int yPad = -100; | |
while (!_kbhit()) { | |
for (int k = 0; k < 150; k++) { | |
if (k == 75) | |
{ | |
COLOR = RGB(0, 0, 0); | |
yPad = -100; | |
} | |
if (k == 0) | |
{ | |
COLOR = RGB(255, 255, 255); | |
yPad = -100; | |
} | |
for (int j = 0; j < 4; j++) { | |
//Draw pixels | |
for (int i = 0; i < 100; i++, pixel++) | |
{ | |
SetPixel(mydc, pixel + xPad, i + yPad, COLOR); | |
} | |
for (int i = 99; i > 0; i--, pixel++) | |
{ | |
SetPixel(mydc, pixel + xPad, i + yPad, COLOR); | |
} | |
} | |
pixel = 0; | |
yPad += 10; | |
} | |
} | |
ReleaseDC(myconsole, mydc); | |
cin.ignore(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment