Last active
July 24, 2020 13:19
-
-
Save omaraflak/f81af3f734e54c94aa6221593efc7ee6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def normalize(vector): | |
return vector / np.linalg.norm(vector) | |
width = 300 | |
height = 200 | |
camera = np.array([0, 0, 1]) | |
ratio = float(width) / height | |
screen = (-1, 1 / ratio, 1, -1 / ratio) # left, top, right, bottom | |
image = np.zeros((height, width, 3)) | |
for i, y in enumerate(np.linspace(screen[1], screen[3], height)): | |
for j, x in enumerate(np.linspace(screen[0], screen[2], width)): | |
pixel = np.array([x, y, 0]) | |
origin = camera | |
direction = normalize(pixel - origin) | |
# image[i, j] = ... | |
print("progress: %d/%d" % (i + 1, height)) | |
plt.imsave('image.png', image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment