Advertisement
Guest User

snakes eat donuts

a guest
Nov 19th, 2020
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import sys  ,   math
  2. printer = lambda o: \
  3.    (sys.stdout. \
  4.        write("\x1b[H") and  \
  5.           [sys.stdout.write \
  6.       (str("".join(line)) + \
  7.    "\n") for line in o]);
  8. def render(A, B):
  9.  cosA, cosB, sinA, \
  10.   sinB = math.cos(A), math \
  11.    .cos(B), math.sin(A), \
  12.      math.sin(        B); \
  13.        output, zbuffer =[[' '
  14.      for l in range(screen_width)] for _
  15.      in range(screen_height)], [[0  for
  16.     l in range(screen_width)] for _
  17.    in range(screen_height)]; theta = 0;
  18.  while theta < math.pi:
  19.   theta +=theta_spacing; \
  20.    costheta,\
  21.     sintheta = math.cos(theta),\
  22.    math.sin(theta); phi = 0
  23.   while phi < (2*math.pi):
  24.    phi += phi_spacing
  25.    cosphi, sinphi =\
  26.      math.cos(    \
  27.      phi         ),\
  28.     math.sin(phi);
  29.    cx, cy =   R2   + \
  30.   R1*costheta,R1     *\
  31.  sintheta; x =  \
  32. cx*  (cosB      *\
  33.  cosphi     +sinA*\
  34.   sinB*sinphi )-cy*\
  35.    cosA*sinB; y = cx\
  36.   *(sinB     *    \
  37. cosphi   - sinA*   \
  38.  cosB  *sinphi)+cy* \
  39.   cosA*cosB
  40.    z = K2+cosA  *cx*  \
  41.     sinphi + cy*  sinA;\
  42.      ooz =   1/z;\
  43.     xp = int(     \
  44.   screen_width/2 + \
  45. K1*ooz       *x);\
  46.  yp = int(        \
  47.   screen_height/2  -
  48.    K1       *ooz*y);\
  49.     L = cosphi*      \
  50.      costheta*sinB-   \
  51.       cosA*costheta*   \
  52.      sinphi-sinA*     \
  53.     sintheta+cosB*   (
  54.    cosA*sintheta    -
  55.   costheta*sinA    *
  56.   sinphi          )
  57.    if L > 0 and (ooz>
  58.    zbuffer[yp][xp]) :
  59.     zbuffer[yp]    \
  60.     [xp]=ooz;output \
  61.     [yp]       [xp] =\
  62.     ".,-~:;=!*#$@"[int(
  63.     L*8)]
  64.  printer(output)
  65. theta_spacing = 0.07; \
  66.  phi_spacing = 0.02;   \
  67.   R1,        R2, K2 = 1,\
  68.    2, 5; screen_width =  \
  69.  80; screen_height = 80;  \
  70.   K1 = screen_width * \
  71.    K2*3/(8*(R1+R2));
  72. A, B = 1, 1
  73. while True:
  74.  A += theta_spacing; \
  75. B + phi_spacing
  76.  render(A,B)
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement