b  =   . ; x =. ;

b[n_]  :=  
      2  NIntegrate[f[x] Sin[n π x], {x, 0, 1}]

a1  =   .2;  a2  =   .7; 
    f[x_]  :=  Which[x < a1, -x, x < a2, x  -  2  a1, True, 
        1 - x]

nx  =  Range[30];

bs  =   b  /@  nx

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

bg  =  bh  /@  nx;

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

f[x_, t_]   =  bg  .  bs;

Plot[f[x, #], {x, 0, 1}, 
            PlotStyle  ->  {Thickness[ .004], Hue[ .05]},  
            PlotRange  -> {- .3,  .3}] &  /@    Range[
          0,  .35,  .0025];