Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:57:37+00:00 2026-06-17T03:57:37+00:00

Well I was bored so wanted to make an animation in a console window.

  • 0

Well I was bored so wanted to make an animation in a console window.

Now when I setup the first bits I noticed it is very slow, something around 333ms for a whole screen to fill with characters..

I am wondering if there is a way to at least get ~20 fps?

Here is my code:

#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <iostream>
#include <array>

#define WIDTH (100)
#define HEIGHT (35)

bool SetWindow(int Width, int Height) { 
    _COORD coord; 
    coord.X = Width; coord.Y = Height; 

    _SMALL_RECT Rect; 
    Rect.Left = 0;              Rect.Top = 0;  
    Rect.Bottom = Height - 1;   Rect.Right = Width - 1; 

    HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); 
    if (Handle == NULL)return FALSE; 
    SetConsoleScreenBufferSize(Handle, coord);
    if(!SetConsoleWindowInfo(Handle, TRUE, &Rect)) return FALSE; 
    return TRUE; 
} 

std::array<std::array<unsigned char, WIDTH+1>, HEIGHT> Screen;//WIDTH+1 = prevent cout from undefined behaviour

void Putchars(unsigned char x){
    for(int row = 0; row < HEIGHT; ++row){
        std::fill(Screen[row].begin(),Screen[row].end(),x);
        Screen[row].at(WIDTH) = 0;//here = prevent cout from undefined behaviour
    }
}

void ShowFrame(DWORD delay = 0,bool fPutchars = false, unsigned char x = 0){
    if(fPutchars)Putchars(x);
    if(delay)Sleep(delay);
    system("CLS");
    for(int row = 0; row < HEIGHT; ++row)
        std::cout << Screen[row].data() << std::flush;
}

int _tmain(int argc, _TCHAR* argv[]){//sould execute @~63 fps, yet it executes @~3-4 fps
    if(SetWindow(100,HEIGHT)){
        for(unsigned char i = 219; i != 0; --i)
        ShowFrame(16,true, i);
    }
    return 0;
}

Edit: after reading numerous answers, tips and comments I finally worked it out, thank you guys, this is my final “base” code:

#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <iostream>
#include <array>

#define WIDTH (100)
#define HEIGHT (34)

HANDLE current;
HANDLE buffer;

bool SetWindow(int Width, int Height) { 
    _COORD coord; 
    coord.X = Width; coord.Y = Height; 

    _SMALL_RECT Rect; 
    Rect.Left = 0;              Rect.Top = 0;  
    Rect.Bottom = Height - 1;   Rect.Right = Width - 1; 

    HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); 
    if (Handle == NULL)return FALSE; 
    SetConsoleScreenBufferSize(Handle, coord);
    if(!SetConsoleWindowInfo(Handle, TRUE, &Rect)) return FALSE; 
    return TRUE; 
} 

std::array<std::array<CHAR, WIDTH+1>, HEIGHT> Screen;//WIDTH+1 = prevent cout from undefined behaviour

void Putchars(CHAR x){
    for(int row = 0; row < HEIGHT; ++row){
        std::fill(Screen[row].begin(),Screen[row].end(),x);
        Screen[row].at(WIDTH) = 0;//here = prevent cout from undefined behaviour
    }
}

void ShowFrame(DWORD delay = 0, bool fPutchars = false, CHAR x = 0){
    if(fPutchars)Putchars(x);
    if(delay)Sleep(delay);
    //system("CLS");
    _COORD coord;
    coord.X = 0;
    for(int row = 0; row < HEIGHT; ++row)
    {
        coord.Y = row;
        FillConsoleOutputCharacterA(buffer,Screen[row].data()[0],100,coord,NULL);
    }
}

int _tmain(int argc, _TCHAR* argv[]){//sould execute @~63 fps, yet it executes @~3-4 fps
    SetWindow(WIDTH, HEIGHT);
    current = GetStdHandle (STD_OUTPUT_HANDLE);
    buffer = CreateConsoleScreenBuffer (
        GENERIC_WRITE,
        0,
        NULL,
        CONSOLE_TEXTMODE_BUFFER,
        NULL
    );
    SetConsoleActiveScreenBuffer (buffer);

    if(SetWindow(WIDTH,HEIGHT)){
        for(CHAR i = 219; i != 0; --i)
        ShowFrame(250,true, i);
    }
    CloseHandle (buffer); //clean up
    return 0;
}

