Added Graph function
This commit is contained in:
parent
a47e6f7fed
commit
a63285a8b5
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
|
||||||
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
|
||||||
22
newMain.py
22
newMain.py
@ -5,15 +5,22 @@ 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, -6)
|
scale = 1 * pow(10, -6)
|
||||||
unit_scale = -3
|
unit_scale = -3
|
||||||
|
time = 0
|
||||||
|
time_scale = .1
|
||||||
|
|
||||||
sensor = Sensor( 50 * pow(10, -6), 30 * pow(10, -6), 20 * pow(10, -6))
|
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")
|
||||||
|
|
||||||
@ -45,23 +52,26 @@ while True:
|
|||||||
|
|
||||||
scale_bar_size = abs((x - (x * .1)) - (x - (x * .1)) - (1 * pow(10, unit_scale) / scale))
|
scale_bar_size = abs((x - (x * .1)) - (x - (x * .1)) - (1 * pow(10, unit_scale) / scale))
|
||||||
|
|
||||||
print(scale_bar_size)
|
|
||||||
if int(scale_bar_size) < 40:
|
if int(scale_bar_size) < 40:
|
||||||
unit_scale += 1
|
unit_scale += 1
|
||||||
elif int(scale_bar_size) > 100:
|
elif int(scale_bar_size) > 500:
|
||||||
unit_scale -= 1
|
unit_scale -= 1
|
||||||
|
|
||||||
scale_bar_end_point = (x - (x * .1)) - (1 * pow(10, unit_scale) / scale)
|
scale_bar_end_point = (x - (x * .1)) - (1 * pow(10, unit_scale) / scale)
|
||||||
|
|
||||||
screen.fill((200,100,5))
|
screen.fill((200,100,5))
|
||||||
|
|
||||||
sensor.display(x, y, screen, scale)
|
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)
|
graph.add_data(time, math.sin(time))
|
||||||
|
# pygame.draw.circle(screen, (150,255,10), (x / 2, y /2), 3 * pow(10, -6) / scale)
|
||||||
|
|
||||||
pygame.draw.line(screen, (255,255,255), (x - (x * .1), y - (y * .1)), (scale_bar_end_point, y - (y * .1)))
|
pygame.draw.line(screen, (255,255,255), (x - (x * .1), y - (y * .1)), (scale_bar_end_point, y - (y * .1)))
|
||||||
|
|
||||||
print(scale)
|
# print((1 *pow(10, -6)) / scale)
|
||||||
#print((1 *pow(10, -6)) / scale)
|
|
||||||
|
time += time_scale
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|||||||
10
particle.py
10
particle.py
@ -1,4 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
|
import pygame
|
||||||
|
|
||||||
class Particle:
|
class Particle:
|
||||||
def __init__(self, speed, size, perm, rest):
|
def __init__(self, speed, size, perm, rest):
|
||||||
@ -7,10 +8,13 @@ class Particle:
|
|||||||
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 * size * size * size
|
||||||
|
self.distance = 0
|
||||||
|
|
||||||
def move(self, time, scale):
|
def move(self, time_interval, scale, left_limit, right_limit, screen, height):
|
||||||
distance = (self.speed * time) / scale
|
self.distance += (self.speed * time_interval) / scale
|
||||||
return distance
|
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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user