Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # NUM-DONUT! Coded By nonogamer9
- # An Port Of Donut.c For The numworks!
- import math
- import kandinsky as kd
- import time
- 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))
- def render_frame(A, B):
- cosA, sinA = math.cos(A), math.sin(A)
- cosB, sinB = math.cos(B), math.sin(B)
- kd.fill_rect(0, 0, screen_width, screen_height, kd.color(0, 0, 0))
- zbuffer = [[0] * screen_height for _ in range(screen_width)]
- for theta in range(int(2 * math.pi / theta_spacing)):
- costheta = math.cos(theta * theta_spacing)
- sintheta = math.sin(theta * theta_spacing)
- for phi in range(int(2 * math.pi / phi_spacing)):
- 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(screen_width / 2 + K1 * ooz * x)
- yp = int(screen_height / 2 - 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)
- kd.set_pixel(xp, yp, kd.color(brightness, brightness, brightness))
- A, B = 1.0, 1.0
- while True:
- render_frame(A, B)
- A += 0.08
- B += 0.03
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement