# Introduction to Programming for College Students: Various Functions Related to Rectangle (Part 1)

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

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

# How to draw a free rectangle

The rectangle drawn by the function rect was a rectangle composed of horizontal and vertical line segments. However, rectangles are not the only rectangles, and the definition of a rectangle also 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: x and y coordinates of the second vertex x3, y3: x and y coordinates of the 3rd vertex x4, y4: x and y coordinates of the 4th vertex

It will be.

This kind of notation seems a bit 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.

Let's actually draw a rectangle using the quad function

``````background(250,250,250);
size(500,500);

strokeWeight(10);
stroke(0,64,255);
fill(255,0,0);
`````` At first glance, this rectangle looks like a group of triangles, but it is a solid rectangle with four vertices.

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

Even in such a case, Processing does not issue any error or warning, so always check that the rectangle is drawn as intended.

``````background(250,250,250);
size(500,500);

strokeWeight(10);
stroke(0,64,255);
fill(255,0,0); 