-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHarmonicWave3D.py
127 lines (109 loc) · 3.18 KB
/
HarmonicWave3D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import sys
import matplotlib.pyplot as plt
import numpy as np
import math
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
def checkP(s):
#print("run check p")
k = 2222222222222222222
if s.find("p") == 1 or s == "p" :
s = s.replace("p"," ")
if len(s) != 1:
k = float(s)
if len(s) != 1:
k *= np.pi
else:
k = np.pi
elif s.find("π") == 1 or s == "π":
s = s.replace("π"," ")
if len(s) != 1:
k = float(s)
if len(s) != 1:
k *= np.pi
else:
k = np.pi
#print(k)
return k
def checkE(s):
#print("run check e")
k = 2222222222222222222
if s.find("e") == 1 or s == "e":
s = s.replace("e"," ")
if len(s) != 1:
k = float(s)
if len(s) != 1:
k *= np.exp(1)
else:
k = np.exp(1)
#print(k)
return k
def checkEP(s):
#print("run check ep")
k = 2222222222222222222
if (s.find("pe") == 1 or s.find("ep") == 1) :
#print("in here")
s = s.replace("e"," ")
s = s.replace("p"," ")
if len(s) != 1:
k = float(s)
if len(s) != 1:
k *= np.exp(1)
k *= np.pi
else:
k = np.exp(1)*np.pi
#print(k)
return k
def check(s):
flag = checkEP(s)
if flag != 2222222222222222222:
return flag
flag = checkP(s)
if flag != 2222222222222222222:
return flag
flag = checkE(s)
if flag != 2222222222222222222:
return flag
if s.find(","):
s = s.replace(",",".")
return float(s)
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [ [sg.Text('Enter A value: '), sg.InputText('4')],
[sg.Text('Enter T value: '), sg.InputText('1')],
[sg.Text('Enter λ value: '), sg.InputText('0.5')],
[sg.Button('Create Plot') ,sg.Button('Close Window'),sg.Text('By Michail-Panagiotis Bofos')]
]
# Create the Window
sg.theme("DarkTeal12")
window = sg.Window('Harmonic Wave 3D example', layout).Finalize()
#window.Maximize()
# Event Loop to process "events" and get the "values" of the inputs
win2_active = False
while True:
event, values = window.read()
if event in (None, 'Close Window'): # if user closes window or clicks cancel
break
if event in (None,'Create Plot'):
win2_active = True
layout2 = [
[sg.Text('The second window'), sg.Text('', key='_OUTPUT_')],
[sg.Input(do_not_clear=True, key='_IN_')],
[sg.Button('Show'), sg.Button('Exit')]
]
l = check(values[2])
T = check(values[1])
A = check(values[0])
#X = list(np.linspace(0, maxx, 100))
#t = list(np.linspace(0, maxt, 100))
X = list(np.linspace(0, 2*l, 100))
t = list(np.linspace(0, 2*T, 100))
X, t = np.meshgrid(X, t)
Z = A * np.sin(2*np.pi*(t/T + X/l))
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X, t, Z, rstride=1, cstride=1, cmap=cm.viridis)
plt.show()
window.Close()