# I need help for processing task

**URL:** <https://discourse.processing.org/t/i-need-help-for-processing-task/10252>\
**Category:** Coding Questions\
**Created:** [April 14, 2019, 7:04am UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252 "2019-04-14T07:04:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![derecH](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@derecH](https://discourse.processing.org/u/derecH)\
**Post date:** [April 14, 2019, 7:04am UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252/1 "2019-04-14T07:04:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [April 14, 2019, 7:07am UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252/2 "2019-04-14T07:07:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![derecH](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@derecH](https://discourse.processing.org/u/derecH)\
**Post date:** [April 15, 2019, 3:57pm UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252/3 "2019-04-15T15:57:40Z")

</div>

```auto
  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();
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 15, 2019, 3:59pm UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252/4 "2019-04-15T15:59:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![derecH](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@derecH](https://discourse.processing.org/u/derecH)\
**Post date:** [April 20, 2019, 11:10am UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252/5 "2019-04-20T11:10:16Z")

</div>

The problem is:

- Algorithm not included :[https://discourse.processing.org/t/i-need-help-for-processing-task/10252Midpoint](https://discourse.processing.org/t/i-need-help-for-processing-task/10252Midpoint)
- if I exchange point coordinates ,no line  
(Sorry but I’m your beginner).

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++;  
}

}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 20, 2019, 11:44am UTC](https://discourse.processing.org/t/i-need-help-for-processing-task/10252/6 "2019-04-20T11:44:05Z")

</div>

Do some research on the web

// [https://www.geeksforgeeks.org/mid-point-line-generation-algorithm/](https://www.geeksforgeeks.org/mid-point-line-generation-algorithm/)

**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

```auto

// 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++;
  }
}

```
