a =. ; b  =   . ; x =. ;

a0  :=   (1/π) NIntegrate[f[x] , {x, -π, π}]; 
    a[n_]  :=  (1/π) 
        NIntegrate[f[x] Cos[n  x], {x, -π, π}]; 
    b[n_]  :=  (1/π) 
        NIntegrate[f[x] Sin[n  x], {x, -π, π}];

f[x_]  :=  
      1.2 + Which[x < -2, -1, x  <  2, x/2, 
          True, -1]

as  =   a  /@  nx;
bs  =   b  /@  nx;

ah[n_]  :=  E^(-n^2 t) Cos[n  x]; 
    bh[n_]  :=  E^(-n^2 t) Sin[n  x];

ag  =  ah /@  nx; 
bg  =  bh  /@  nx;

f[x_, t_]   =  (a0/2)  + ag . as  +   bg  .  bs;

f[x_, 0]  =  f[x];

Plot[f[x, #], {x, -π, π}, 
            PlotStyle  ->  {Thickness[ .004], Hue[ .07]},  
            PlotRange  -> {0, 2.3}] &  /@    Range[0, 
          5,  .01];