import pygame import numpy as np import matplotlib.pyplot as plt from particle import Particle from sensor import Sensor from slider import Slider pygame.init() SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SENSOR_DISTANCE = 200 y_lim = 40000 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) sensor = Sensor(width = 50, distance = SENSOR_DISTANCE, space = 300) silica = Particle(speed = 1, size = 60, perm = 4) time = .1 time_data = [] volume_data = [] plt.ion() fig, ax = plt.subplots() line, = ax.plot([], [], 'r-') ax.set_xlim(0, 800) ax.set_ylim(-1000, y_lim) ax.set_xlabel('Time (s)') ax.set_ylabel('Volume') ax.set_title('Volume/time') slider1 = Slider(20, 20, 100, 20, 20, SENSOR_DISTANCE / 2, 80) run = True while run: distance = silica.move(time) if distance > SCREEN_WIDTH + (silica.size * 2): time =.1 time_data = [] volume_data = [] screen.fill((0,0,0)) sensor.generate(SCREEN_WIDTH, SCREEN_HEIGHT, screen) pygame.draw.circle(screen, (255, 255, 255), (distance - silica.size, 300), silica.size) pygame.draw.circle(screen, (0,255,0), (distance - silica.size, 300), 10) slider1.draw(screen) silica.updateSize(slider1.value) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False slider1.handle_event(event) volume = sensor.getParticleVolume(distance, silica) if (volume > y_lim): y_lim = volume + (volume * 1.2) ax.set_ylim(-1000, y_lim) time_data.append(time) volume_data.append(volume) line.set_xdata(time_data) line.set_ydata(volume_data) ax.relim() ax.autoscale_view() plt.draw() plt.pause(0.01) pygame.display.update() time = time + 1 pygame.quit()