1717 font-size : 1rem ;
1818 margin : 5px 0 ;
1919 width : 100% ;
20- box-sizing : border-box;
20+ box-sizing : border-box;
2121 }
2222
2323 textarea { height : 80px ; }
2929 padding-top : 10px ;
3030 padding-bottom : 10px ;
3131 width : 120px ;
32+ background : # fcfcfc ;
3233 }
3334
3435 .buttons {
@@ -86,9 +87,35 @@ <h1>WavePlayerJS</h1>
8687 < button id ="playBtn "> Play Wave</ button >
8788 < button id ="stopBtn "> Stop Wave</ button >
8889 </ div >
89- < button id ="loadPresetBtn " style ="margin-left: auto; " onclick =" alert('This feature hasn\'t been added yet.'); " > Load Preset</ button >
90+ < button id ="loadPresetBtn " style ="margin-left: auto; "> Load Preset</ button >
9091 </ div >
9192 </ div >
93+
94+ < div id ="presetMenu " style ="
95+ display: none;
96+ border: 1px solid #aaa;
97+ padding: 5px;
98+ background: #eee;
99+ width: 150px;
100+ position: fixed;
101+ right: 164px;
102+ top: 190px;
103+ ">
104+ < div class ="menu-item " data-value ="Math.sin(t*vf)*va "> Sine Wave</ div >
105+ < div class ="menu-item " data-value ="Math.sign(Math.sin(t*vf))*va "> Square Wave</ div >
106+ < div class ="menu-item " data-value ="(2/Math.PI)*Math.asin(Math.sin(2*t*vf))*va "> Triangle Wave</ div >
107+ < div class ="menu-item " data-value ="((Math.sin(t*vf)*((2)/(Math.PI))*Math.asin(Math.sin(2*t*vf))+Math.sign(Math.sin(t*vf)))*((1.84)/(Math.PI)))*va "> Hybrid Wave</ div >
108+ < div class ="menu-item " data-value ="(2/Math.PI)*Math.asin(Math.sin(2*t*vf))*va + (2/Math.PI)*Math.tan(Math.sin(t*vf))*va*vp "> Mountain Wave</ div >
109+ < div class ="menu-item " data-value ="Math.sin(Math.atanh(Math.sin(t*vf)))*va "> Insect Wave</ div >
110+ < div class ="menu-item " data-value ="((Math.sin(Math.cos(t*vf)*(5+vp-1)))*((Math.sin(t*vf)**7)))*va "> Pulse Wave</ div >
111+ < div class ="menu-item " data-value ="((Math.sin(Math.atanh(Math.sin(t*vf)))*va*Math.asinh(Math.tan(Math.cos(t*vf+Math.cos(t*vf))))*va)/(Math.sin(Math.cos(t*vf))*va)) "> Needle Wave</ div >
112+ < div class ="menu-item " data-value ="(((2)/(Math.PI))*Math.asin(Math.sin(t*vf)))*(((2)/(Math.PI))*Math.acos(Math.cos(t*vf)))*va "> Fin Wave</ div >
113+ < div class ="menu-item " data-value ="Math.asin(Math.sin(2*t*vf)*Math.sin(t*vf))+Math.asin(Math.sin(2*t*vf))*Math.asin(Math.sin(t*vf*5))*va "> Trisine Wave</ div >
114+ < div class ="menu-item " data-value ="((Math.sin(t*vf*2)**5)+Math.sin(t*vf)-Math.asin(Math.sin(t*vf*2))*Math.asin(Math.cos(t*vf*2))-Math.sin(Math.tan(t*vf*9)))*((va)/(3)) "> Lightning Wave</ div >
115+ < div class ="menu-item " data-value ="(((2)/(Math.PI))*Math.asin(Math.sin(t*vf))+(Math.sin(t*vf))^19)*((va)/(2)) "> Drip Wave</ div >
116+ < div class ="menu-item " data-value ="(((2)/(Math.PI))*Math.asin(Math.sin(2*t*vf))*Math.sin(t*vf)*1.4)*va "> Bird Wave</ div >
117+ < div class ="menu-item " data-value ="Math.sin(Math.tan(t*vf)*Math.sign(Math.cos(t*99999*vf)))*va "> Noisy Infinity Wave</ div >
118+ </ div >
92119
93120 < br />
94121 < p > Use ** instead of ^ for exponents</ p >
@@ -147,6 +174,7 @@ <h1>WavePlayerJS</h1>
147174 let themeBtn = document . getElementById ( "theme-button" ) ;
148175 let pagebody = document . body ;
149176 let elements = document . querySelectorAll ( "button, input, textarea" ) ;
177+ let premenu = document . getElementById ( "presetMenu" ) ;
150178
151179 if ( dark == 0 ) {
152180 // Switch to dark mode
@@ -157,6 +185,7 @@ <h1>WavePlayerJS</h1>
157185 el . style . background = "#323232" ;
158186 el . style . color = "#f0f0f0" ;
159187 }
188+ premenu . style . background = "#454545" ;
160189 dark = 1 ;
161190 } else if ( dark == 1 ) {
162191 // Switch to light mode
@@ -167,9 +196,30 @@ <h1>WavePlayerJS</h1>
167196 el . style . background = "" ;
168197 el . style . color = "" ;
169198 }
199+ premenu . style . background = "#eee" ;
170200 dark = 0 ;
171201 }
172202}
203+
204+
205+ // Code for preset menu - created by ChatGPT
206+ const menuButton = document . getElementById ( "loadPresetBtn" ) ;
207+ const popupMenu = document . getElementById ( "presetMenu" ) ;
208+ const box = document . getElementById ( "formula" ) ;
209+
210+ // Show or hide the menu
211+ menuButton . addEventListener ( "click" , ( ) => {
212+ popupMenu . style . display =
213+ popupMenu . style . display === "none" ? "block" : "none" ;
214+ } ) ;
215+
216+ // When you click an option, write its value to the textbox
217+ popupMenu . addEventListener ( "click" , event => {
218+ const item = event . target . closest ( ".menu-item" ) ;
219+ if ( ! item ) return ; // clicked outside an item
220+ box . value = item . dataset . value ;
221+ popupMenu . style . display = "none" ; // hide the menu again
222+ } ) ;
173223</ script >
174224</ body >
175225</ html >
0 commit comments