参考资料:
Donut-shaped C code that generates a 3D spinning donut
如题,当初会来撰写这篇参考笔记,只是因为在找到了 video-to-ascii 这个 Python 的套件的时候,刚好在 YT 上看到了,可以在终端机(Terminal)上产生一个 3D 旋转甜甜圈的程序的介绍影片,於是乎,就在自己实际操作过之後,顺便把自己的实际操作过程撰写成笔记,然後也顺便录了,在 Ubuntu 上执行这个程序码的实测效果的影片,并把在 YT 上搜寻到的其他类似的影片教学,整理并放在了这篇参考笔记的最後面,有兴趣的人,可以拉到最底下看看w。
特此撰写本篇文章作为纪录文件,用以方便後续有需要的时候,可以快速的重复查阅,虽然後面比较没有什麽机会再用到,但也算是一个还不错的经验。
可以在命令列产生一个 3D 旋转的甜甜圈。
C 程序码来源影片:
donut_deobfuscated.c
#include <stdio.h>
#include <math.h>
#include <string.h>
#define HIDE_CURSOR() printf("\033[?25l")
int main() {
float A = 0, B = 0;
float i, j;
int k;
float z[1760];
char b[1760];
HIDE_CURSOR();
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];
}
}
}
HIDE_CURSOR();
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;
}
P.S. 在 Windows 10 上执行会比较卡,原因未知,建议用 linux 执行会比较顺。
可以用 cmder,执行指令:
gcc -o donut donut_deobfuscated.c -lm && donut.exe
执行指令:
gcc -o donut donut_deobfuscated.c -lm && ./donut
Python/Pygame 3D ASCII Spinning Donut Tutorial:
Python/Pygame 3D ASCII Spinning Earth Tutorial:
<<: Day 15:Remove Duplicates from linked list
在上篇有提到用 Selenium + WebDriver 就可以让程序帮你自动发文, 但有试过的朋友...
本节是以 Golang 上游 7ee4c1665477c6cf574cb9128deaf9d009...
从下面截图可以看得出来,原本的画面设计大部分按钮图案是灰色的,有些地方的文字也是非全黑的颜色。这在一...
Day 18: LeetCode 322. Coin Change Tag: follow John...
这个得上一篇在https://ithelp.ithome.com.tw/articles/10257...