Hey guys,
I’m new at processing and I would like to do a simple task: draw a line without using the line() function.
I already have this code:
void setup() {
size(1300, 800);
}
float x1=100;
float x2=200;
float y1=1;
float y2=779;
float m=(y2-y1)/(x2-x1);
void draw()
{
drawAline(x1,y1,x2,y2);
}
void drawAline(float xa,float ya, float xb, float yb){
if(xa<xb){
while(xa<xb){
xa++;
ya=m+ya;
point(xa,ya);
}
}
if(xa>xb){
while(xa>xb){
xa--;
ya=ya-m;
point(xa,ya);
}
}
if(xa==xb){
if(ya>yb)
{
while(ya>yb){
yb++;
point(xb,yb);
}
}
if(yb>ya){
while(yb>ya){
ya++;
point(xa,ya);
}
}
if(ya==yb){
point(xa,ya);
}
}
}
In some ways it works well because the line is continious, but sometimes the line is dashed. What else should I add to make it work?
I hope you can help me on this! Thanks!