Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbe1c02d4b | |||
| a63285a8b5 | |||
| a47e6f7fed |
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
__pycache__/graph.cpython-312.pyc
|
||||||
|
__pycache__/particle.cpython-312.pyc
|
||||||
|
|
||||||
|
__pycache__/sensor.cpython-312.pyc
|
||||||
|
__pycache__/slider.cpython-312.pyc
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
26
graph.py
Normal file
26
graph.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Graph:
|
||||||
|
def __init__(self, ratio, max_time, center, y_scale):
|
||||||
|
self.ratio = ratio
|
||||||
|
self.max_time = max_time
|
||||||
|
self.center = center
|
||||||
|
self.y_scale = y_scale
|
||||||
|
self.data = []
|
||||||
|
|
||||||
|
def draw(self, screen, x, y, time_scale):
|
||||||
|
rect = pygame.Rect(0, 0, x, y / self.ratio)
|
||||||
|
pygame.draw.rect(screen, (0,0,0), rect)
|
||||||
|
self.draw_data(x, y, screen, time_scale)
|
||||||
|
|
||||||
|
def add_data(self, time, value):
|
||||||
|
self.data.append([time, value])
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
return self.data
|
||||||
|
|
||||||
|
def draw_data(self, x, y, screen, time_scale):
|
||||||
|
offset = 0
|
||||||
|
for i in range(len(self.data) - 1, -1, -1):
|
||||||
|
pygame.draw.circle(screen, (255,0,0), (x - offset ,(y / (2 * self.ratio)) + self.data[i][1] * 10), 1)
|
||||||
|
offset += time_scale * 10
|
||||||
45
newMain.py
45
newMain.py
@ -5,13 +5,21 @@ import math
|
|||||||
from sensor import Sensor
|
from sensor import Sensor
|
||||||
from particle import Particle
|
from particle import Particle
|
||||||
from slider import Slider
|
from slider import Slider
|
||||||
|
from graph import Graph
|
||||||
|
|
||||||
SCREEN_WIDTH = 1352
|
SCREEN_WIDTH = 1352
|
||||||
SCREEN_HEIGHT = 878
|
SCREEN_HEIGHT = 878
|
||||||
|
|
||||||
scale = 1 * pow(10, -8)
|
scale = 1 * pow(10, -6)
|
||||||
|
unit_scale = -3
|
||||||
|
time = 0
|
||||||
|
time_scale = 1
|
||||||
|
|
||||||
sensor = Sensor((50*pow(10, -9)) / scale, (200 * pow(10,-9)) / scale, (300 * pow(10, -9)) / scale)
|
sensor = Sensor( 50 * pow(10, -6), 30 * pow(10, -6), 20 * pow(10, -6))
|
||||||
|
|
||||||
|
particle = Particle(10 * pow(10, -8), 7 * pow(10, -6), 1, 1)
|
||||||
|
|
||||||
|
graph = Graph(4, 10, 0, 10)
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption("CytoSim")
|
pygame.display.set_caption("CytoSim")
|
||||||
@ -32,18 +40,41 @@ while True:
|
|||||||
scale = scale / 1.1
|
scale = scale / 1.1
|
||||||
elif event.y == -1:
|
elif event.y == -1:
|
||||||
scale = scale * 1.1
|
scale = scale * 1.1
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
print("Button")
|
||||||
|
if event.key == pygame.K_UP:
|
||||||
|
scale = scale / 1.1
|
||||||
|
elif event.key == pygame.K_DOWN:
|
||||||
|
scale = scale * 1.1
|
||||||
|
|
||||||
|
|
||||||
x, y = screen.get_size()
|
x, y = screen.get_size()
|
||||||
|
|
||||||
|
scale_bar_size = abs((x - (x * .1)) - (x - (x * .1)) - (1 * pow(10, unit_scale) / scale))
|
||||||
|
|
||||||
|
if int(scale_bar_size) < 40:
|
||||||
|
unit_scale += 1
|
||||||
|
elif int(scale_bar_size) > 500:
|
||||||
|
unit_scale -= 1
|
||||||
|
|
||||||
|
scale_bar_end_point = (x - (x * .1)) - (1 * pow(10, unit_scale) / scale)
|
||||||
|
|
||||||
screen.fill((200,100,5))
|
screen.fill((200,100,5))
|
||||||
|
|
||||||
sensor.generate(x, y, screen)
|
sensor.display(x, y + (y / graph.ratio), screen, scale)
|
||||||
|
particle.move(time_scale, scale, sensor.left_limit, sensor.right_limit, screen, y + (y / graph.ratio))
|
||||||
|
graph.draw(screen, x, y, time_scale)
|
||||||
|
|
||||||
pygame.draw.circle(screen, (150,255,10), (x / 2, y /2), 3 * pow(10, -6) / scale)
|
volume = sensor.testSensor1(particle.distance, particle, scale, screen)
|
||||||
|
print(volume)
|
||||||
|
|
||||||
pygame.draw.line(screen, (255,255,255), (x - (x * .1), y - (y * .1)), ((x - (x * .1)) - (1 * pow(10, -6) / scale), y - (y * .1)))
|
graph.add_data(time, volume)
|
||||||
|
# pygame.draw.circle(screen, (150,255,10), (x / 2, y /2), 3 * pow(10, -6) / scale)
|
||||||
|
|
||||||
print(scale)
|
pygame.draw.line(screen, (255,255,255), (x - (x * .1), y - (y * .1)), (scale_bar_end_point, y - (y * .1)))
|
||||||
#print((1 *pow(10, -6)) / scale)
|
|
||||||
|
# print((1 *pow(10, -6)) / scale)
|
||||||
|
|
||||||
|
time += time_scale
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|||||||
14
particle.py
14
particle.py
@ -1,16 +1,22 @@
|
|||||||
import math
|
import math
|
||||||
|
import pygame
|
||||||
|
|
||||||
class Particle:
|
class Particle:
|
||||||
def __init__(self, speed, size, perm, rest):
|
def __init__(self, speed, size, perm, rest):
|
||||||
self.speed = speed
|
self.speed = speed
|
||||||
self.size = size
|
self.size = size
|
||||||
|
self.radius = size / 2
|
||||||
self.perm = perm
|
self.perm = perm
|
||||||
self.rest = rest
|
self.rest = rest
|
||||||
self.volume = (4/3.0) * math.pi * size * size * size
|
self.volume = (4/3.0) * math.pi * pow(self.radius, 3)
|
||||||
|
self.distance = 0
|
||||||
|
|
||||||
def move(self, time):
|
def move(self, time_interval, scale, left_limit, right_limit, screen, height):
|
||||||
distance = self.speed * time
|
self.distance += (self.speed * time_interval) / scale
|
||||||
return distance
|
self.pixel_distance = self.distance + left_limit
|
||||||
|
if self.distance + left_limit + (self.size / (2 * scale)) > right_limit:
|
||||||
|
self.distance = 0
|
||||||
|
pygame.draw.circle(screen, (255,225,255), (left_limit + self.distance, height / 2), self.size / (2 * scale))
|
||||||
|
|
||||||
def partialVol(self, height):
|
def partialVol(self, height):
|
||||||
partialVol = (1/3) * math.pi * height * height * ((3 * self.size) - height)
|
partialVol = (1/3) * math.pi * height * height * ((3 * self.size) - height)
|
||||||
|
|||||||
106
sensor.py
106
sensor.py
@ -1,4 +1,5 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
import math
|
||||||
|
|
||||||
class Sensor:
|
class Sensor:
|
||||||
def __init__(self, width, distance, space):
|
def __init__(self, width, distance, space):
|
||||||
@ -6,49 +7,82 @@ class Sensor:
|
|||||||
self.distance = distance
|
self.distance = distance
|
||||||
self.space = space
|
self.space = space
|
||||||
self.volume = width * pow(distance, 2)
|
self.volume = width * pow(distance, 2)
|
||||||
|
self.total_width = (4 * width) + space
|
||||||
|
self.total_height = 100 * pow(10, -6) - distance
|
||||||
|
|
||||||
def generate(self, screenWidth, screenHeight, screen):
|
def display(self, screenWidth, screenHeight, screen, scale):
|
||||||
self.sensor1_x = (screenWidth / 2) - (self.space / 2) - self.width
|
center_x = screenWidth / 2
|
||||||
self.sensor1_y = 0
|
center_y = screenHeight / 2
|
||||||
self.sensor1_x_size = self.width
|
scaled_half_x = self.total_width / (2 * scale)
|
||||||
self.sensor1_y_size = (screenHeight / 2) - (self.distance / 2)
|
scaled_half_y = self.total_height / (2 * scale)
|
||||||
|
scaled_width = self.width / scale
|
||||||
|
scaled_distance = self.distance / scale
|
||||||
|
scaled_space = self.space / scale
|
||||||
|
self.height = screenHeight
|
||||||
|
|
||||||
self.inner1 = self.sensor1_x
|
self.scaled_sensor1_left_limit = center_x - scaled_space - scaled_width
|
||||||
self.outer1 = self.inner1 + self.width
|
self.scaled_sensor1_right_limit = center_x - scaled_space
|
||||||
|
self.scaled_sensor2_left_limit = center_x + scaled_space
|
||||||
|
self.scaled_sensor2_right_limit = center_x + scaled_space + scaled_width
|
||||||
|
|
||||||
|
self.right_limit = center_x + scaled_half_x
|
||||||
|
self.left_limit = center_x - scaled_half_x
|
||||||
|
|
||||||
|
sensor1_rect_up = pygame.Rect(center_x - scaled_space - scaled_width, center_y - scaled_half_y, scaled_width, scaled_half_y - (scaled_distance / 2))
|
||||||
|
sensor1_rect_down = pygame.Rect(center_x - scaled_space - scaled_width, center_y + (scaled_distance / 2), scaled_width, scaled_half_y - (scaled_distance / 2))
|
||||||
|
sensor2_rect_up = pygame.Rect(center_x + scaled_space, center_y - scaled_half_y, scaled_width, scaled_half_y - (scaled_distance / 2))
|
||||||
|
sensor2_rect_down = pygame.Rect(center_x + scaled_space, center_y + (scaled_distance / 2), scaled_width, scaled_half_y - (scaled_distance / 2))
|
||||||
|
|
||||||
|
pygame.draw.rect(screen, (0,200,0), sensor1_rect_up)
|
||||||
|
pygame.draw.rect(screen, (0,200,0), sensor1_rect_down)
|
||||||
|
pygame.draw.rect(screen, (0,200,0), sensor2_rect_up)
|
||||||
|
pygame.draw.rect(screen, (0,200,0), sensor2_rect_down)
|
||||||
|
|
||||||
|
pygame.draw.line(screen, (100,100,50), (center_x - scaled_half_x, center_y - (scaled_distance / 2)), (center_x + scaled_half_x, center_y - (scaled_distance / 2)))
|
||||||
|
pygame.draw.line(screen, (100,100,50), (center_x - scaled_half_x, center_y + (scaled_distance / 2)), (center_x + scaled_half_x, center_y + (scaled_distance / 2)))
|
||||||
|
|
||||||
|
pygame.draw.line(screen, (255,255,255), (center_x - scaled_half_x, center_y - scaled_half_y), (center_x + scaled_half_x, center_y - scaled_half_y), 7)
|
||||||
|
pygame.draw.line(screen, (255,255,255), (center_x + scaled_half_x, center_y - scaled_half_y), (center_x + scaled_half_x, center_y + scaled_half_y), 7)
|
||||||
|
pygame.draw.line(screen, (255,255,255), (center_x + scaled_half_x, center_y + scaled_half_y), (center_x - scaled_half_x, center_y + scaled_half_y), 7)
|
||||||
|
pygame.draw.line(screen, (255,255,255), (center_x - scaled_half_x, center_y + scaled_half_y), (center_x - scaled_half_x, center_y - scaled_half_y), 7)
|
||||||
|
|
||||||
sensor1a = pygame.Rect(self.sensor1_x, self.sensor1_y, self.sensor1_x_size, self.sensor1_y_size)
|
|
||||||
sensor1b = pygame.Rect(self.sensor1_x, self.sensor1_y + self.sensor1_y_size + self.distance, self.sensor1_x_size, self.sensor1_y_size)
|
|
||||||
pygame.draw.rect(screen, (0, 0, 255), sensor1a)
|
|
||||||
pygame.draw.rect(screen, (0, 0, 255), sensor1b)
|
|
||||||
|
|
||||||
self.sensor2_x = (screenWidth / 2) + (self.space / 2)
|
return 0
|
||||||
self.sensor2_y = 0
|
|
||||||
self.sensor2_x_size = self.width
|
|
||||||
self.sensor2_y_size = (screenHeight / 2) - (self.distance / 2)
|
|
||||||
|
|
||||||
self.inner2 = self.sensor2_x
|
|
||||||
self.outer2 = self.inner2 + self.width
|
|
||||||
|
|
||||||
sensor2a = pygame.Rect(self.sensor2_x, self.sensor2_y, self.sensor2_x_size, self.sensor2_y_size)
|
|
||||||
sensor2b = pygame.Rect(self.sensor2_x, self.sensor2_y + self.sensor2_y_size + self.distance, self.sensor2_x_size, self.sensor2_y_size)
|
|
||||||
pygame.draw.rect(screen, (0, 0, 255), sensor2a)
|
|
||||||
pygame.draw.rect(screen, (0, 0, 255), sensor2b)
|
|
||||||
|
|
||||||
def testSensor1(self, partCenter, particle):
|
def testSensor1(self, partCenter, particle, scale, screen):
|
||||||
if (particle.size >= abs(self.inner1 - (partCenter - particle.size))) and (particle.size >= abs(self.outer1 - (partCenter - particle.size))):
|
particle_right_limit = particle.pixel_distance + (particle.radius / scale)
|
||||||
volume = ((particle.volume / 2) - (particle.partialVol(particle.size - ((partCenter - particle.size) - self.inner1)))) + ((particle.volume / 2) - particle.partialVol(particle.size - (self.outer1 - (partCenter - particle.size))))
|
particle_left_limit = particle.pixel_distance - (particle.radius / scale)
|
||||||
return volume
|
|
||||||
elif particle.size >= abs(self.inner1 - (partCenter - particle.size)):
|
pygame.draw.line(screen, (0,0,0), (particle_left_limit, self.height), (particle_left_limit, 0))
|
||||||
volume = particle.partialVol(particle.size - (self.inner1 - (partCenter - particle.size)))
|
pygame.draw.line(screen, (0,100,0), (particle_right_limit, self.height), (particle_right_limit, 0))
|
||||||
return volume
|
|
||||||
elif particle.size >= abs(self.outer1 - (partCenter - particle.size)):
|
pygame.draw.line(screen, (0,0,0), (self.scaled_sensor1_left_limit, self.height), (self.scaled_sensor1_left_limit, 0))
|
||||||
volume = particle.volume - particle.partialVol(particle.size - (self.outer1 - (partCenter - particle.size)))
|
pygame.draw.line(screen, (0,100,0), (self.scaled_sensor1_right_limit, self.height), (self.scaled_sensor1_right_limit, 0))
|
||||||
return volume
|
|
||||||
elif ((partCenter - particle.size) >= self.inner1 and (partCenter - particle.size) <= self.outer1):
|
if (particle_right_limit >= self.scaled_sensor1_left_limit and particle_left_limit < self.scaled_sensor1_left_limit):
|
||||||
volume = particle.volume
|
if (particle.pixel_distance < self.scaled_sensor1_left_limit):
|
||||||
return volume
|
height = particle_right_limit - self.scaled_sensor1_left_limit
|
||||||
|
volume = ((math.pi * height * height) / 3) * ((3 * (particle.radius / scale)) - height)
|
||||||
|
else:
|
||||||
|
height = self.scaled_sensor1_left_limit - particle.pixel_distance
|
||||||
|
volume = ((math.pi * height * height) / 3) * ((3 * (particle.radius / scale)) - height)
|
||||||
|
elif (particle_right_limit <= self.scaled_sensor1_right_limit and particle_left_limit >= self.scaled_sensor1_left_limit):
|
||||||
|
volume = particle.volume / scale
|
||||||
|
elif (particle_right_limit > self.scaled_sensor1_right_limit and particle_left_limit > self.scaled_sensor1_left_limit and particle_left_limit < self.scaled_sensor1_right_limit):
|
||||||
|
if (particle.pixel_distance > self.scaled_sensor1_right_limit):
|
||||||
|
height = particle.pixel_distance - self.scaled_sensor1_right_limit
|
||||||
|
volume = ((math.pi * height * height) / 3) * ((3 * (particle.radius / scale)) - height)
|
||||||
|
else:
|
||||||
|
height = self.scaled_sensor1_right_limit - particle_left_limit
|
||||||
|
volume = ((math.pi * height * height) / 3) * ((3 * (particle.radius / scale)) - height)
|
||||||
else:
|
else:
|
||||||
return 0
|
volume = 0
|
||||||
|
|
||||||
|
|
||||||
|
return volume * scale
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def testSensor2(self, partCenter, particle):
|
def testSensor2(self, partCenter, particle):
|
||||||
if (particle.size >= abs(self.inner2 - (partCenter - particle.size))) and (particle.size >= abs(self.outer2 - (partCenter - particle.size))):
|
if (particle.size >= abs(self.inner2 - (partCenter - particle.size))) and (particle.size >= abs(self.outer2 - (partCenter - particle.size))):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user