Skip to content

Commit

Permalink
Suite de Physique Version 1.2.5
Browse files Browse the repository at this point in the history
Ajout d'un bouton de guide, correction de bogues et le programme est maintenant plus convivial.
  • Loading branch information
Souhail-Bel authored Apr 1, 2023
1 parent 78a491a commit 76af7d5
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 97 deletions.
6 changes: 6 additions & 0 deletions Commencer le programme.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <cstdlib>

int main() {
std::system("\"Suite de Physique/Suite de Physique.exe\"");
return 0;
}
28 changes: 20 additions & 8 deletions guiWorks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
currN=0
currZ=1
currVal = 1
guide = None


def MAIN_ATOM(mainy):
global t, isTurning, elecs, currVal, currN, currZ
global t, isTurning, elecs, currVal, currN, currZ, guide

ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")

app = ctk.CTkToplevel(mainy)
app.geometry("800x600+100+50")
app.title("L'atome")
gum.createGuideWindow(app, "Guide: L'atome","atom.txt")


canvas = Canvas(app,width=800,height=600,bg="#1A1A1A",relief="ridge")
canvas.pack()
Expand Down Expand Up @@ -134,7 +135,7 @@ def Zwork(feedback=None):
currVal = 1
elemVal.configure(text=str(currVal)+" électron(s)")
elemsBox.set("1-Hydrogène")
print("Hydrogène 1")
print("Merci d'entrer une valuer valable (utilisant l'Hydrogène par défaut)")

def elemsBoxy(elemy):
#Ztextbox.delete("0.0","end")
Expand All @@ -150,10 +151,10 @@ def toggleTurn():
elemNature.configure(text='Non-métaux')
elecs = [1]

zInput = ctk.CTkButton(master=app, text="Choisir le nombre Z", command=Zwork)
zInput = ctk.CTkButton(master=app, text="Choisir le nombre Z", font=("Arial",25), command=Zwork)
zInput.place(relx=0.5, rely=0.95, anchor=CENTER)

button2 = ctk.CTkButton(master=app, text="Animer", command=toggleTurn, width = 100)
button2 = ctk.CTkButton(master=app, text="Animer", font=("Arial",25),command=toggleTurn, width = 100)
button2.place(relx=0.975, rely=0.95, anchor=E)

elemsBox = ctk.CTkOptionMenu(master=app,
Expand Down Expand Up @@ -273,10 +274,21 @@ def updateGraphics():
circle_dist(Cx, Cy, NZ[0], 2, 2, dessZ, dessN, NZ[0]*15/5)
app.after(int(1e2), updateGraphics)




#GUM LOGIC
def gumCall():
global guide
if guide is None:
guide = gum.createGuideWindow(app, "Guide: L'atome","atom.txt")
else:
guide.destroy()
guide = gum.createGuideWindow(app, "Guide: L'atome","atom.txt")

gumButton = ctk.CTkButton(app,text="Guide",width=50,height=20,command=gumCall,image=ctk.CTkImage(dark_image=Image.open("./res/guide.png"),size=(30, 30)))
gumButton.place(relx=0.95,rely=0.5,anchor=E)

app.after(int(1e3/2), updateGraphics)
return app
app.mainloop()

if __name__ == '__main__':
Expand Down
22 changes: 17 additions & 5 deletions guideManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def createGuideWindow(parent, title, text):
textLi = [i[:-1] for i in open(mainGuidyPath+text,'r').readlines()]
linesSpacing = 25
hLi = (len(textLi)+2)*linesSpacing



guide = ctk.CTkToplevel(parent)
guide.geometry(f'{widthGuidy+20}x{min(heightGuidy,hLi+60)}+550+150')
guide.resizable(False,False)
Expand Down Expand Up @@ -68,7 +69,16 @@ def createGuideWindow(parent, title, text):
cont.create_text(Cx,i*linesSpacing+15,
text=linClr[0][1:offset],font=("Arial", 20,attrLine),
fill="white")

elif '¤' in line:
jList = line.split(';')
Cl = widthGuidy/(len(jList)+1)
i+=1
for l in range(len(jList)):
img = Image.open(jList[l][1:])
img = img.resize((int(float(img.size[0])*30/(img.size[1])),30), Image.Resampling.LANCZOS)
img = ImageTk.PhotoImage(img)
garbageCollector.update({'image'+str(i)+'-'+str(l): img})
imgObj = cont.create_image(Cl*(l+1),(i-0.5)*linesSpacing+15,anchor='center',image=img)
elif '$' in line:
jList = line.split(';')
Cl = widthGuidy/(len(jList)+1)
Expand All @@ -95,18 +105,20 @@ def createGuideWindow(parent, title, text):
if len(linClr)>1:
cont.create_text(Cx,i*linesSpacing+15,
text=linClr[0][0:offset],font=("Arial", 12,attrLine),
fill=linClr[1].strip(),width=450,justify=CENTER)
fill=linClr[1].strip(),width=480,justify=CENTER)
else:
cont.create_text(Cx,i*linesSpacing+15,
text=line[0:offset],font=("Arial", 12,attrLine),
fill="white",width=450,justify=CENTER)
fill="white",width=480,justify=CENTER)

