这个代码完成了模拟线性筛的动画。效果如下:
代码如下:
#include <iostream>
#include <string>
#include <graphics.h>
using namespace std;
#define BLOCK_WIDTH 70
#define START_X 80
#define START_Y 60
#define MAX_PER_LINE 10
#define TEXT_COLOR_UNCHOOSE RGB(0, 0, 0)
#define BOADER_COLOR_UNCHOOSE RGB(0, 0, 0)
#define TEXT_COLOR_CHOOSE RGB(232, 16, 16)
#define BOADER_COLOR_CHOOSE RGB(23, 213, 107)
#define TEXT_COLOR_CHOOSE_2 RGB(220, 220, 157)
#define BOADER_COLOR_CHOOSE_2 RGB(86, 153, 175)
// 演示延迟时间
#define DELAY_TIME 1000
int textx = 850, texty = 100;
// 输出运行消息
void printtext(LPCTSTR str) {
// 清空
if (texty >= 700) {
setbkcolor(WHITE);
clearrectangle(850, 0, 1200, 1000);
texty = 100;
textx = 850;
}
settextstyle(22, 0, _T("Consolas"));
settextcolor(BLACK);
setbkcolor(WHITE);