Advertisement
Mysoft

Untitled

Apr 30th, 2022
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define Windows
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #ifdef Windows
  6.   #include <windows.h>
  7.     HANDLE hCon;
  8.   void Ansi_ClearScreen() {
  9.       hCon=GetStdHandle(STD_OUTPUT_HANDLE); system("cls");
  10.         CONSOLE_CURSOR_INFO tCur = {.dwSize=8 , .bVisible = FALSE };
  11.         SetConsoleCursorInfo( hCon , &tCur );
  12.     }
  13.   void Ansi_MoveHome()    { COORD tHome = { .X=1 , .Y=1 }; SetConsoleCursorPosition(hCon,tHome); }
  14. #else
  15.   void Ansi_ClearScreen() { printf("\x1b[2j"); }
  16.   void Ansi_MoveHome()    { printf("\x1b[H"); }
  17. #endif
  18.  
  19. int k;
  20. double sin(),cos();
  21. int main(){
  22.   float A=0,B=0,i,j,z[1760];
  23.     char buffer[1761]; buffer[1760]=0;
  24.    
  25.     Ansi_ClearScreen();
  26.    
  27.     for(;;) {
  28.      
  29.         memset(buffer,32,1760);
  30.         memset(z,0,1760*sizeof(float));
  31.        
  32.     for( j=0 ; j<6.28 ; j+=0.07 ) {
  33.             for( i=0 ; i<6.28 ; i+=0.02 ) {
  34.                
  35.                 //calc pixel
  36.                 float c=sin(i) , d=cos(j) , e=sin(A) , f=sin(j) , g=cos(A);
  37.                 float h=d+2 , D=1/(c*h*e+f*g+5) , l=cos(i);
  38.                 float m=cos(B) , n=sin(B) , t=c*h*g-f*e;
  39.                 int x=40+30*D*(l*h*m-t*n) , y=12+15*D*(l*h*n+t*m);
  40.                 int o=x+80*y , N=8*((f*e-c*d*g)*m-c*d*e-f*g-l*d*n);
  41.                
  42.                 //plot pixel and Z order
  43.                 if ( ((unsigned)y)<22 && ((unsigned)x)<80 && D>z[o] ) {
  44.                   z[o] = D ; buffer[o] = ".,-~:;=!*#$@"[ N>0 ? N : 0 ];
  45.                 }
  46.                
  47.             }
  48.         }
  49.        
  50.         //rotate donut
  51.         A+=.04 ; B+= 0.02;                 
  52.  
  53.         //display buffer
  54.         Ansi_MoveHome();
  55.         for( k=0;  k<1761 ; k+= 80 ) { buffer[k] = 10; }
  56.         puts(buffer);      
  57.        
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement