Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Windows
- #include <stdio.h>
- #include <string.h>
- #ifdef Windows
- #include <windows.h>
- HANDLE hCon;
- void Ansi_ClearScreen() {
- hCon=GetStdHandle(STD_OUTPUT_HANDLE); system("cls");
- CONSOLE_CURSOR_INFO tCur = {.dwSize=8 , .bVisible = FALSE };
- SetConsoleCursorInfo( hCon , &tCur );
- }
- void Ansi_MoveHome() { COORD tHome = { .X=1 , .Y=1 }; SetConsoleCursorPosition(hCon,tHome); }
- #else
- void Ansi_ClearScreen() { printf("\x1b[2j"); }
- void Ansi_MoveHome() { printf("\x1b[H"); }
- #endif
- int k;
- double sin(),cos();
- int main(){
- float A=0,B=0,i,j,z[1760];
- char buffer[1761]; buffer[1760]=0;
- Ansi_ClearScreen();
- for(;;) {
- memset(buffer,32,1760);
- memset(z,0,1760*sizeof(float));
- for( j=0 ; j<6.28 ; j+=0.07 ) {
- for( i=0 ; i<6.28 ; i+=0.02 ) {
- //calc pixel
- float c=sin(i) , d=cos(j) , e=sin(A) , f=sin(j) , g=cos(A);
- float h=d+2 , D=1/(c*h*e+f*g+5) , l=cos(i);
- float m=cos(B) , n=sin(B) , t=c*h*g-f*e;
- int x=40+30*D*(l*h*m-t*n) , y=12+15*D*(l*h*n+t*m);
- int o=x+80*y , N=8*((f*e-c*d*g)*m-c*d*e-f*g-l*d*n);
- //plot pixel and Z order
- if ( ((unsigned)y)<22 && ((unsigned)x)<80 && D>z[o] ) {
- z[o] = D ; buffer[o] = ".,-~:;=!*#$@"[ N>0 ? N : 0 ];
- }
- }
- }
- //rotate donut
- A+=.04 ; B+= 0.02;
- //display buffer
- Ansi_MoveHome();
- for( k=0; k<1761 ; k+= 80 ) { buffer[k] = 10; }
- puts(buffer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement