# I need help for processing task

Hi all! I need help for processing task.
Condition:

setup{}
draw{}
own Section drawing{}
other own functions{}
mousepressed{}
keypressed{}

project:
Section Sketching Function (Incremental Algorithm or Midpoint Algorithm)
-has 2 point coordinates as input parameter
-draws the same section on the interchanged point coordinates
-draws the same point on the same point with the point they define

And what code do you have so far? What have you tried? What works? What doesn’t? Are you getting a result different from what you expect?

3 Likes
``````  size(600, 400);
noLoop();
smooth();

}

void draw() {
println(mouseX + "\t" + mouseY);

if ( (frameCount & 1) == 0 ) {
point(mouseX, mouseY);
return;
}

line(pmouseX, pmouseY, mouseX, mouseY);
println();
}

void mouseClicked() {
redraw();
}
``````

Okay – did you solve your problem with this code, or is something not working?

1 Like

The problem is:

void setup() {
size(640, 480);
noLoop();
smooth();
}

void draw() {
vonal(100,0,222,102);
println();
}

void vonal(int x1,int x2, int y1, int y2){
int dx,dy,d,x,y;
dx = x2-x1 ;
dy = y2-y1;
d = 2*(dy-dx);
x=x1;
y=y1;
for (int i=1;i<dx;i++)
{
point(x,y);
if(d>0){
y++;
d+=2*(dy-dx);
}
else
{
d+=2*dy;
}
x++;
}

}

Do some research on the web

My code

my code is just a wild guess.

You have to write code for the situation when x2 < x1 or y2 < y1 I think

Chrisir

``````
// https://www.geeksforgeeks.org/mid-point-line-generation-algorithm/
void setup() {
size(640, 480);
//noLoop();
smooth();
}

void draw() {
stroke(0);
vonal(100, 230, 222, 402);
// println();
}

void vonal(int x1, int x2, int y1, int y2) {
int dx, dy, d, x, y;
dx = x2-x1;
x=x1;
y=y1;
dx = x2-x1;
dy = y2-y1;
d = 2*(dy-dx);

for (int i=1; i<dx; i++) {

ellipse(x, y, 4, 4);
if (d>0) {
y++;
d+=2*(dy-dx);
} else
{
d+=2*dy;
}
x++;
}
}
``````