如何在ubuntu上写一个类似sl跑火车指令,“跑甜甜圈”
首先创建.c文件
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <unistd.h>int main() {float A = 0, B = 0;float i, j;int k;float z[1760]; //array to store particular value wjhich will be used for creating the shadown/back image of the doughnutchar b[1760]; //array of characters to stor the components that will make up the doughnutprintf("\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; // This defines the speed at which the doughnut will be rotating on 2D axisB += 0.00002; // This will determine the rotation on t5he 3rd axis }usleep(100000); //used for time delay}return 0;
}
将文件保存到一个你知道的路径,并且进行编译。
gcc ttq.c -lm -o ttq
因为用来math.h所以要加一个-lm来链接库,不然会报错。
接下来就是自定义命令,当然也可以直接调用可执行文件,但需要在指定目录下或者在终端输入目录,不是很方便。
在.alias中加入你所要自定义的命令
sudo vim /home/.alias
sudo vim /home/.bashrc
加入如下代码,使你的自定义名生效
# Aliases
if [ -f ~/.alias ]; then. ~/.alias
fi
source /home/.alias
source /home/.bashrc
最后在任何路径下输入,你所定义的命令就可以看到一个‘跑’起来的甜甜圈