Classes/main.py

80 lines
1.3 KiB
Python

import pygame
import numpy as np
import matplotlib.pyplot as plt
from particle import Particle
from sensor import Sensor
pygame.init()
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
sensor = Sensor(width = 50, distance = 200, space = 200)
silica = Particle(speed = 1, size = 20, perm = 4)
time = .1
time_data = []
volume_data = []
plt.ion()
fig, ax = plt.subplots()
line, = ax.plot([], [], 'r-')
ax.set_xlim(0, 400)
ax.set_ylim(0, 40000)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Volume')
ax.set_title('Volume/time')
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)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
volume = sensor.testSensor1(distance, silica)
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
print(volume)
pygame.quit()