Processing provides method rect()
to draw a rectangle. This code draws a white 50 X 50 rectangle on black background.
void setup() {
size(500, 500);
background(0);
fill(255);
noStroke();
}
void draw() {
rect(225, 225, 50, 50);
}
The signature of method rect()
is this.
rect(x, y, w, h);
x
and y
is the coordinate of the rectangle. w
and h
is rectangle's width and height.
Method fill()
is used to specify the filling color of the rectangle and other shapes such as ellipse, triangle, polygon.
Method noStroke()
is used to specify that that there are no strokes around the rectangle. This method also affects other shapes such as ellipse, triangle, polygon.