Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys , math
- printer = lambda o: \
- (sys.stdout. \
- write("\x1b[H") and \
- [sys.stdout.write \
- (str("".join(line)) + \
- "\n") for line in o]);
- def render(A, B):
- cosA, cosB, sinA, \
- sinB = math.cos(A), math \
- .cos(B), math.sin(A), \
- math.sin( B); \
- output, zbuffer =[[' '
- for l in range(screen_width)] for _
- in range(screen_height)], [[0 for
- l in range(screen_width)] for _
- in range(screen_height)]; theta = 0;
- while theta < math.pi:
- theta +=theta_spacing; \
- costheta,\
- sintheta = math.cos(theta),\
- math.sin(theta); phi = 0
- while phi < (2*math.pi):
- phi += phi_spacing
- cosphi, sinphi =\
- math.cos( \
- phi ),\
- math.sin(phi);
- cx, cy = R2 + \
- R1*costheta,R1 *\
- sintheta; x = \
- cx* (cosB *\
- cosphi +sinA*\
- sinB*sinphi )-cy*\
- cosA*sinB; y = cx\
- *(sinB * \
- cosphi - sinA* \
- cosB *sinphi)+cy* \
- cosA*cosB
- z = K2+cosA *cx* \
- sinphi + cy* sinA;\
- ooz = 1/z;\
- xp = int( \
- screen_width/2 + \
- K1*ooz *x);\
- yp = int( \
- screen_height/2 -
- K1 *ooz*y);\
- L = cosphi* \
- costheta*sinB- \
- cosA*costheta* \
- sinphi-sinA* \
- sintheta+cosB* (
- cosA*sintheta -
- costheta*sinA *
- sinphi )
- if L > 0 and (ooz>
- zbuffer[yp][xp]) :
- zbuffer[yp] \
- [xp]=ooz;output \
- [yp] [xp] =\
- ".,-~:;=!*#$@"[int(
- L*8)]
- printer(output)
- theta_spacing = 0.07; \
- phi_spacing = 0.02; \
- R1, R2, K2 = 1,\
- 2, 5; screen_width = \
- 80; screen_height = 80; \
- K1 = screen_width * \
- K2*3/(8*(R1+R2));
- A, B = 1, 1
- while True:
- A += theta_spacing; \
- B + phi_spacing
- render(A,B)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement