5. Given a square $A B C D$ with side length 1, $E$ is the midpoint of side $C D$, and a moving point $P$ travels along the perimeter of the square $A B C D$ in the direction $A$ $\rightarrow B \rightarrow C \rightarrow E$. Let the distance traveled by point $P$ be $x$, and the area of $\triangle A P E$ be $y$. Then the graph of $y$ as a function of $x$ 

is roughly one of the graphs in Figure 1 ( ).
(A)
(B)
(C)
(D)
Figure 1
5. A.

As shown in Figure 5 (a), when $0 < x \leqslant 1$, $A P = x$, hence $y = \frac{1}{2} x$;
As shown in Figure 5 (b), when $1 < x \leqslant 2$, $B P = x - 1$,
$$
\begin{array}{l}
C P = 2 - x \text{. Therefore,} \\
y = S_{\text{square } A B C D} - S_{\triangle A B P} - S_{\triangle E C P} - S_{\triangle A D E} \\
= -\frac{1}{4} x + \frac{3}{4} \text{; }
\end{array}
$$

Figure 5
As shown in Figure 5 (c), when $2 < x < \frac{5}{2}$,
$$
E P = \frac{5}{2} - x \text{. }
$$

Therefore, $y = \frac{1}{2} \left( \frac{5}{2} - x \right) \times 1 = \frac{5}{4} - \frac{1}{2} x$.