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

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

Click here for a list: http://gurakura.sakura.ne.jp/series/美大生のためのプログラミング入門/

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

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);
quad(70,50, 80,400, 400,300, 250,280);

quad

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);
quad(70,50, 80,400, 400,300, 150,480);

invalid quad

Recommended Posts

Introduction to Programming for College Students: Various Functions Related to Rectangle (Part 2)
Introduction to Programming for College Students: Various Functions Related to Rectangle (Part 1)
Introduction to Programming for College Students: Introduction
Introduction to Programming for College Students: Variables
Introduction to Programming for College Students: How to Draw Basic Rectangle
Introduction to programming for college students (updated from time to time)
Introduction to Programming for College Students: Making a Canvas
Introduction to Programming for College Students: Preparation Let's Install Processing
Introduction to Programming for College Students: Draw a Straight Line
Introduction to Programming for College Students: Make Straight Lines More Attractive
Introduction to Practical Programming
An introduction to functional programming for object-oriented programmers in Elm
Introduction to Spring Boot Part 1
Introduction to Linux Container / Docker (Part 1)
Introduction to Functional Programming (Java, Javascript)
Introduction to Linux Container / Docker (Part 2)