Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 02_LAB_serial_protocol by
Diff: draw.cpp
- Revision:
- 17:a0b884f78802
- Parent:
- 15:92cfae44483c
- Child:
- 18:08bd68471535
--- a/draw.cpp Thu Oct 12 01:30:06 2017 +0000 +++ b/draw.cpp Thu Oct 19 23:38:01 2017 +0000 @@ -80,16 +80,52 @@ void line_n(float xi, float yi, float xf, float yf) { - float xp; float yp; - float m= (yf-yi)/(xf-xi); - float b=yf-m*xf; - - for (xp =xi;xp<=xf;xp+=RSTEP) + float xp; float yp; + float m; float b; + int st=1 ; + int run=1; + m=(float)(yf-yi)/(xf-xi); + + if (abs(m)<=1){ + b=(float)yf-(float)(m*xf); + // command.printf(" m = %f b= %f \n", m,b); + xp =xi; + while(run) { - yp =m*xp+b; - vertex2d(xp,yp); + yp =m*xp+b; + vertex2d(xp ,yp); + //print_bin2hex(xp); print_bin2hex(yp); + //command.printf(" \n"); + if (xf>xi){ + xp=xp+st; + if (xp>xf)run=0; + }else { + xp-=st; + if (xp<xf)run=0; + } + } - + }else{ + m=(float)(xf-xi)/(yf-yi); + b=(float)xf-(float)(m*yf); + // command.printf(" m = %f b= %f \n", m,b); + yp =yi; + while(run) + { + xp =m*yp+b; + vertex2d(xp ,yp); + // print_bin2hex(xp); print_bin2hex(yp); + // command.printf(" \n"); + if (yf>yi){ + yp=yp+st; + if (yp>yf)run=0; + }else { + yp-=st; + if (yp<yf)run=0; + } + + } + } } void line(float xi, float yi, float xf, float yf) { @@ -117,7 +153,7 @@ void circle(float x, float y, float radio) { initdraw(x+radio,y); - // coloque codigo aca + // coloque codigo nodraw(); } \ No newline at end of file