Advertisement
mig_eu

donut2

May 13th, 2021 (edited)
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5.  
  6. #define R(mul, shift, x, y) \
  7. _= x; \
  8. x -= mul * y >> shift; \
  9. y += mul*_ >> shift; \
  10. _ = 3145728 - x * x - y * y >> 11; \
  11. x = x *_ >> 10; \
  12. y = y *_ >> 10;
  13.  
  14. int8_t b[1760], z[1760];
  15.  
  16. void main() {
  17.  
  18.     int sA = 1024, cA = 0,sB = 1024,cB = 0, _;
  19.     for (;;) {
  20.        
  21.         memset(b, 32, 1760);  // text buffer
  22.         memset(z, 127, 1760);   // z buffer
  23.        
  24.         int sj = 0, cj = 1024;
  25.        
  26.         for (int j = 0; j < 90; j++) {
  27.            
  28.             int si = 0, ci = 1024;  // sine and cosine of angle i
  29.            
  30.             for (int i = 0; i < 324; i++) {
  31.                 int R1 = 1, R2 = 2048, K2 = 5120 * 1024;
  32.  
  33.                 int x0 = R1 * cj + R2,
  34.                     x1 = ci * x0 >> 10,
  35.                     x2 = cA * sj >> 10,
  36.                     x3 = si * x0 >> 10,
  37.                     x4 = R1 * x2 - (sA * x3 >> 10),
  38.                     x5 = sA * sj >> 10,
  39.                     x6 = K2 + R1 * 1024 * x5 + cA * x3,
  40.                     x7 = cj * si >> 10,
  41.                     x = 40 + 30*(cB * x1 - sB * x4) / x6,
  42.                     y = 12 + 15 * (cB * x4 + sB * x1) / x6,
  43.                     N = (-cA * x7 - cB * ((-sA * x7 >> 10) + x2) - ci * (cj * sB >> 10) >> 10) - x5 >> 7;
  44.  
  45.                 int o = x + 80 * y;
  46.                 int8_t zz = (x6 - K2) >> 15;
  47.                 if (22 > y && y > 0 && x > 0 && 80 > x && zz < z[o]){
  48.                    
  49.                     z[o] = zz;
  50.                    
  51.                     b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];
  52.                 }
  53.                
  54.                 R(5, 8, ci, si)  // rotate i
  55.             }
  56.    
  57.             R(9, 7, cj, sj)  // rotate j
  58.        
  59.         }
  60.        
  61.         for (int k = 0; 1761 > k; k++){
  62.            
  63.             putchar(k % 80 ? b[k] : 10);
  64.         }
  65.        
  66.         R(5, 7, cA, sA);
  67.         R(5, 8, cB, sB);
  68.         usleep(15000);
  69.         printf("\x1b[23A");
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement