void picoDrawCircleRaw(int mx, int my, int r,int color) { /* A first point of the circle is x=r,y=0. For a closed circle boundary line, the next possible point is either the left neighbour (x-1,y) or the lower neighbour (x,y+1). We insert x and y into the circles defining equation x*x+y*y=r*r to calculate radius error. Whichever gives less error is the better point for the circle. From this we calculate again the best neighbour. For symmetry reasons, we only need do do it for an eighth of the circle and mirror it. */ int x=r, y=0, nrx, // new sqared radius if we dec x nry, // new sqared radius if we inc y erx, // error if we dec x ery, // error if we inc y r2=r*r, // square of r ar2=r2; // radius of a circle that goes through last drawn point do{ picoDrawPointRaw(mx+x, my+y, color); picoDrawPointRaw(mx+x, my-y, color); picoDrawPointRaw(mx-x, my+y, color); picoDrawPointRaw(mx-x, my-y, color); picoDrawPointRaw(mx+y, my+x, color); picoDrawPointRaw(mx+y, my-x, color); picoDrawPointRaw(mx-y, my+x, color); picoDrawPointRaw(mx-y, my-x, color); nry=ar2+2*y+1; // if we inc y nyr=(y+1)^2+x^2 = y^2+2y+1+x^2 = r^2+2y+1 nrx=ar2-2*x+1; // if we dec x nxr=y^2+(x-1)^2 = y^2+x^2-2x-1 = r^2-2x+1 ery=r2-nry; if (ery<0) ery=-ery; erx=r2-nrx; if (erx<0) erx=-erx; if (ery=y); }