Wavelength = 500
Amplitude = 100
Time Period = 4
Transverse Wave
Simple simulation of a Transverse Wave.
A simple example is a wave on a string. Transverse Waves are waves in which particles are moving in a direction perpendicular to the wave proparation.
The wave is a sinusoidal wave with a wavelength of 200 pixels and an amplitude of 100 pixels.
You can play with the wavelength, amplitude and time period of the wave.
Quick tip: The wave looks beautiful when the wavelength is above 900 and time period is less than 3 and amplitude is less than 70.
Code
elem=document.querySelector(".example-container");
setCanvas(elem);
t=0;
t2=0;
function draw(){
lambda=document.getElementById("lambda").value;
amp=document.getElementById("amp").value;
timep=document.getElementById("timep").value;
clearCanvas();
points=[]
for(i=0;i<WIDTH;i++){
points.push([i,HEIGHT/2+amp*sin(i*2*PI/lambda-t*2*PI/timep)]);
}
new polygon(points,'#695fe6',0,'#695fe6',3,false);
t+=0.01;
requestAnimationFrame(draw);
}
draw();
document.getElementById("lambda").addEventListener("input",function(){
document.getElementById("wlval").innerHTML=this.value;
});
document.getElementById("amp").addEventListener("input",function(){
document.getElementById("aval").innerHTML=this.value;
});
document.getElementById("timep").addEventListener("input",function(){
document.getElementById("tval").innerHTML=this.value;
});