Trying to Smoothly animate in console in c++

Viewed 92

I'm trying to make smooth animations in the console window in c++. I'm using windows.h for functions like Ellipse, and LineTo. The issue is that the frames are very slow and blink a lot. Sometimes the frames get progressively slower and slower as the program moves along. I tried animating a circle that moves down to the right, and a line that goes from the upper left corner to wherever the circle is. When I used the LineTo function, the line was black. I don't know how to color it. Any help would be appreciated, I just want to be able to draw and animate in the console.

#include <windows.h>

void drawSprt(int x, int y) {
    
    HWND handle = GetConsoleWindow();
    
    HDC dc = GetDC(handle);
    
    int r = 10;
    int a;
    
    COLORREF color = 0x00FFFFFF;
    
    Ellipse( dc, x-r,y-r,x+r,y+r);
    MoveToEx( dc, 0, 0, NULL);
    LineTo( dc, x+r, y+r);
    
    ReleaseDC(handle, dc);
}

int main() {
    
    int x = 100;
    int y = 100;
    start:
    
    drawSprt(x,y);
    
    Sleep(500);
    
    x+=5;
    
    y+=5;
    
    system("cls");
    
    
    goto start;
    
}
0 Answers
Related