A little help is needed !?

Can anybody pls educate me how did the writer measure the following two rect () to produce (1,2, 4,3) ( I understood only 1,2 touching the coordinate 1 (x), 2 (y) part ).

Rect () (3,2,4,2). I understood only (3,2) coordinate but not 4,2.

Any input in this matter will get greatly appreciated. Thanks heaps

The rect() function needs 4 arguments, 2 are coordinates and the other 2 specify the size:
rect(x, y, width, height)

4,2 is referring to the size of the rectangle, not coordinates. So it is saying “draw a rectangle at 3,2 that is 4 pixels wide and 2 pixels tall.”

It’s important to understand what data these functions are asking for, and the reference will tell you! All hail the reference!

The line example says line(x1, y1, x2, y2). It is drawing a line between those 2 specified points. It asks for 4 numbers just like the rect, but they do something completely different.

Here is more info on the rect function straight from the reference:

Draws a rectangle to the screen. A rectangle is a four-sided shape with every angle at ninety degrees. By default, the first two parameters set the location of the upper-left corner, the third sets the width, and the fourth sets the height. The way these parameters are interpreted, however, may be changed with the rectMode() function.

3 Likes