Plotting a scrolling Graph

as i argue already i advice against it,
but you can as a first step change

k++;

to

k +=2;