Hello World
#include <stdio.h>
#include <math.h>
#include <windows.h>
//定义隐藏光标函数
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = FALSE;
cursor.dwSize = sizeof(cursor);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
}
void clearScreen(){
printf("\e[1;1H\e[2J");
}
int main() {
HideCursor();
int buffer[128][64];
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 64; j++) {
buffer[i][j] = 0;
}
}
int x_cnt = 0;
while(1)
{
clearScreen();
double x = x_cnt * 2 * M_PI / 64;
double y = (sin(x) + 1) / 2 * (64 - 1);
buffer[127][(int)(y + 0.5f)] = 1;
x_cnt++;
x_cnt%=64;
// 将buffer打印出来
for (int j = 0; j < 64; j++) {
for (int i = 0; i < 128; i++) {
if(buffer[i][j] == 1)
{
printf("\033[1;33;42m* ");
}
else
{
printf(" ", buffer[i][j]);
}
}
printf("\n");
}
Sleep(50);
//将buffer里的数据整体往左平移
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 64; j++) {
buffer[i][j] = buffer[i + 1][j];
}
// buffer[i][64-1] = 0;
}
}
return 0;
}
标签:int,++,示波器,cursor,buffer,虚拟,64,终端,printf
From: https://www.cnblogs.com/USTHzhanglu/p/18061536