diff --git a/__pycache__/particle.cpython-312.pyc b/__pycache__/particle.cpython-312.pyc new file mode 100644 index 0000000..25b743f Binary files /dev/null and b/__pycache__/particle.cpython-312.pyc differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..0c85b3a --- /dev/null +++ b/main.py @@ -0,0 +1,88 @@ +import pygame +import numpy as np +import matplotlib.pyplot as plt +from particle import Particle + +pygame.init() + +SCREEN_WIDTH = 800 +SCREEN_HEIGHT = 600 + + + +screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) + +sensor1 = pygame.Rect(200, 200, 50, 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, 1) +ax.set_ylim(0, 30000) +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)) + + pygame.draw.rect(screen, (255,0,0), sensor1) + + 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 + + if silica.size >= abs(200 - (distance - silica.size)): + pygame.draw.circle(screen, (0,255,0),(100, 100), 50) + volume = silica.partialVol(abs(200 - (distance - silica.size))) + elif silica.size >= abs(250 - (distance - silica.size)): + pygame.draw.circle(screen, (0,255,0),(100, 100), 50) + volume = silica.volume - silica.partialVol(abs(250 - (distance - silica.size))) + elif ((distance - silica.size) >= 200 and (distance - silica.size) <= 250): + pygame.draw.circle(screen, (0,255,0),(100, 100), 50) + volume = silica.volume + else: + volume = 0 + + 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_data) + + + +pygame.quit() + + diff --git a/particle.py b/particle.py new file mode 100644 index 0000000..7162884 --- /dev/null +++ b/particle.py @@ -0,0 +1,18 @@ +import math + +class Particle: + def __init__(self, speed, size, perm): + self.speed = speed + self.size = size + self.perm = perm + self.volume = (4/3.0) * math.pi * size * size * size + + def move(self, time): + distance = self.speed * time + return distance + + def partialVol(self, height): + partialVol = (1/3) * math.pi * height * height * ((3 * self.size) - height) + return partialVol + +