i+=1
cont.rowconfigure(0,weight=1)
cont.columnconfigure(0,weight=1)
#guide.mainloop()


return guide
#guide.mainloop()

if __name__ == "__main__":
app = ctk.CTk()
createGuideWindow(app, "Test Guide", 'testText.txt')
Expand Down
56 changes: 46 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,75 @@
import nbodyTk
import mech
import guideManager as gum
from PIL import Image
#import pyi_splash


ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")

app = ctk.CTk()
app.geometry("400x300+150+150")
app.geometry("400x350+150+150")
app.resizable(False,False)
app.title("Suite de Physique")

gum.createGuideWindow(app, "Guide", "main.txt")

atomApp = None
def ATOM_PROG():
guiWorks.MAIN_ATOM(app)
global atomApp
if atomApp is None:
atomApp = guiWorks.MAIN_ATOM(app)
else:
atomApp.destroy()
atomApp = guiWorks.MAIN_ATOM(app)

gravApp = None
def GRAV_PROG():
nbodyTk.MAIN_GRAV(app)
global gravApp
if gravApp is None:
gravApp = nbodyTk.MAIN_GRAV(app)
else:
gravApp.destroy()
gravApp = nbodyTk.MAIN_GRAV(app)


def RC_PROG():
rc.MAIN_RC(app)

mechApp = None
def MECH_PROG():
mech.MAIN_MECH(app)
#pyi_splash.close()
global mechApp
if mechApp is None:
mechApp = mech.MAIN_MECH(app)
else:
mechApp.destroy()
mechApp = mech.MAIN_MECH(app)

ctk.CTkLabel(app,text="Pour la 2ème année:",font=("Arial", 25)).place(relx=0.05,rely=0.05,anchor=NW)
ATOM = ctk.CTkButton(app, text="L'atome",command=ATOM_PROG,font=("Arial", 25),width=250,height=30)
ATOM.place(relx=0.5,rely=0.2,anchor=S)
ATOM.place(relx=0.5,rely=0.225,anchor=S)

ctk.CTkLabel(app,text="Pour la 3ème année:",font=("Arial", 25)).place(relx=0.05,rely=0.25,anchor=NW)
GRAV = ctk.CTkButton(app, text="Gravitation", command=GRAV_PROG,font=("Arial", 25),width=250,height=30)
GRAV.place(relx=0.5,rely=0.4,anchor=S)
GRAV.place(relx=0.5,rely=0.425,anchor=S)

ctk.CTkLabel(app,text="Pour la 4ème année:",font=("Arial", 25)).place(relx=0.05,rely=0.45,anchor=NW)
COND = ctk.CTkButton(app, text="Circuit RC",command=RC_PROG,font=("Arial", 25),width=250,height=30)
COND.place(relx=0.5,rely=0.6,anchor=S)
COND.place(relx=0.5,rely=0.625,anchor=S)
COND = ctk.CTkButton(app, text="Mécanique",command=MECH_PROG,font=("Arial", 25),width=250,height=30)
COND.place(relx=0.5,rely=0.8,anchor=S)
COND.place(relx=0.5,rely=0.75,anchor=S)

guide = None
#GUM LOGIC
def gumCall():
global guide
if guide is None:
guide = gum.createGuideWindow(app, "Guide", "main.txt")
else:
guide.destroy()
guide = gum.createGuideWindow(app, "Guide", "main.txt")

