#include <iostream>
#include <windows.h>
#include <cmath>
using namespace std;
const double PI = 3.1415926;
const int COUNT = 300;
const double SPLICE = 0.01;
const int INTERVAL = 300;
int main()
{
/*while(1)
{
for (int i=0;i<9600000;++i) ;
Sleep(10);
}*/
/*
int busyTime = 10;
int idalTime = busyTime;
long long start = 0;
while(1)
{
start = GetTickCount();
while(GetTickCount()-start <= busyTime) ;
Sleep(idalTime);
}*/
DWORD busySpan [COUNT] = {0};
DWORD idalSpan [COUNT] = {0};
DWORD startTime = 0;
double radians = 0.0;
int j = 0;
int half = INTERVAL / 2;
for (size_t i = 0; i<COUNT;++i)
{
busySpan[i] = half + half*sin(PI*radians);
idalSpan[i] = INTERVAL - busySpan[i];
radians += SPLICE;
}
while(1)
{
j = j% COUNT;
startTime = GetTickCount();
while(GetTickCount() - startTime < busySpan[j]) ;
Sleep(idalSpan[j]);
j++;
}
return 0;
}
#include <windows.h>
#include <cmath>
using namespace std;
const double PI = 3.1415926;
const int COUNT = 300;
const double SPLICE = 0.01;
const int INTERVAL = 300;
int main()
{
/*while(1)
{
for (int i=0;i<9600000;++i) ;
Sleep(10);
}*/
/*
int busyTime = 10;
int idalTime = busyTime;
long long start = 0;
while(1)
{
start = GetTickCount();
while(GetTickCount()-start <= busyTime) ;
Sleep(idalTime);
}*/
DWORD busySpan [COUNT] = {0};
DWORD idalSpan [COUNT] = {0};
DWORD startTime = 0;
double radians = 0.0;
int j = 0;
int half = INTERVAL / 2;
for (size_t i = 0; i<COUNT;++i)
{
busySpan[i] = half + half*sin(PI*radians);
idalSpan[i] = INTERVAL - busySpan[i];
radians += SPLICE;
}
while(1)
{
j = j% COUNT;
startTime = GetTickCount();
while(GetTickCount() - startTime < busySpan[j]) ;
Sleep(idalSpan[j]);
j++;
}
return 0;
}