These weren't done by myself but I find them handy sometimes.
Fast linedraw. Works on every angle and without any gaps in the line:
Code:
int sgn (long a)
{
if (a > 0) return +1;
else if (a < 0) return -1;
else return 0;
}
void Line(int x1, int y1, int x2, int y2, int mode)
{
long u,s,v,d1x,d1y,d2x,d2y,m,n;
int i;
u = x2-x1;
v = y2-y1;
d1x = sgn(u);
d1y = sgn(v);
d2x = sgn(u);
d2y = 0;
m = abs(u);
n = abs(v);
if (m<=n)
{
d2x = 0;
d2y = sgn(v);
m = abs(v);
n = abs(u);
}
s = (int)(m / 2);
for (i=0;i<ceil(m);i++)
{
Plot(x1,y1,mode);
s += n;
if (s >= m)
{
s -= m;
x1 += d1x;
y1 += d1y;
}
else
{
x1 += d2x;
y1 += d2y;
}
}
}
And fast circledraw:
Code:
void CirclePoint(long cx,long cy,long x,long y,char mode)
{
if (x==0)
{
Plot(cx,cy+y,mode);
Plot(cx,cy-y,mode);
Plot(cx+y,cy,mode);
Plot(cx-y,cy,mode);
}
else if (x==y)
{
Plot(cx+x,cy+y,mode);
Plot(cx-x,cy+y,mode);
Plot(cx+x,cy-y,mode);
Plot(cx-x,cy-y,mode);
}
else if (x<y)
{
Plot(cx+x,cy+y,mode);
Plot(cx-x,cy+y,mode);
Plot(cx+x,cy-y,mode);
Plot(cx-x,cy-y,mode);
Plot(cx+y,cy+x,mode);
Plot(cx-y,cy+x,mode);
Plot(cx+y,cy-x,mode);
Plot(cx-y,cy-x,mode);
}
}
void Circle(long xcenter, long ycenter, long radius, int mode)
{
long x=0;
long y=radius;
long p=(5-radius*4)/4;
CirclePoint(xcenter,ycenter,x,y,mode);
while(x<y)
{
x++;
if (p<0)
{
p+=2*x+1;
}
else
{
y--;p+=2*(x-y)+1;
}
CirclePoint(xcenter,ycenter,x,y,mode);
}
}
I'll post some other stuff to the demo-thread.