gumButton = ctk.CTkButton(app,text="Guide",width=50,height=20,command=gumCall,image=ctk.CTkImage(dark_image=Image.open("./res/guide.png"),size=(30, 30)))
gumButton.place(relx=0.5,rely=0.95,anchor=S)

app.mainloop()
50 changes: 44 additions & 6 deletions mech.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import guideManager as gum
import time

guide = None

def MAIN_MECH(mainy):
global guide
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")

Expand All @@ -18,8 +21,6 @@ def MAIN_MECH(mainy):
app.resizable(False,False)
app.title("Mécanique")

gum.createGuideWindow(app, "Guide: Mécanique", "mech.txt")

canvas = Canvas(app,bg="#1A1A1A",width=750,height=450)
canvas.pack()

Expand Down Expand Up @@ -234,11 +235,35 @@ def energyPlot():
plt.legend()
plt.grid()
plt.show()


def phasePlot():
m, h, k,x0,v0 = unpack_values()
X, Y = [],[]
if not (m*k == 0):
TIME = np.linspace(0,50*np.sqrt(m/k),400)
X = np.real(LAPLACE_SOLVE_MECH(m,h,k,x0,v0)(TIME))
V = np.real(LAPLACE_SOLVE_MECH(m,h,k,x0,v0,1)(TIME))
plt.figure()
eigenValue = -h/(2*m) #ou valuer propre
sqrt = ((h/m)**2 - 4*(k/m))/2
sqrt = np.sqrt(sqrt) if (sqrt>=0) else np.sqrt(-sqrt)*1j
eigenPlus = eigenValue+sqrt
eigenMinus = eigenValue-sqrt
lambdaTitle = r'$\lambda_1 =$'+ str(np.round(np.real(eigenPlus),2)) +(r'$+$' if np.imag(eigenPlus)>=0 else r'$-$')+ str(np.round(np.imag(eigenPlus),2)) +r'$i$'
lambdaTitle += r', $\lambda_2 =$'+ str(np.round(np.real(eigenMinus),2)) +(r'$+$' if np.imag(eigenMinus)>=0 else r'')+ str(np.round(np.imag(eigenMinus),2)) +r'$i$'
plt.title("Diagramme de l'Espace des Phases " + lambdaTitle)
plt.plot(X, V, color='purple',label='Trajectoire de Phase')
plt.scatter(0,0,color='green',label="Point d'Equilibre")
plt.xlabel('Position')
plt.ylabel('Vitesse')
plt.grid()
plt.legend()
plt.show()

ctk.CTkButton(app,text="Simuler", font=("Arial", 24),command=simuler).place(relx=1/3,rely=0.8,anchor=CENTER)
ctk.CTkButton(app,text="Arrêter", font=("Arial", 24),command=arreter).place(relx=2/3,rely=0.8,anchor=CENTER)
ctk.CTkButton(app,text="Tracer l'énergie", font=("Arial", 24),command=energyPlot).place(relx=1/2,rely=0.9,anchor=CENTER)
ctk.CTkButton(app,text="Réinitialiser", font=("Arial", 24),command=arreter).place(relx=2/3,rely=0.8,anchor=CENTER)
ctk.CTkButton(app,text="Tracer l'énergie", font=("Arial", 24),command=energyPlot).place(relx=1/3,rely=0.9,anchor=CENTER)
ctk.CTkButton(app,text="Plan de Phase", font=("Arial", 24),command=phasePlot).place(relx=2/3,rely=0.9,anchor=CENTER)


FPS = 24
Expand Down Expand Up @@ -297,7 +322,20 @@ def updateGraphics(h,k,t):
t = time.time() - T0
#t += 1
canvas.after(10,updateGraphics, h,k,t)


#GUM LOGIC
def gumCall():
global guide
if guide is None:
guide = gum.createGuideWindow(app, "Guide: Mécanique", "mech.txt")
else:
guide.destroy()
guide = gum.createGuideWindow(app, "Guide: Mécanique", "mech.txt")

gumButton = ctk.CTkButton(app,text="Guide",width=50,height=20,command=gumCall,image=ctk.CTkImage(dark_image=Image.open("./res/guide.png"),size=(30, 30)))
gumButton.place(relx=0.5,rely=0.75,anchor=CENTER)

return app
#app.after(10, updateGraphics, 0)
app.mainloop()

Expand Down
Loading

0 comments on commit 76af7d5

Please sign in to comment.