Couldn't find the code so I re-wrote it (with much head scratching)........
Its in PocketC for PalmOS, but it's syntax is almost identical to normal C.
And don't complain about not knowing C because its bloody obvious what the code does!
When I first wrote it, it was pretty fast, this time I haven't had time to optimise it fully, there are some quite glaring slow areas, but I'll edit the post if I get a free minute.PHP Code://Circle Algorithm
library "PToolboxLib" //this is a library which contains the SetPixel() funtion, which simply draws a black dot on the screen
int i,k,a,b,c,d,e,f,g,h; //declare some integers and floats (like singles in VB)
float j,t;
//my algorithm
//##########################
circle(int x,int y,float r)
{
j=r*r; //radius squared
t=(0.7071068*r)+1;
for(i=0;i<=t;i++) //VB equivalent: [b]For i = 0 to t[/b]
{
k=sqrt(j-(i*i)); //k set to the height of the minute hand above 3 o'clock-9 o'clock line when i defines horizontal distance from (x,y), using pythagoras's theorem
//these next 8 lines are for speed, halves the number of calculations needed
a=x-i;
b=x+i;
c=x-k;
d=x+k;
e=y-i;
f=y+i;
g=y-k;
h=y+k;
//weirdly, the code ran a bit faster on my PalmOS device when I wrote each function call individually (rather than in a loop), this is at the expense of a larger executable file, but not by much...
SetPixel(b,g); //North-Right
SetPixel(a,g); //North-Left
SetPixel(d,e); //East-Up
SetPixel(d,f); //East-Down
SetPixel(a,h); //South-Left
SetPixel(b,h); //South-Right
SetPixel(c,e); //West-Up
SetPixel(c,f); //West-Down
} //end of for loop
} //end of function definition
//#########################
main() //this is just a demo program to show circle() in action
{
graph_on(); //clear form
circle(80,80,79.5); //call my function, circle radius at (80,80) and the radius is 79.5
wait(); //pauses so you can admire the beautiful circle
}





Reply With Quote