c - MikroC, Drawing line graph -


i'm trying create function draw line graph within specific window on glcd screen.

lets window's x-axle runs pixel 24 through 205 (left right) , y-axle runs pixel 55 through 5 (low high).

i'll need graph add new value (or dot) whenever new data available. can call graph refreshing within data collection routine. thats no problem.

the latest value needs added right position on graph, 205. need clear line , draw new value/dot. no problem.

t6963c_line(205, 5, 205, 55, t6963c_black); //clearing whole line t6963c_dot(205, posy, t6963c_white);        //drawing new dot 

but i'm not sure is, how shift previous values/dots 1 place left on refreshing (each time new value/dot added on x-position 205), until reaches border of window, 22.

any appriciated!

addition:

int posy1[181]; int i1;   for(i1 = 0; i1 < 181 - 1; i1++)  {      t6963c_dot(i1 + 24, posy1[i1], t6963c_black); //erase old dots  }  for(i1 = 0; i1 < 181 - 1; i1++)  {      posy1[i1] = posy1[i1 + 1]; //shift array  }  posy1[181] = eq; //add new value (eq) array  for(i1 = 0; i1 < 181 - 1; i1++)  {      t6963c_dot(i1 + 24, posy1[i1], t6963c_white); //redraw dots  } 

create array of width of data, , store y values in there. then, on adding new value, erase previous dots, shift values in array 1 position down, , redraw them. finally, add y position of new dot @ end of array.

this general idea; there lots of optimizations possible. erase dot on known y position, don't have draw vertical line -- plotting single black dot on enough. also, don't have physically copy every plot[x+1] plot[x] -- can leave array , update offset index modulus data width.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -