Hi im sure ive put this post in the right place as it is about 2d graphics but not the actual graphic functions supplied by java. infact im trying out writing a line algerithm. below is what i have so far, it should work for 25% of line angles. but it doesnt. can someone please point me the right way. thankyou.
private void drawLine(int x1, int y1, int x2, int y2)
{
int dX = 0, dY = 0;//device x and y
int q = Math.min(x1, x2);//
// //top left hand side
int p = Math.min(y1, y2);//
//Calculate the slope
float m = (float) (y1 - y2) / (float) (x1 - x2);
if (m > 0)// posetive slope rises left to right
{
if (y1 - y2 >= x1 - x2)//taller so dify*pixels
{
for (float y = 0; y <= y1 - y2; y++)
{
dY = GMath.floatToInt(y + p);//(Math.min(y1,y2));
dX = GMath.floatToInt((y * m) + q);
g.drawLine(dX, dY, dX, dY);
}
}
else//wider so difx*pixels
{
}
}
else //negative slope // falls left to right
{
if (x1 - x2 <= y1 - y2)//taller so dify*pixels
{
}
else//wider so difx*pixels
{
}
}
}
thankyou for your help.