Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgumCorrupto committed Apr 8, 2024
0 parents commit bef7a56
Show file tree
Hide file tree
Showing 21 changed files with 540 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist
Binary file added assets/CURSIV.TTF
Binary file not shown.
Binary file added assets/svt2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions colorParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import PyQt6.QtGui as gui

def parseQt(colVal: str, alpha):
colVal = colVal[1:len(colVal - 1)]
colVal = int(colVal, 16)
return gui.QColor(colVal)
31 changes: 31 additions & 0 deletions colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"normal": {
"black": "#1C1E1F",
"red": "#F76C7C",
"orange": "#F3A96A",
"yellow": "#E3D367",
"green": "#9CD57B",
"blue": "#78CEE9",
"purple": "#BAAOF8",
"gray": "#82878B"
},
"bg": {
"bg_dim": "#21282C",
"bg0": "#273136",
"bg1": "#313B42",
"bg2": "#352F46",
"bg3": "#3A444B",
"bg4": "#414B53",
"bg_red": "#FF6D7E",
"bg_green": "#A2E57B",
"bg_blue": "#7CD5F1"
},
"gray_dim": "#55626D",
"fg": "#E1E2E3",
"diff": {
"diff_red": "#55593D",
"diff_green": "#394634",
"diff_blue": "#354157",
"diff_yellow": "#4E432F"
}
}
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
visualização de gráficos

posição x tempo
S x T

velocidade x tempo
V x T

área x tempo
A x T
Binary file added src/__pycache__/configDialog.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/data.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/graph.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/renderer.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/runner.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/sim.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/window.cpython-312.pyc
Binary file not shown.
106 changes: 106 additions & 0 deletions src/configDialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import PyQt6.QtWidgets as widgets
import PyQt6.QtGui as gui
from sim import obj, Simulation
from data import Data
import graph

class ConfigDialog(widgets.QDialog):
def __init__(self, parent):
super().__init__()
self._main = widgets.QWidget(self)
self.mainLayout = widgets.QFormLayout(self._main)
self.parent = parent
self.setWindowTitle("Configurator 3000")
self.initForms()

def initForms(self):
self.velLabel = widgets.QLabel()
self.velLabel.setText("Velocidade")
self.velIn = widgets.QLineEdit()
self.velIn.setText(obj.startVel.__str__())

self.acceLabel = widgets.QLabel()
self.acceLabel.setText("Aceleração")
self.acceIn = widgets.QLineEdit()
self.acceIn.setText(obj.acce.__str__())

self.time0Label = widgets.QLabel()
self.time0Label.setText("Tempo Inicial")
self.time0In = widgets.QLineEdit()
self.time0In.setText(obj.Time0.__str__())

self.timeFLabel = widgets.QLabel()
self.timeFLabel.setText("Tempo Final")
self.timeFIn = widgets.QLineEdit()
self.timeFIn.setText(obj.TimeF.__str__())

self.pos0Label = widgets.QLabel()
self.pos0Label.setText("Posição Inicial")
self.pos0In = widgets.QLineEdit()
self.pos0In.setText(obj.startPos.__str__())

self.submitBtn = widgets.QPushButton()
self.submitBtn.setText("Atualizar")

self.mainLayout.addWidget(self.velLabel)
self.mainLayout.addWidget(self.velIn)

self.mainLayout.addWidget(self.acceLabel)
self.mainLayout.addWidget(self.acceIn)

self.mainLayout.addWidget(self.time0Label)
self.mainLayout.addWidget(self.time0In)

self.mainLayout.addWidget(self.timeFLabel)
self.mainLayout.addWidget(self.timeFIn)

self.mainLayout.addWidget(self.pos0Label)
self.mainLayout.addWidget(self.pos0In)

self.mainLayout.addWidget(self.submitBtn)

self.submitBtn.clicked.connect(self.updateStuff)

self.setFixedSize(165, 300)

def updateStuff(self):
if int(self.time0In.text() > self.timeFIn.text()):
msg = widgets.QMessageBox()
msg.setWindowTitle("Erro ao processar formulário")
msg.setText("Tempo final não pode ser menor que o tempo inicial.\nTempo não pode conter casas decimais")
msg.exec()
return
try:
obj = Simulation(
float(self.velIn.text()),
float(self.pos0In.text()),
float(self.acceIn.text()),
int(self.time0In.text()),
int(self.timeFIn.text())
)
except:
msg = widgets.QMessageBox()
msg.setWindowTitle("Erro ao processar formulário")
msg.setText("Use ponto final (.) para informar casas decimais ao invés da vírgula (,).\nNão é permitido caracteres alfabéticos.\nTempo só pode ser expressado em números inteiros")
msg.exec()
return

