#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <vector>
// 头文件
class Drawer {
private:
char** frame_;
HANDLE output, buffer;
COORD coord = { 0,0 };
DWORD bytes = 0;
int control_ = 0; // 用于切换输出区和缓冲区
int lenth_; // 绘制区域长度
int width_;// 绘制区域宽度
double fps_; // 帧数
public:
Drawer(int len = 10,int wid = 10, double fps = 10) :lenth_(len), width_(wid), fps_(1000.0 / fps) {
if(lenth_ < 0)
lenth_ = 15;
if(width_ < 0)
width_ = 15;
if(fps_ < 0)
fps_ = 20;
Init();
}
void Init();
void GetFrame(char** frame) {
frame_ = frame;
}
void Draw();
};
// 实现
void Drawer::Draw() {
for (int i = 0; i < width_; i++)
{
coord.Y = i;
if (!control_)
WriteConsoleOutputCharacterA(buffer, frame_[i], lenth_, coord, &bytes);
else
WriteConsoleOutputCharacterA(output, frame_[i], lenth_, coord, &bytes);
}
if (!control_)
SetConsoleActiveScreenBuffer(buffer);
else
SetConsoleActiveScreenBuffer(output);
Sleep(fps_);
control_ = !control_;
}
void::Drawer::Init() {
buffer = CreateConsoleScreenBuffer(
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL
);
output = CreateConsoleScreenBuffer(
GEN
一个简单的基于双缓冲区的控制台绘制类 C++实现
于 2022-04-01 17:42:21 首次发布

最低0.47元/天 解锁文章
4266

被折叠的 条评论
为什么被折叠?



