# Question about a simple code using lines and rectangles

**URL:** <https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402>\
**Category:** Coding Questions\
**Created:** [September 19, 2026, 8:12pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402 "2026-09-19T20:12:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesP](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@JamesP](https://discourse.processing.org/u/JamesP)\
**Post date:** [September 19, 2026, 8:12pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/1 "2026-09-19T20:12:48Z")

</div>

Why is it that I have to use (100,40,400,210) to make the rectangle the same size as the lines? I would have thought I could use (100,40,500,250). It doesn’t make sense to me that 400, 210 is at the same spot as where my line ends but it is at 500, 250.

 ![Screenshot 2026-09-19 at 9.04.27 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/b/1bbabcc92232562ccb2fcbf1f56114a068ddc78d.jpeg)

---

<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:** [September 19, 2026, 8:21pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/2 "2026-09-19T20:21:25Z")

</div>

The reason is this

Line works with x1,y1 and x2,y2

rect works with x,y and w,h

Hence the difference

---

<div class="post-metadata">

**Author:** ![JamesP](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@JamesP](https://discourse.processing.org/u/JamesP)\
**Post date:** [September 19, 2026, 8:23pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/3 "2026-09-19T20:23:19Z")

</div>

Oh I understand now. Thank you!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 19, 2026, 8:32pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/4 "2026-09-19T20:32:44Z")

</div>

You can use the `rectMode` function to change how the parameters are interpreted, for instance `rectMode(CORNERS)` works with x1,y1 and x2,y2

```auto
void setup(){
  size(640, 480);
}

void draw(){
  background(200);
  rectMode(CORNERS);
  
  noStroke();
  fill(128,128,255);
  rect(100, 40, 500, 250);
  
  stroke(0);
  strokeWeight(5);
  line(100, 40, 500, 250);
  
  strokeWeight(3);
  line(500,40,100,250);
}

```

gives you

 ![Screenshot 2026-09-19 at 21.30.09](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/5/551bf2275c1d183085f785e1929868830f5a1b97.png)

---

<div class="post-metadata">

**Author:** ![JamesP](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@JamesP](https://discourse.processing.org/u/JamesP)\
**Post date:** [September 19, 2026, 8:35pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/5 "2026-09-19T20:35:27Z")

</div>

Thank you! I see how that works now. I’m literally just starting as you can tell. 😅

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 20, 2026, 6:45am UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/6 "2026-09-20T06:45:34Z")

</div>

> [@JamesP](#):
>
> I’m literally just starting

Every expert starts as a novice, enjoy the journey 😃

---

<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:** [September 20, 2026, 7:19pm UTC](https://discourse.processing.org/t/question-about-a-simple-code-using-lines-and-rectangles/49402/7 "2026-09-20T19:19:18Z")

</div>

The reference gives you info for the command

Right click on the word rect and choose “reference”

**Pro Tipp:** Ctrl-t gives you auto-format.

Every line gets changed (where necessary), better indents.

I use it all the times.

For example the content of a function (setup()) gets indent.

Chrisir
