forked from TinkeringPenguin/donut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonut.c
61 lines (57 loc) · 1.66 KB
/
donut.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
int k;
double sin() ,cos();
// main
int main() {
float a=0, b=0, i, j, z[1760];
char screen[1760];
printf("\x1b[2J");
while (1) {
// init arrays
for (int la=0;la<1760;la++) {
z[la] = 0;
}
for (int la=0;la<1760;la++) {
screen[la] = ' ';
}
for(j=0; 6.28>j; j+=0.07) {
for(i=0; 6.28 >i; i+=0.02) {
float sini=sin(i),
cosj=cos(j),
sinA=sin(a),
sinj=sin(j),
cosA=cos(a),
cosj2=cosj+2,
mess=1/(sini*cosj2*sinA+sinj*cosA+5),
cosi=cos(i),
cosB=cos(b),
sinB=sin(b),
t=sini*cosj2*cosA-sinj* sinA;
int x=40+30*mess*(cosi*cosj2*cosB-t*sinB),
y= 12+15*mess*(cosi*cosj2*sinB +t*cosB),
o=x+80*y,
N=8*((sinj*sinA-sini*cosj*cosA)*cosB-sini*cosj*sinA-sinj*cosA-cosi *cosj*sinB);
// debug
// printf("%d %d %d %d\n",x,y,o,N);
if(22>y&&y>0&&x>0&&80>x&&mess>z[o]){
z[o]=mess;
if (N>0) {
screen[o] = ".,-~:;=!*#$@"[N];
} else {
screen[o] = '.';
}
}
}
}
// prints
printf("\x1b[d");
for(k=0; 1761>k; k++)
if (k%80==0) {
putchar(10);
} else {
putchar(screen[k]);
}
a+=0.04;
b+= 0.02;
}
return 0;
}