add exercise sheet 8 solution plotter script

This commit is contained in:
Akbar Rahman 2024-01-17 15:50:25 +00:00
parent 4369e246bd
commit 996700bec9
Signed by: alvierahman90
GPG Key ID: 6217899F07CA2BDF

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
#
# Akbar Rahman
import matplotlib.pyplot as plt
x0, y0 = (5, 5)
x1, y1 = (18, 16)
dx = x1 - x0
dy = y1 - x0
D = 2 * dy - dx
y = y0
print(f"{dx=} {dy=} {D=} {y=}")
xs = []
ys = []
for x in range(x0, x1 + 1):
# moveto(x, y)
if D > 0:
y += 1
D -= 2 * dx
D += 2 * dy
print(f"{D=}\t{x=}\t{y=}")
xs.append(x)
ys.append(y)
print(f"{xs=}")
print(f"{ys=}")
plt.plot(xs, ys)
plt.show()