t = []
s = []
a = []
v = []

for dat in obj.dataArr:
t.append(dat.time)
s.append(dat.pos)
a.append(dat.acce)
v.append(dat.vel)

self.parent.SGraph.setPlot(t, s)
self.parent.AGraph.setPlot(t, a)
self.parent.VGraph.setPlot(t, v)
self.parent.gScene.sim = obj
self.parent.reset()



6 changes: 6 additions & 0 deletions src/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Data:
def __init__(self, pos, time, vel, acce):
self.pos = pos
self.time = time
self.vel = vel
self.acce = acce
10 changes: 10 additions & 0 deletions src/entry,py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sim
import window
import sys

import numpy as np

window.app.show()
window.app.activateWindow()
window.app.raise_()
window.qapp.exec()
103 changes: 103 additions & 0 deletions src/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import matplotlib.pyplot as plt
import matplotlib.patches as pt
import matplotlib.animation as anm
import numpy as np
from matplotlib.backends.backend_qtagg import FigureCanvas
from sim import obj, Simulation
import gc

class g():
def __init__(self, title, x, labelX, y, labelY, par):
self.x = x
self.y = y
self.labelX = labelX
self.labelY = labelY
self.title = title
self.parent = par

# overriding abstract method
def setPlot(self, x, y):
self.x = x
self.y = y
self.ani.__del__()
self.ani.pause()
self.circle.remove()
del self.ani
gc.collect()

if len(self.ax.lines) > 0:
for line in list(self.ax.lines):
line.remove()
if len(self.ax.patches) > 0:
for patch in list(self.ax.patches):
patch.remove()
self.ax.plot(self.x, self.y, linewidth=2.0)
yl = max(self.y)
if self.y[0] == self.y[len(self.y)-1]:
yl *= 1.5
#self.ax.relim()
self.ax.set(xlim=(0, max(self.x)),
ylim=(0, yl))
self.circleW = max(self.x)*0.1 if max(self.x) >= 1 else 0.015
self.circleH = yl*0.1333 if yl >= 1 else 0.015
self.circle = pt.Ellipse((self.x[0],self.y[0]),self.circleW, self.circleH, fc='yellow',ec='black')
self.ax.add_patch(self.circle)
self.ani = anm.FuncAnimation(self.fig, self.update, frames=len(self.x), blit=True, interval=100)
plt.subplots_adjust(top=0.85, bottom=0.18, left=0.20, right=0.80, hspace=0.25,
wspace=0.35)

def plot(self):
plt.style.use('_mpl-gallery')
self.fig, self.ax = plt.subplots()
self.canvas = FigureCanvas(self.fig)
self.canvas.setMinimumSize(364, 224)
self.parent.graphLayout.addWidget(self.canvas)

self.ax.plot(self.x, self.y, linewidth=2.0)
yl = max(self.y)
if self.y[0] == self.y[len(self.y)-1]:
yl *= 1.5
self.ax.set(xlim=(0, max(self.x)), xticks=np.arange(0, 0),
ylim=(0, yl), yticks=np.arange(0, 0))
#self.circleW = max(self.x)*0.1 if max(self.x) >= 1 else 1.0
self.circleW = max(self.x)*(self.canvas.height()/ self.canvas.width())*0.1 if max(self.x) >= 1 else 1.0
#self.circleH = yl*0.13333 if yl >= 1 else 1.0
self.circleH = yl*(self.canvas.height()/ self.canvas.width())*0.1 if yl >= 1 else 1.0
self.circle = pt.Ellipse((self.x[0],self.y[0]),self.circleW, self.circleH, fc='yellow',ec='black')
self.ax.add_patch(self.circle)
self.i = 0
self.isRunning = False
self.ani = anm.FuncAnimation(self.fig, self.update, frames=len(self.x), blit=True, interval=100)

plt.ylabel(self.labelY)
plt.xlabel(self.labelX)
plt.title(self.title)
plt.yscale('linear')
plt.xscale('linear')
plt.subplots_adjust(top=0.85, bottom=0.11, left=0.20, right=0.80, hspace=0.25,
wspace=0.5)
#amém
#plt.show()

