add exercise sheet 8 solution plotter script
This commit is contained in:
parent
4369e246bd
commit
996700bec9
@ -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()
|
Loading…
Reference in New Issue
Block a user