КомпГр_ЛР6_Заболотников_Петрова_Романова_9373
.pdfext = 16.0/9.0 H = 150
W = int(H*ext) maxval = 255
ppm_header = f'P6\n{W} {H}\n{maxval}\n' my_file = 'blue_red_example1.ppm'
with open(my_file, 'wb') as f: f.write(bytearray(ppm_header, 'ascii'))
for y in range(H):
for x in range(W):
c = trace(len(spheres) - 1 , vect3(0, 1, 5), unit_vector(vect3(x - W / 2, H / 2.0 - y, -H)), lights, spheres)
pixel_col = vect3(int(min(1.0, c.x()) * 255), int(min(1.0, c.y())
* 255),
int(min(1.0, c.z()) * 255)) write_color(my_file, pixel_col)
window = Tk()
window.geometry(f"{W + 100}x{H + 100}+500+500")
canvas = Canvas(window, width=W, height=H, bg="#000000") canvas.pack()
img = PhotoImage(file=my_file)
canvas.create_image((0, 0), image=img, state="normal", anchor='nw') window.mainloop()
21