Vsevolod Levitan преди 1 година
родител
ревизия
d35e1df68b
променени са 1 файла, в които са добавени 25 реда и са изтрити 0 реда
  1. 25 0
      gradient/main.py

+ 25 - 0
gradient/main.py

@@ -0,0 +1,25 @@
+import numpy as np
+import matplotlib.pyplot as plt
+
+def lerp(v0, v1, t):
+    return (1 - t) * v0 + t * v1
+
+size = 100
+image = np.zeros((size, size, 3), dtype="uint8")
+
+color1 = np.array([255, 128, 0])
+color2 = np.array([0, 128, 255])
+
+x = np.linspace(0, 1, size)
+y = np.linspace(0, 1, size)
+
+x_grid, y_grid = np.meshgrid(x, y)
+
+t = (x_grid + y_grid) / 2
+
+colors = lerp(color2, color1, t[..., np.newaxis])
+image[:, :, :] = colors.astype(np.uint8)
+
+plt.figure(1)
+plt.imshow(image)
+plt.show()