Code
img = load_image
x,y = pixel_coordinates(img)
show(img, map_x, map_y)
The pseudocode for the texture mapping is below.
Getting UV-coordinates right is hard. The UV-coordinates are the coordinates of the texture image that correspond to each vertex of the 3D model. If the UV-coordinates are wrong, the texture will be distorted or not appear at all. This is what it looks like when they are off:
Or this one where the V coordinate is linearly increasing
Below we have the UV-coordinates almost right, but the seam is blurry. This is a ‘seam crosser’ problem. The UV-coordinates are in [0,1]x[0,1] so on the torus 0.9 is actually close to 0.1, but the texture mapping doesn’t know that, so it stretches the texture across the seam. This can be fixed by snapping the UV-coordinates to 0 or 1 when they are close to the seam, but this can cause other problems if not done carefully.