# [Java] An Introduction to Programming for College Students: Various Functions for Rectangle (Part 1)

- With Qiita, it is difficult to print only the text part. Therefore, the same contents are also posted on the following pages. If you want to print out or convert to PDF, please use this page:

http://gurakura.sakura.ne.jp/hellomondrian/rect2/

Click here for a list: http://gurakura.sakura.ne.jp/series/ Introduction to programming for art students/

Qiita version general table of contents: https://qiita.com/iigura/items/37180d127da93d0b8abb

# Free way to draw a rectangle

The rectangle drawn by the function rect was a rectangle composed of horizontal and vertical line segments. However, not only a rectangle is a rectangle, but the definition of a rectangle includes more free-form rectangles.

The quad function is a function for drawing such a free rectangle. The arguments are quad(x1,y1, x2,y2, x3,y3, x4,y4), respectively

x1,y1: x and y coordinates of the first vertex x2,y2: the x and y coordinates of the second vertex x3,y3: the x and y coordinates of the third vertex x4,y4: x and y coordinates of the 4th vertex

Will be.

▽ This kind of notation feels a little redundant, so after that, for i=1,…,4,

\[x_i,y_i :\mbox{x and y coordinates of the i-th vertex}\]It may also be written as.

Actually draw a square using the quad function

```
background(250,250,250);
size(500,500);
strokeWeight(10);
stroke(0,64,255);
fill(255,0,0);
quad(70,50, 80,400, 400,300, 250,280);
```

At first glance, this square looks like a triangle, but it’s a solid square with four vertices.

Since the quad function only draws the figure that connects the four specified vertices, it may not be a quadrangle depending on the parameters given (see the program and figure below).

Processing will not give any errors or warnings in such cases, so be sure to always check that the intended rectangle is drawn.

```
background(250,250,250);
size(500,500);
strokeWeight(10);
stroke(0,64,255);
fill(255,0,0);
quad(70,50, 80,400, 400,300, 150,480);
```