#Generation of plot for calm conditions
#Fix length of the harbour

wi=rep(0,100)
LL=100
plot(wi,type="l",xlim=c(0,LL),ylim=c(-5,5),col="blue",lwd=2)
abline(v=100,lwd=3)
title("Calm conditions")

#Generation of plot for incoming + reflected wave
#Fix length of the harbour, wave heigth, wave velocity, number of nodes
#Be careful: waves must be aligned to make sure that there is a fixed end at the harbour entrance.
wi=0
wii=0
H=2
LL=100
n=3
v=1
L=LL/(2*n+1)*4
T=L/v
sf=1/4*L
stop=2*LL
for(i in 1:(stop))
{
wi=H/2*cos(2*pi*(seq(sf,LL+sf)/L-i/T))
wii=H/2*cos(2*pi*(seq(sf,LL+sf)/L+i/T))
if(i<LL) wi[i+1]=0
if(i<LL) plot(wi[1:(i+1)],type="l",xlim=c(0,LL),ylim=c(-5,5)) else
plot(wi[1:i],type="l",xlim=c(0,LL),ylim=c(-5,5)) 
title("Reflected wave")
if(i>=(LL))
{
if(stop-i==0) stopp=1 else stopp=stop-i
lines(seq((stopp),(LL)),wii[(stopp):(LL)],col="red",lwd=2)
lines(seq((stopp),(LL)),wi[(stopp):(LL)]+wii[(stopp):(LL)],col="blue",lwd=2)
}
abline(v=LL,lwd=3)
abline(h=0,lwd=1,col="blue")
date_time=Sys.time()
while((as.numeric(Sys.time()) - as.numeric(date_time))<0.05){}
}

#Generation of standing wave
#Generation of plot for incoming + reflected wave
#Fix length of the harbour, wave heigth, wave velocity, number of nodes
#Be careful: waves must be aligned to make sure that there is a fixed end at the harbour entrance.
wi=0
wii=0
H=2
LL=100
n=3
v=2
L=LL/(2*n+1)*4
T=L/v
sf=1/4*L
for(i in 1:2000)
{
wi=H/2*cos(2*pi*(seq(sf,LL+sf)/L-i/T))
wii=H/2*cos(2*pi*(seq(sf,LL+sf)/L+i/T))
plot(wi,type="l",xlim=c(0,LL),ylim=c(-5,5))
title("Standing wave")
lines(wii,col="red",lwd=2)
lines(wi+wii,col="blue",lwd=2)
abline(v=LL,lwd=3)
abline(h=0,lwd=1,col="blue")
date_time=Sys.time()
while((as.numeric(Sys.time()) - as.numeric(date_time))<0.05){}
}
