shape functions() Flashcards
arc()
arc(x, y, w, h, start, stop, [mode], [detail])
Draw an arc to the screen. f called with only x, y, w, h, start and stop, the arc will be drawn and filled as an open pie segment. If a mode parameter is provided, the arc will be filled like an open semi-circle (OPEN), a closed semi-circle (CHORD), or as a closed pie segment (PIE). The origin may be changed with the ellipseMode() function.
ellipse()
ellipse(x, y, w, [h])
Draws an ellipse (oval) to the screen. By default, the first two parameters set the location of the center of the ellipse, and the third and fourth parameters set the shape’s width and height. If no height is specified, the value of width is used for both the width and height.
circle()
circle(x, y, d)
Draws a circle to the screen. A circle is a simple closed shape. It is the set of all points in a plane that are at a given distance from a given point, the centre. This function is a special case of the ellipse() function, where the width and height of the ellipse are the same. Height and width of the ellipse correspond to the diameter of the circle.
line()
line(x1, y1, x2, y2)
Draws a line (a direct path between two points) to the screen. If called with only 4 parameters, it will draw a line in 2D with a default width of 1 pixel. This width can be modified by using the strokeWeight() function. A line cannot be filled, therefore the fill() function will not affect the color of a line. So to color a line, use the stroke() function.
point()
point(x, y, [z]
Draws a point, a coordinate in space at the dimension of one pixel. The first parameter is the horizontal value for the point, the second param is the vertical value for the point. The color of the point is changed with the stroke() function. The size of the point can be changed with the strokeWeight() function.
quad()
quad(x1, y1, x2, y2, x3, y3, x4, y4, [detailX], [detailY])
Draws a quad on the canvas. A quad is a quadrilateral, a four sided polygon. It is similar to a rectangle, but the angles between its edges are not constrained to ninety degrees. The first pair of parameters (x1,y1) sets the first vertex and the subsequent pairs should proceed clockwise or counter-clockwise around the defined shape.
rect()
rect(x, y, w, [h], [tl], [tr], [br], [bl])
Draws a rectangle on the canvas. A rectangle is a four-sided closed 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, may be changed with the rectMode() function.
The fifth, sixth, seventh and eighth parameters, if specified, determine corner radius for the top-left, top-right, lower-right and lower-left corners, respectively. An omitted corner radius parameter is set to the value of the previously specified radius value in the parameter list.
triangle()
triangle(x1, y1, x2, y2, x3, y3)
Draws a triangle to the canvas. A triangle is a plane created by connecting three points. The first two arguments specify the first point, the middle two arguments specify the second point, and the last two arguments specify the third point.
square()
square(x, y, s, [tl], [tr], [br], [bl])
Draws a square to the screen. A square is a four-sided shape with every angle at ninety degrees, and equal side size. This function is a special case of the rect() function, where the width and height are the same, and the parameter is called “s” for side size. By default, the first two parameters set the location of the upper-left corner, the third sets the side size of the square. The way these parameters are interpreted, may be changed with the rectMode() function.
The fourth, fifth, sixth and seventh parameters, if specified, determine corner radius for the top-left, top-right, lower-right and lower-left corners, respectively. An omitted corner radius parameter is set to the value of the previously specified radius value in the parameter lis
ellipseMode()
ellipseMode(mode)
Modifies the location from which ellipses are drawn by changing the way in which parameters given to ellipse(), circle() and arc() are interpreted.
The default mode is CENTER, in which the first two parameters are interpreted as the shape’s center point’s x and y coordinates respectively, while the third and fourth parameters are its width and height.
ellipseMode(RADIUS) also uses the first two parameters as the shape’s center point’s x and y coordinates, but uses the third and fourth parameters to specify half of the shapes’s width and height.
ellipseMode(CORNER) interprets the first two parameters as the upper-left corner of the shape, while the third and fourth parameters are its width and height.
ellipseMode(CORNERS) interprets the first two parameters as the location of one corner of the ellipse’s bounding box, and the third and fourth parameters as the location of the opposite corner.
The parameter to this method must be written in ALL CAPS because they are predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
noSmooth() & smooth()
Draws all geometry with jagged (aliased) edges. Note that smooth() is active by default in 2D mode, so it is necessary to call noSmooth() to disable smoothing of geometry, images, and fonts. In 3D mode, noSmooth() is enabled by default, so it is necessary to call smooth() if you would like smooth (antialiased) edges on your geometry.
rectMode()
rectMode(MODE)
Modifies the location from which rectangles are drawn by changing the way in which parameters given to rect() are interpreted.
The default mode is CORNER, which interprets the first two parameters 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 as the location of one of the corners, and the third and fourth parameters as the location of the diagonally opposite corner. Note, the rectangle is drawn between the coordinates, so it is not neccesary that the first corner be the upper left corner.
rectMode(CENTER) interprets the first two parameters 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 as the shape’s center point, but uses the third and fourth parameters to specify half of the shape’s width and height respectively.
The parameter to this method must be written in ALL CAPS because they are predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
strokeCap()
strokeCap(cap)
Constant: either ROUND, SQUARE or PROJECT
Sets the style for rendering line endings. These ends are either rounded, squared or extended, each of which specified with the corresponding parameters: ROUND, SQUARE and PROJECT. The default cap is ROUND.
The parameter to this method must be written in ALL CAPS because they are predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
strokeJoin()
strokeJoin(join)
Constant: either MITER, BEVEL, ROUND
Sets the style of the joints which connect line segments. These joints are either mitered, beveled or rounded and specified with the corresponding parameters MITER, BEVEL and ROUND. The default joint is MITER.
The parameter to this method must be written in ALL CAPS because they are predefined as constants in ALL CAPS and Javascript is a case-sensitive language.
strokeWeight()
strokeWeight(weight)
Number: the weight of the stroke (in pixels)
Sets the width of the stroke used for lines, points and the border around shapes. All widths are set in units of pixels.
Note that it is affected by any transformation or scaling that has been applied previously.