Skip to content
Snippets Groups Projects
Select Git revision
  • 58f02fed0c7348a8cf24423ebeea1bfd81bfc746
  • master default protected
2 results

Spyder-weai.desktop

Blame
  • TEST_grafic.py 1.84 KiB
    # -*- coding: utf-8 -*-
    """
    Created on Tue Jun  6 08:42:32 2023
    
    @author: Basti-Uni
    """
    
    #%% imports
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import matplotlib.patches as patches
    from matplotlib.patches import Circle
    import matplotlib.image as img
    
    # not impoertend imports
    import time
    import random
    
    #%% classes
    
    
    background_url = './Bilder/Strecke_02.jpg'
    background = img.imread(background_url)
    #background = background.resize((1500, 800))
    fig = plt.figure()
    ax = fig.add_subplot(111)
    live_image = ax.imshow(background)
    ax.set_xlim(0,4032)
    ax.set_ylim(3024,0)
    plt.show(block=False)
    
    #%%
    for x in range(10):
        ax.plot([(x*100)+550, 500], [800, 2000], color='red', linewidth=10)
        fig.canvas.draw_idle()
        fig.canvas.flush_events()
        time.sleep(1)
        
    #%%
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib.animation import FuncAnimation
    
    # Bild laden
    image_path = './Bilder/Strecke_02.jpg'
    image = plt.imread(image_path)
    
    # Start- und Endposition der Linie
    start_x, start_y = 100, 100
    end_x, end_y = 400, 400
    
    # Anzahl der Schritte
    num_steps = 100
    
    # Zwischenwerte für die Linienposition berechnen
    x_values = np.linspace(start_x, end_x, num_steps)
    y_values = np.linspace(start_y, end_y, num_steps)
    
    # Funktion zum Zeichnen des Bildes und der Linie
    def draw_image(frame):
        plt.imshow(image)
        plt.plot([x_values[frame], y_values[frame]], [x_values[frame+1], y_values[frame+1]], color='red', linewidth=2)
        plt.axis('off')
    
    # Funktion zum Aktualisieren der Linienposition
    def update_line(frame):
        # Bild anzeigen und Linie zeichnen
        plt.cla()  # Vorherigen Plot löschen
        draw_image(frame)
    
    # Animation erstellen
    fig = plt.figure()
    animation = FuncAnimation(fig, update_line, frames=num_steps-1, repeat=True, interval=50)  # 50 Millisekunden Verzögerung zwischen den Schritten
    
    # Bild anzeigen
    plt.show()