# 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')
  text(0.95, 0.1, expression(f))
  lines(x, f(x, 1), lwd = 2, col = "#008DFFFF")
  text(0.5, 0.6, expression(f[1]))
  if (i > 1) {
    lines(x, f(x, 2), lwd = 2, col = "#008DFFFF")
    text(0.55, 0.4, expression(f[2]))
  }
  if (i > 2) {
    lines(x, f(x, 5), lwd = 2, col = "#008DFFFF")
    text(0.7, 0.25, expression(f[3]))
  }
  lines(0:1, c(0, 0), lwd = 3)
  lines(1:2, c(1, 1), lwd = 3)
}

