具体版本为Ubuntu 20.04。

程序如下:

#include

#include

#include

#include

void usleep(__int64 usec)

{

HANDLE timer;

LARGE_INTEGER ft;

ft.QuadPart = -(10 * usec);

timer = CreateWaitableTimer(NULL, TRUE, NULL);

SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);

WaitForSingleObject(timer, INFINITE);

CloseHandle(timer);

}

int main() {

float A = 0, B = 0;

float i, j;

int k;

float z[1760];

char b[1760];

printf("\x1b[2J");

for (;;) {

memset(b, 32, 1760);

memset(z, 0, 7040);

for (j = 0; j < 6.28; j += 0.07) {

for (i = 0; i < 6.28; i += 0.02) {

float c = sin(i);

float d = cos(j);

float e = sin(A);

float f = sin(j);

float g = cos(A);

float h = d + 2;

float D = 1 / (c * h * e + f * g + 5);

float l = cos(i);

float m = cos(B);

float n = sin(B);

float t = c * h * g - f * e;

int x = 40 + 30 * D * (l * h * m - t * n);

int y = 12 + 15 * D * (l * h * n + t * m);

int o = x + 80 * y;

int N = 8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n);

if (22 > y && y > 0 && x > 0 && 80 > x && D > z[o]) {

z[o] = D;

b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];

}

}

}

printf("\x1b[H");

for (k = 0; k < 1761; k++) {

putchar(k % 80 ? b[k] : 10);

A += 0.00004;

B += 0.00002;

}

usleep(30000);

}

return 0;

}

直接暴力编译必然报错如下:

将其更换为#include ,并删除如下函数:

void usleep(__int64 usec)

{

HANDLE timer;

LARGE_INTEGER ft;

ft.QuadPart = -(10 * usec);

timer = CreateWaitableTimer(NULL, TRUE, NULL);

SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);

WaitForSingleObject(timer, INFINITE);

CloseHandle(timer);

}

再次编译:

g++ donut.cpp

运行以下看看效果吧?就不做动图了,这个案例只为了说明算法是不分平台的,学习算法对于编程而言才是最重要的!

#include

#include

#include

#include

int main() {

float A = 0, B = 0;

float i, j;

int k;

float z[1760];

char b[1760];

printf("\x1b[2J");

for (;;) {

memset(b, 32, 1760);

memset(z, 0, 7040);

for (j = 0; j < 6.28; j += 0.07) {

for (i = 0; i < 6.28; i += 0.02) {

float c = sin(i);

float d = cos(j);

float e = sin(A);

float f = sin(j);

float g = cos(A);

float h = d + 2;

float D = 1 / (c * h * e + f * g + 5);

float l = cos(i);

float m = cos(B);

float n = sin(B);

float t = c * h * g - f * e;

int x = 40 + 30 * D * (l * h * m - t * n);

int y = 12 + 15 * D * (l * h * n + t * m);

int o = x + 80 * y;

int N = 8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n);

if (22 > y && y > 0 && x > 0 && 80 > x && D > z[o]) {

z[o] = D;

b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];

}

}

}

printf("\x1b[H");

for (k = 0; k < 1761; k++) {

putchar(k % 80 ? b[k] : 10);

A += 0.00004;

B += 0.00002;

}

usleep(30000);

}

return 0;

}

本文同步分享在 博客“zhangrelay”(CSDN)。

如有侵权,请联系 [email protected] 删除。

本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

技术
今日推荐
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信