#include <iostream>
#include <windows.h>
#include <vector>
#include <cmath>
using namespace std;
const int WIDTH = 80;
const int HEIGHT = 25;
void drawGraph(vector<int>& graphData) {
system("cls");
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
if (i == HEIGHT / 2) {
cout << "-";
}
else if (i == HEIGHT / 2 + graphData[j]) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
}
int main() {
vector<int> graphData(WIDTH, 0);
double theta = 0.0;
while (true) {
theta +=2;
// 使用正弦函数产生心电图数据
for (int i = 0; i < WIDTH; i++) {
graphData[i] = static_cast<int>(sin(theta + i / 10.0) * HEIGHT / 4);
}
drawGraph(graphData);
Sleep(1); // 控制动画速度,单位为毫秒
}
return 0;
}
这个代码使用了字符界面来绘制心电图图形。在每一帧中,通过计算正弦函数的值来生成心电图数据,并在屏幕上绘制出来。可以通过调整theta
的增量和Sleep
函数的参数来控制动画的速度。
编译并运行这段代码后,你会看到一个动画模拟的心电图图形。请注意,这只是一个简单的示例,如果你想要更加详细和准确的心电图模拟,可能需要使用更复杂的算法和数据处理。