# Uniform convergence: Illustration
x <- seq(0, 2, len=101)
f <- function(x, n) {
  if (missing(n)) {
    return(1*(x > 1))
  } else {
    (x <= 1)*x^n + (x > 1)
  }
}
for (i in 1:3) {
  plot(x, f(x, 1), type='n', bty='n', xlab='x', ylab='f(x)', las=1, ylim=c(-0.1, 1.1))
  polygon(c(0, 1, 1, 0), c(-0.05, -0.05, 0.05, 0.05), border=NA, col='gray')
  polygon(c(1, 2, 2, 1), c(0.95, 0.95, 1.05, 1.05), border=NA, col='gray')
  lines(x, f(x, 1), lwd=2, col="#008DFFFF")
  if (i > 1) lines(x, f(x, 2), lwd=2, col="#008DFFFF")
  if (i > 2) lines(x, f(x, 5), lwd=2, col="#008DFFFF")
  lines(0:1, c(0, 0), lwd=3)
  lines(1:2, c(1, 1), lwd=3)
}

