Im using de DDA (Digital Diferential Analizer) to make a line, and thought I know maybe using de DrawLine the way I am, just run along with it. Im trying to make different types of lines like dashed or dotted, etc. Im thinking in makeing the for from below jump some numbers to make a dotted line. But I cant still find a way todo it. This is what I have so far:
public void paint(Graphics g) {
super.paint(g);
int dot=0;
int x1 = pointStart.x;
int x2 = pointEnd.x;
int y1 = pointStart.y;
int y2 = pointEnd.y;
float dx, dy, m, y, x;
if (x1>x2){
int ax = x2;
int ay = y2;
x2 = x1;
x1 = ax;
y2 = y1;
y1 = ay;
}
dx = x2 - x1;
dy = y2 - y1;
m = dy/dx;
if (m>=-1&&m<=1){
dot = (int)dx/4;
y = y1;
System.out.println(m);
for (x = x1 ; x <= x2;x++){
//if (x>=dot&&x<=dot+10||x>=dot*2&&x<=dot*2+10||x>=dot*3&&x<=dot*3+10){
g.drawLine((int)x, (int)Math.round(y), (int)x, (int)Math.round(y));
y+=m;
//}
}
}
else{
x = x1;
System.out.println(m);
for (y = y1 ; y <= y2;y++){
g.drawLine((int)Math.round(x), (int)y, (int)Math.round(x), (int)y);
x+=1/m;
}
}
/*if (pointStart != null) {
if (x1>)
g.setColor(Color.RED);
//g.drawLine(pointStart.x, pointStart.y, pointEnd.x, pointEnd.y);
g.drawLine(x1, y1, x1, y1);
}*/
}
Any ideas?
ok so the basic idea is to segmentate any line to selected pattern for example like this:
and do not forget to reset pattern ix,l to zero before any pattern style change. Code is not optimized so its pretty slow but simple enough to understand i hope.