版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/roczheng1990/article/details/77488627
编程之美的例子
#include "Windows.h"
#include "stdlib.h"
#include "math.h"
#include <iostream>
using namespace std;
const double SPLIT = 1;
const int COUNT = 300;
const double PI = 3.14159265;
const int INTERVAL = 100;
int main(int argc,_TCHAR* argv[])
{
DWORD busySpan[COUNT];
DWORD idleSpan[COUNT];
int half = INTERVAL / 2;
double radian = 0.0;
for(int i = 0; i < COUNT;i++)
{
busySpan[i] = (DWORD)(half + (sin(PI * radian) * half));
idleSpan[i] = INTERVAL - busySpan[i];
radian += SPLIT;
}
DWORD startTime = 0;
int j = 0;
while(true)
{
j = j % COUNT;
startTime = GetTickCount();
while((GetTickCount() - startTime) <= busySpan[j])
;
Sleep(idleSpan[j]);
}
//cout << "Hello world!" << endl;
return 0;
}
结果我并没跑出来!噗!