这个只能是单核CPU,多核心CPU做不到这个效果,主要用到了Sin Cos函数,和Sleep函数做出的效果。
上代码!
- //正弦波曲线
- double time = 0.0;
- double runtime;
- int c;
-
- while (1)
- {
- runtime = 100 + 100 * sin(time);
- time += 0.05;
- c = clock();
-
- while (clock() - c < runtime);
-
- Sleep(200 - runtime);
- }
-
-
- //横线
- while (1)
- {
- int start = clock();
- while (clock() - start < 10);
- Sleep(10);
- }
- //单向斜线
- int k = -1;
- int c = 0;
- int runtime;
- while (1)
- {
- runtime = 100 + k * (c++ % 101);
-
- int start = clock();
- while (clock() - start < runtime);
- Sleep(100 - runtime);
- }
-
-
- //双向斜线
- int k = 1;
- int c = 0;
- int runtime;
- while (1)
- {
- runtime = (int)(c < 100) * (100 + -1 * (c % 100)) + (int)(c > 100) * (c - 100);
- c = c++ % 200;
- int start = clock();
- while (clock() - start < runtime);
-
- Sleep(100 - runtime);
- }