From 3c568ac93aedf5fe7172b5a9fef12be2ddd1ec97 Mon Sep 17 00:00:00 2001 From: russian_proger Date: Tue, 15 Apr 2025 13:01:52 +0300 Subject: [PATCH] fix: plot axis --- random_pilot.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/random_pilot.py b/random_pilot.py index 4332b91..3058c6a 100644 --- a/random_pilot.py +++ b/random_pilot.py @@ -5,6 +5,8 @@ from time import sleep # from scipy import from matplotlib import pyplot as plt +random.seed(1) + class RandomPilot(): angle: float @@ -27,18 +29,27 @@ class RandomPilot(): def _test(): randomPilot = RandomPilot() point = [0, 0] - iter_count = 250 + iter_count = 100 points = [point.copy()] - plt.axis([-100, 100, -100, 100]) - # plt. + for i in range(iter_count): dx, dy = randomPilot.step() prev_point = point.copy() point[0] += dx point[1] += dy points.append(point.copy()) - plt.plot(*zip(*points[-2:]), color='#5e5') - plt.pause(0.025) + + coords = list(zip(*points)) + padding = 5 + plt.axis([ + min(coords[0]) - padding, max(coords[0]) + padding, + min(coords[1]) - padding, max(coords[1]) + padding]) + + for i in range(iter_count): + plt.plot(coords[0][i:i+2], coords[1][i:i+2], color='#5e5') + plt.pause(0.05) + + sleep(1) if __name__ == '__main__':