def update(self, frame):
hMod = 0.175 if max(self.y) == min(self.y) else 0.070
self.circleW = max(self.x)*(0.1+(self.canvas.height()/self.canvas.width()*0.1)) if max(self.x) >= 1 else 0.018
self.circleH = max(self.y)*(hMod+(self.canvas.width()/self.canvas.height()*0.1)) if max(self.y) >= 1 else 0.018
self.circle.remove()
#isso é do SATANÁS, AMIGO!!!!1!
#ainda bem que não precisei usar
#reze por mim, quem estiver vendo esse código
#gc.collect()
if self.i < len(self.x) - 1 and self.isRunning == True:
self.i+= 1
self.circle = pt.Ellipse((self.x[self.i],self.y[self.i]),self.circleW, self.circleH, fc='yellow',ec='black')
else:
self.circle = pt.Ellipse((self.x[self.i],self.y[self.i]),self.circleW, self.circleH, fc='yellow',ec='black')
self.ax.add_patch(self.circle)

return [self.circle]

def play(self):
self.isRunning = True if not self.isRunning else False
def reset(self):
self.i = 0
49 changes: 49 additions & 0 deletions src/renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sys
from PyQt6.QtWidgets import QGraphicsScene, QGraphicsRectItem, QGraphicsEllipseItem
from PyQt6.QtCore import QTimer
from PyQt6.QtGui import QBrush, QColor, QFont

class scene(QGraphicsScene):
def __init__(self, parent, view, sim):
super().__init__(parent)
self.setSceneRect(0, 0, 400, 175)
self.sim = sim
self.view = view
self.view.setScene(self)
self.text = self.addText("Representação")
self.text.setScale(5)
self.runner = QGraphicsEllipseItem(0, 0, 100, 100)
brush = QBrush(QColor(255, 255, 0, 255))
self.runner.setBrush(brush)
self.vel = self.sim.startVel
self.addItem(self.runner)
self.elapsedTime = self.sim.Time0
self.timer = QTimer()
self.timer.setInterval(100)
self.timer.timeout.connect(self.run)
self.isRunning = False
self.timer.start()

def run(self):
self.text.setPos((self.view.width()/2) - ((self.text.boundingRect().width()*5)/2), ((self.height()/2)) - ((self.text.boundingRect().height()) * 5)/2)
self.runner.setPos(self.runner.x(), (self.height()/2) - 100/2)
if self.isRunning and self.elapsedTime < self.sim.TimeF:
self.elapsedTime+=1
pos = self.runner.x() + (self.vel)
self.runner.setPos(pos, (self.height()/2) - 100/2)
self.vel += self.sim.acce
self.text.setPlainText("T={}, A={}, S={}, V={}".format(self.elapsedTime,
self.sim.acce,
self.sim.dataArr[int(self.elapsedTime - self.sim.Time0) - 1].pos,
self.sim.dataArr[int(self.elapsedTime - self.sim.Time0) - 1].vel))

def pauseSim(self):
self.isRunning = False

def playSim(self):
self.isRunning = True if not self.isRunning else False

def resetSim(self):
self.runner.setPos(0, self.runner.y())
self.vel = self.sim.startVel
self.elapsedTime = self.sim.Time0
57 changes: 57 additions & 0 deletions src/sim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import data

class Simulation():
#variable declaration
currTime = 0
Time0 = 0
TimeF = 0

startVel = 0
currVel = 0
acce = 0

startPos = 0
pos = 0

dataArr = []

#constructor
def __init__(self, vel, pos, acce, time0, timeF):
self.startVel = vel
self.startPos = pos
self.acce = acce
self.Time0 = time0
self.TimeF = timeF
self.dataArr = []
self.reset()
self.run()

# devo criar uma única função?? nahhhhh
def setVel(self, vel):
self.startVel = vel
def setAcce(self, acce):
self.acce = acce
def setTime(self, time0, timeF):
self.Time0 = time0
self.TimeF = timeF
def setPos(self, pos):
self.startPos = pos

#run simulation
def run(self):
while self.currTime < self.TimeF:
self.currTime+=1
vel = self.startVel + self.acce*self.currTime
pos = self.startPos + self.startVel * self.currTime + (self.acce*pow(self.currTime, 2)) * 0.5
#Amém
self.dataArr.append(data.Data(pos, self.currTime, vel, self.acce))

#reset the simulation
def reset(self):
self.currVel = self.startVel
self.pos = self.startPos
self.currTime = self.Time0



obj = Simulation(0, 0, 1, 0, 50)
Empty file added src/style.py
Empty file.
Loading

0 comments on commit bef7a56

Please sign in to comment.