Hướng dẫn dùng processing rect python

Name

rect[]

Description

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.

To draw a rounded rectangle, add a fifth parameter, which is used as the radius value for all four corners.

To use a different radius value for each corner, include eight parameters. When using eight parameters, the latter four set the radius of the arc at each corner separately, starting with the top-left corner and moving clockwise around the rectangle.

Examples

  • size[400, 400];
    rect[120, 80, 220, 220];
    

  • size[400, 400];
    rect[120, 80, 220, 220, 28];

  • size[400, 400];
    rect[120, 80, 220, 220, 12, 24, 48, 72];

Syntax

  • rect[a, b, c, d]
  • rect[a, b, c, d, r]
  • rect[a, b, c, d, tl, tr, br, bl]

Parameters

  • a[float]x-coordinate of the rectangle by default
  • b[float]y-coordinate of the rectangle by default
  • c[float]width of the rectangle by default
  • d[float]height of the rectangle by default
  • r[float]radii for all four corners
  • tl[float]radius for top-left corner
  • tr[float]radius for top-right corner
  • br[float]radius for bottom-right corner
  • bl[float]radius for bottom-left corner

Related

Name

rectMode[]

Description

Modifies the location from which rectangles are drawn by changing the way in which parameters given to rect[] are interpreted.

The default mode is rectMode[CORNER], which interprets the first two parameters of rect[] as the upper-left corner of the shape, while the third and fourth parameters are its width and height.

rectMode[CORNERS] interprets the first two parameters of rect[] as the location of one corner, and the third and fourth parameters as the location of the opposite corner.

rectMode[CENTER] interprets the first two parameters of rect[] as the shape's center point, while the third and fourth parameters are its width and height.

rectMode[RADIUS] also uses the first two parameters of rect[] as the shape's center point, but uses the third and fourth parameters to specify half of the shape's width and height.

The parameter must be written in ALL CAPS because Processing is a case-sensitive language.

Examples

  • size[400, 400];
    rectMode[CORNER];  // Default rectMode is CORNER
    fill[255];  // Set fill to white
    rect[100, 100, 200, 200];  // Draw white rect using CORNER mode
    
    rectMode[CORNERS];  // Set rectMode to CORNERS
    fill[100];  // Set fill to gray
    rect[100, 100, 200, 200];  // Draw gray rect using CORNERS mode

  • size[400, 400];
    rectMode[RADIUS];  // Set rectMode to RADIUS
    fill[255];  // Set fill to white
    rect[200, 200, 120, 120];  // Draw white rect using RADIUS mode
    
    rectMode[CENTER];  // Set rectMode to CENTER
    fill[100];  // Set fill to gray
    rect[200, 200, 120, 120];  // Draw gray rect using CENTER mode

Parameters

  • mode[int]either CORNER, CORNERS, CENTER, or RADIUS

Related

Name

square[]

Description

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

Examples

Syntax

  • square[x, y, extent]

Parameters

  • x[float]x-coordinate of the rectangle by default
  • y[float]y-coordinate of the rectangle by default
  • extent[float]width and height of the rectangle by default

Related

Bài Viết Liên Quan

Chủ Đề