Untitled
unknown
python
2 years ago
1.4 kB
6
Indexable
print("\033c") import numpy as np import matplotlib.pyplot as plt # The user informs the coordinates of the two points for the line. x1 = 100 y1 = 100 x2 = 400 y2 = 400 #The user decides the point diameter pd = 20 #Calculate the half diameter hd = int(pd/2) #The user decides the line width lw = 10 #Calculate the half line width hw = int(lw/2) #Setting the size of the canvas row = int(500) col = int(500) print('col, row =', col, ',', row) #Preparing the black canvas Gambar = np.zeros(shape=(row, col, 3), dtype=np.uint8) # Gambar[:, :, :] = 255 # Mengubah layar menjadi putih # Looping membuat Titik berbentuk Kotak # for i in range(y1-hd, y1+hd+1): #start : 95, stop: 106 # for j in range(x1-hd, x1+hd+1): #start : 95, stop: 106 # Gambar[i, j, 0] = 255 # # for i in range(y2-hd, y2+hd+1): #start : 95, stop: 106 # for j in range(x2-hd, x2+hd+1): #start : 95, stop: 106 # Gambar[i, j, 0] = 255 #Coloring the two points red(loop, condition, comparation) for i in range(x1-hd, x1+hd+1): for j in range(y1-hd, y1+hd+1): if( (i-x1)**2 + (j-y1)**2) < hd ** 2: Gambar[j, i, :] = 0 Gambar[j, i, 0] = 255 for i in range(x2-hd, x2+hd+1): for j in range(y2-hd, y2+hd+1): if( (i-x2)**2 + (j-y2)**2) < hd ** 2: Gambar[j, i, :] = 0 Gambar[j, i, 0] = 255 plt.figure() plt.imshow(Gambar) plt.show()
Editor is loading...