and it seems to work very fast 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:57:38+00:00Added an answer on June 17, 2026 at 3:57 am

    Just glancing at your code, you’re spawning a separate program (“CLS”) once per frame. That’s horrendously slow all by itself.

    Contrary to some of the comments, the Windows console is capable of at least fairly reasonable speed if used even close to correctly (as in: you can update the console faster than any monitor can display the data).

    Just for reference, here’s a version of John Conway’s Game of Life written for the Windows console. For timing purposes, it just generates a random starting screen and runs for 2000 generations, then stops. On my machine, it does 2000 generations in about 2 seconds, or around 1000 frames per second (useless, since a typical monitor can only update at around 60-120 Hz). Under 32-bit Windows with a full-screen console, it can roughly double that (again, at least on my machine). I’m pretty sure with a little work, this could be sped up some more, but I’ve never seen any reason to bother.

    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    #include <io.h>
    
    #define     ROWS        50
    #define     COLS        80
    
    // The total number of generations is really double this number.
    int generations = 1000;
    
    int civ1[ROWS+2][COLS+2], civ2[ROWS+2][COLS+2];
    
    CHAR_INFO disp[ROWS][COLS];
    HANDLE console;
    COORD size = { COLS, ROWS };
    COORD src = { 0, 0};
    SMALL_RECT  dest = { 0, 0, COLS, ROWS };
    
    void ClrScrn(char attrib) {
        COORD pos = { 0, 0};
        DWORD written;
        unsigned size;
    
        size = ROWS * COLS;
    
        FillConsoleOutputCharacter(console, ' ', size, pos, &written);
        FillConsoleOutputAttribute(console, attrib, size, pos, &written);
        SetConsoleCursorPosition(console, pos);
    }
    
    void fill_edges(int civ1[ROWS+2][COLS+2]) {
        int i, j;
    
        for (i=1; i<=ROWS; ++i) {
            civ1[i][0] = civ1[i][COLS];
            civ1[i][COLS+1] = civ1[i][1];
        }
        for (j=1; j<=COLS; ++j) {
            civ1[0][j] = civ1[ROWS][j];
            civ1[ROWS+1][j] = civ1[1][j];
        }
        civ1[0][0] = civ1[ROWS][COLS];
        civ1[ROWS+1][COLS+1] = civ1[1][1];
        civ1[0][COLS+1] = civ1[ROWS][1];
        civ1[ROWS+1][0] = civ1[1][COLS];
    }
    
    void update_generation(int old_gen[ROWS+2][COLS+2], 
                           int new_gen[ROWS+2][COLS+2])
    {
        int i, j, count;
    
        for (i = 1; i <= ROWS; ++i)
        {
            for (j = 1; j <= COLS; ++j)
            {
                count = old_gen[i - 1][j - 1] +
                    old_gen[i - 1][j] +
                    old_gen[i - 1][j + 1] +
                    old_gen[i][j - 1] +
                    old_gen[i][j + 1] +
                    old_gen[i + 1][j - 1] +
                    old_gen[i + 1][j] +
                    old_gen[i + 1][j + 1];
    
                switch(count) 
                {
                case 2:
                    new_gen[i][j] = old_gen[i][j];
                    break;
    
                case 3:
                    new_gen[i][j] = 1;
                    disp[i-1][j-1].Char.AsciiChar = '*';
                    break;
                default:
                    new_gen[i][j] = 0;
                    disp[i-1][j-1].Char.AsciiChar = ' ';
                    break;
                }
            }
        }
        WriteConsoleOutput(console, (CHAR_INFO *)disp, size, src, &dest);
        fill_edges(new_gen);
    }
    
    void initialize(void)
    {
        int i, j;
    
        ClrScrn(0x71);
        srand(((unsigned int)time(NULL))|1);
    
        for (i = 1; i <= ROWS; ++i)
        {
            for (j = 1; j <= COLS; ++j)
            {
                civ1[i][j] = (int)(((__int64)rand()*2)/RAND_MAX);
                disp[i-1][j-1].Char.AsciiChar = civ1[i][j] ? '*' : ' ';
                disp[i-1][j-1].Attributes = 0x71;
            }
        }
        WriteConsoleOutput(console, (CHAR_INFO *)disp, size, src, &dest);
        fill_edges(civ1);
    }
    
    int main(int argc, char **argv) {
    
        int i;
    
        if ( argc != 1)
            generations = atoi(argv[1]);
    
        console = GetStdHandle(STD_OUTPUT_HANDLE);
        initialize();
        for (i = 0; i <generations; ++i)
        {
            update_generation(civ1, civ2);
            update_generation(civ2, civ1);
        }
        return EXIT_SUCCESS;
    }
    

    If nothing else, this has a ClrScrn function you may find handy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I was feeling bored and decided I wanted to make a hangman game.
Well, i took a break from RoR for studies, now I am back, I
Well there is enough information about this subject. For example this thread was very
I'v been bored so I created a small console minesweeper game and while writting
Well friends, I have got this query which works but is very long for
Well, my website can not redirect to https://www.facebook.com/QuaFootSpa from http://quafootspa.com/ I have tried redirection
Well I can start the thread when I press togglebutton to ON and it
well i have a configuration like this in the components part of my config
Well, the title pretty much states it. I want to be able to draw
Well, I have a application which somehow requires some system resources, but how do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.