Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CA-DONUT! Coded By nonogamer9
- # An Port Of Donut.c For The Casio PRIZM!
- import math
- import casioplot as cp
- theta_spacing = 0.3
- phi_spacing = 0.1
- R1, R2 = 1, 2
- K2 = 5
- screen_width, screen_height = 80, 60
- K1 = screen_width * K2 * 3 / (8 * (R1 + R2))
- TWOPI = 2 * math.pi
- THETA_STEPS = int(TWOPI / theta_spacing)
- PHI_STEPS = int(TWOPI / phi_spacing)
- HALF_WIDTH = screen_width // 2
- HALF_HEIGHT = screen_height // 2
- sin_table = [math.sin(i * theta_spacing) for i in range(THETA_STEPS)]
- cos_table = [math.cos(i * theta_spacing) for i in range(THETA_STEPS)]
- def render_frame(A, B):
- cosA, sinA = math.cos(A), math.sin(A)
- cosB, sinB = math.cos(B), math.sin(B)
- cp.clear_screen()
- zbuffer = [[0] * screen_height for _ in range(screen_width)]
- for theta in range(THETA_STEPS):
- costheta = cos_table[theta]
- sintheta = sin_table[theta]
- for phi in range(PHI_STEPS):
- cosphi = math.cos(phi * phi_spacing)
- sinphi = math.sin(phi * phi_spacing)
- circlex = R2 + R1 * costheta
- circley = R1 * sintheta
- x = circlex * (cosB * cosphi + sinA * sinB * sinphi) - circley * cosA * sinB
- y = circlex * (sinB * cosphi - sinA * cosB * sinphi) + circley * cosA * cosB
- z = K2 + cosA * circlex * sinphi + circley * sinA
- ooz = 1 / z
- xp = int(HALF_WIDTH + K1 * ooz * x)
- yp = int(HALF_HEIGHT - K1 * ooz * y)
- if 0 <= xp < screen_width and 0 <= yp < screen_height:
- L = cosphi * costheta * sinB - cosA * costheta * sinphi - sinA * sintheta + cosB * (cosA * sintheta - costheta * sinA * sinphi)
- if L > 0 and ooz > zbuffer[xp][yp]:
- zbuffer[xp][yp] = ooz
- brightness = int(L * 255)
- cp.set_pixel(xp, yp, (brightness, brightness, brightness))
- cp.show_screen()
- A, B = 1.0, 1.0
- frame_count = 0
- while True:
- render_frame(A, B)
- A += 0.08
- B += 0.03
- frame_count += 1
- if frame_count % 5 == 0:
- for _ in range(10000):
- pass
- if frame_count >= 200:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement