An raycasting program for the numworks
from kandinsky import * from math import * width, height = 320, 222 # NumWorks screen dimensions def color_map(index): colors = [ color(128, 128, 128), # Light gray color(0, 0, 255), # Blue color(255, 0, 0), # Red color(0, 0, 0), # Black color(255, 0, 255), # Magenta color(0, 255, 0), # Green color(255, 128, 0), # Orange color(128, 64, 0), # Brown color(0, 255, 255), # Cyan color(128, 128, 255), # Light blue color(255, 255, 0), # Yellow color(255, 255, 255), # White color(128, 128, 128), # Light gray color(64, 64, 64) # Gray ] return colors[min(index, len(colors) - 1)] list1 = [12, 24, 23, 22, 21, 20] for y in range(0, height, 2): b = ((height / 2) - y) / height for x in range(0, width, 2): a = (x - (width / 2)) / height e = a**2 + b**2 + 1 f = 2*b - 12 h = 34.75 d = f**2 - (4*e*h) t = 1 / b if b != 0 else float('inf') u = a * t v = t c = abs(floor(u) + floor(v)) % 2 l = 12 m = 12 c = 12 - (1 if t > 0 else 0) * (c + 1) if d >= 0: t = -(f - sqrt(d)) / (2*e) i = a*t j = -b*t - 1 k = 6 - t m = j / 2 if m > 0: m = floor(10 * m) l = list1[min(floor(m / 2), len(list1) - 1)] m = list1[min(floor(m / 2 + 0.5), len(list1) - 1)] else: m = 12 list3 = [i / 1.5, j / 2, k / 1.5] list2 = [-a, b, 1] s = 10**308.25 * sum([a*b for a,b in zip(list3, list2)]) list4 = [a*s - b for a,b in zip(list3, list2)] p, q, r = list4 t = (j + 2) / q if q != 0 else float('inf') if t > 0: u = p*t + i v = r*t + 6 - k c = 11 - (abs(floor(u) + floor(v)) % 2) else: c = 12 else: if t > 0: e = 1 f = 4 h = u**2 + v**2 - 12*v + 37.75 d = f**2 - 4*e*h l = 12 if d >= 0 else c m = l c = color_map(int(c)) l = color_map(int(l)) m = color_map(int(m)) if y > 125/170 * height and (c == color(255, 0, 0) or c == color(0, 0, 255)): c = color(0, 0, 0) set_pixel(width - x - 1, height - y - 1, c) set_pixel(width - x - 1, height - y - 2, l) set_pixel(width - x - 2, height - y - 1, m) set_pixel(width - x - 2, height - y - 2, c)