Triangles

Arithmetics on a vector with its own transpose results in a matrix.

Cropping selects a triangular section.

image0


import numpy as np
from PIL import Image

x = np.arange(200).reshape(200, 1)

a = x + x.T
a[a <= 200] = 1
a[a > 200] = 0
a *= 200

im = Image.fromarray(a.astype(np.uint8))
im.save('corner.png')

Hints

  • the code only works for triangles with two edges parallel to the axes of the coordinate system

  • the instruction a.T transposes the array

  • the conditional assignment allows you to set only a part of the values in an array


Challenge:

Create multiple straight-edge triangles.

image1