vc2010爱心代码
时间: 2024-06-02 10:06:14 浏览: 26
VC2010爱心代码是一种经典的计算机程序,它可以在计算机屏幕上显示出一颗闪烁的爱心。这个程序的原理是通过在控制台输出一些特殊的字符来模拟图形的效果。以下是VC2010爱心代码的实现方式:
```
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut, &cci);
cci.bVisible = false;
SetConsoleCursorInfo(hOut, &cci);
const int n = 300;
const char symbol = { '-', '\\', '|', '/' };
const char* str = "I love you!";
const int len = strlen(str);
const int x = 40, y = 12;
for (int i = 0; i < n; ++i)
{
double f = (i % n) * 1.0 / n * 3.1415926 * 2;
int dx = (int)(sin(f) * 16);
int dy = (int)(cos(f) * 7);
int color = (i % 7) + 9;
COORD pos = { x + dx, y - dy };
SetConsoleCursorPosition(hOut, pos);
SetConsoleTextAttribute(hOut, color);
putchar(symbol[i % 4]);
SetConsoleTextAttribute(hOut, 7);
}
COORD pos = { x - len / 2, y };
SetConsoleCursorPosition(hOut, pos);
cout << str;
getchar();
return 0;
}
```