diff --git a/.gitignore b/.gitignore index 4498d40..55f4b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,6 @@ flycheck_*.el # network security /network-security.data +# Javascript from CoffeeScript files in main directory +/*.js diff --git a/README.md b/README.md index 119f465..836fa4e 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,27 @@ Starting from a central polygon, one can imagine a tree _P_ of polygons created ## Implementation -As a first pass, PolyTree will consist of a Processing sketch written in CoffeeScript and intended to be served with HarpJS. +As a first pass, PolyTree will consist of a Processing sketch written in CoffeeScript along with a minimal framework for deploying it (a bit of HTML and JavaScript). + +## Running + +Although you can use any server and CoffeeScript compiler you like, one path of low resistance for running PolyTree is to use Node.js. Hence, the following procedure assumes you have the node package manager (npm) already installed. + +Make sure you have http-server and CoffeeScript installed globally (note you may need to run the following with sudo depending on your setup): +```bash +npm install -g http-server coffeescript +``` + +Clone this repository and enter its top-level directory: +``` +git clone https://code.studioinfinity.org/glen/polytree.git +cd polytree +``` + +Set coffee to compile the main script (the "--watch" flag is only necessary if you may be editing the script and would like the files being served to update automatically), and start serving the files: +``` +coffee --watch -c polytree.coffee & +http-server +``` + +Now visit http://localhost:8080 in your browser. diff --git a/index.html b/index.html new file mode 100644 index 0000000..069c296 --- /dev/null +++ b/index.html @@ -0,0 +1,5 @@ + +
+ + +description of the canvas
\n', + type: 'String' + }, + { + name: 'display', + description: 'either LABEL or FALLBACK (Optional)
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + describeElement: { + name: 'describeElement', + params: [ + { + name: 'name', + description: 'name of the element
\n', + type: 'String' + }, + { + name: 'text', + description: 'description of the element
\n', + type: 'String' + }, + { + name: 'display', + description: 'either LABEL or FALLBACK (Optional)
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + textOutput: { + name: 'textOutput', + params: [ + { + name: 'display', + description: 'either FALLBACK or LABEL (Optional)
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + gridOutput: { + name: 'gridOutput', + params: [ + { + name: 'display', + description: 'either FALLBACK or LABEL (Optional)
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + alpha: { + name: 'alpha', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + blue: { + name: 'blue', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + brightness: { + name: 'brightness', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + color: { + name: 'color', + class: 'p5', + module: 'Color', + overloads: [ + { + params: [ + { + name: 'gray', + description: + 'number specifying value between white and black.
\n', + type: 'Number' + }, + { + name: 'alpha', + description: + 'alpha value relative to current color range\n (default is 0-255)
\n', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'value', + description: 'a color string
\n', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red,green,blue &\n and alpha components of the color
\n', + type: 'Number[]' + } + ] + }, + { + params: [ + { + name: 'color', + description: '', + type: 'p5.Color' + } + ] + } + ] + }, + green: { + name: 'green', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + hue: { + name: 'hue', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + lerpColor: { + name: 'lerpColor', + params: [ + { + name: 'c1', + description: 'interpolate from this color
\n', + type: 'p5.Color' + }, + { + name: 'c2', + description: 'interpolate to this color
\n', + type: 'p5.Color' + }, + { + name: 'amt', + description: 'number between 0 and 1
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Color' + }, + lightness: { + name: 'lightness', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + red: { + name: 'red', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + saturation: { + name: 'saturation', + params: [ + { + name: 'color', + description: + 'p5.Color object, color components,\n or CSS color
\n', + type: 'p5.Color|Number[]|String' + } + ], + class: 'p5', + module: 'Color' + }, + background: { + name: 'background', + class: 'p5', + module: 'Color', + overloads: [ + { + params: [ + { + name: 'color', + description: + 'any value created by the color() function
\n', + type: 'p5.Color' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'colorstring', + description: + 'color string, possible formats include: integer\n rgb() or rgba(), percentage rgb() or rgba(),\n 3-digit hex, 6-digit hex
\n', + type: 'String' + }, + { + name: 'a', + description: + 'opacity of the background relative to current\n color range (default is 0-255)
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'gray', + description: 'specifies a value between white and black
\n', + type: 'Number' + }, + { + name: 'a', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: + 'red or hue value (depending on the current color\n mode)
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value (depending on the current\n color mode)
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value (depending on the current\n color mode)
\n', + type: 'Number' + }, + { + name: 'a', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red, green, blue\n and alpha components of the color
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'image', + description: + 'image created with loadImage() or createImage(),\n to set as background\n (must be same size as the sketch window)
\n', + type: 'p5.Image' + }, + { + name: 'a', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + clear: { + name: 'clear', + class: 'p5', + module: 'Color' + }, + colorMode: { + name: 'colorMode', + class: 'p5', + module: 'Color', + overloads: [ + { + params: [ + { + name: 'mode', + description: + 'either RGB, HSB or HSL, corresponding to\n Red/Green/Blue and Hue/Saturation/Brightness\n (or Lightness)
\n', + type: 'Constant' + }, + { + name: 'max', + description: 'range for all values
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'mode', + description: '', + type: 'Constant' + }, + { + name: 'max1', + description: + 'range for the red or hue depending on the\n current color mode
\n', + type: 'Number' + }, + { + name: 'max2', + description: + 'range for the green or saturation depending\n on the current color mode
\n', + type: 'Number' + }, + { + name: 'max3', + description: + 'range for the blue or brightness/lightness\n depending on the current color mode
\n', + type: 'Number' + }, + { + name: 'maxA', + description: 'range for the alpha
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + fill: { + name: 'fill', + class: 'p5', + module: 'Color', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'a color string
\n', + type: 'String' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'gray', + description: 'a gray value
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red,green,blue &\n and alpha components of the color
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'the fill color
\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + noFill: { + name: 'noFill', + class: 'p5', + module: 'Color' + }, + noStroke: { + name: 'noStroke', + class: 'p5', + module: 'Color' + }, + stroke: { + name: 'stroke', + class: 'p5', + module: 'Color', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'a color string
\n', + type: 'String' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'gray', + description: 'a gray value
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red,green,blue &\n and alpha components of the color
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'the stroke color
\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + erase: { + name: 'erase', + params: [ + { + name: 'strengthFill', + description: + "A number (0-255) for the strength of erasing for a shape's fill.\n This will default to 255 when no argument is given, which\n is full strength.
\n", + type: 'Number', + optional: true + }, + { + name: 'strengthStroke', + description: + "A number (0-255) for the strength of erasing for a shape's stroke.\n This will default to 255 when no argument is given, which\n is full strength.
\n", + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Color' + }, + noErase: { + name: 'noErase', + class: 'p5', + module: 'Color' + }, + arc: { + name: 'arc', + params: [ + { + name: 'x', + description: "x-coordinate of the arc's ellipse
\n", + type: 'Number' + }, + { + name: 'y', + description: "y-coordinate of the arc's ellipse
\n", + type: 'Number' + }, + { + name: 'w', + description: "width of the arc's ellipse by default
\n", + type: 'Number' + }, + { + name: 'h', + description: "height of the arc's ellipse by default
\n", + type: 'Number' + }, + { + name: 'start', + description: 'angle to start the arc, specified in radians
\n', + type: 'Number' + }, + { + name: 'stop', + description: 'angle to stop the arc, specified in radians
\n', + type: 'Number' + }, + { + name: 'mode', + description: + 'optional parameter to determine the way of drawing\n the arc. either CHORD, PIE or OPEN
\n', + type: 'Constant', + optional: true + }, + { + name: 'detail', + description: + "optional parameter for WebGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the arc. Default value is 25. Won't\n draw a stroke for a detail of more than 50.
\n", + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + ellipse: { + name: 'ellipse', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x-coordinate of the center of ellipse.
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the center of ellipse.
\n', + type: 'Number' + }, + { + name: 'w', + description: 'width of the ellipse.
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height of the ellipse.
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'w', + description: '', + type: 'Number' + }, + { + name: 'h', + description: '', + type: 'Number' + }, + { + name: 'detail', + description: + "optional parameter for WebGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the ellipse. Default value is 25. Won't\n draw a stroke for a detail of more than 50.
\n", + type: 'Integer', + optional: true + } + ] + } + ] + }, + circle: { + name: 'circle', + params: [ + { + name: 'x', + description: 'x-coordinate of the centre of the circle.
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the centre of the circle.
\n', + type: 'Number' + }, + { + name: 'd', + description: 'diameter of the circle.
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + line: { + name: 'line', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x1', + description: 'the x-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'y1', + description: 'the y-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: 'the x-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'the y-coordinate of the second point
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: 'the z-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: 'the z-coordinate of the second point
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + point: { + name: 'point', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x-coordinate
\n', + type: 'Number' + }, + { + name: 'y', + description: 'the y-coordinate
\n', + type: 'Number' + }, + { + name: 'z', + description: 'the z-coordinate (for WebGL mode)
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'coordinate_vector', + description: 'the coordinate vector
\n', + type: 'p5.Vector' + } + ], + chainable: 1 + } + ] + }, + quad: { + name: 'quad', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x1', + description: 'the x-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'y1', + description: 'the y-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: 'the x-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'the y-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'x3', + description: 'the x-coordinate of the third point
\n', + type: 'Number' + }, + { + name: 'y3', + description: 'the y-coordinate of the third point
\n', + type: 'Number' + }, + { + name: 'x4', + description: 'the x-coordinate of the fourth point
\n', + type: 'Number' + }, + { + name: 'y4', + description: 'the y-coordinate of the fourth point
\n', + type: 'Number' + }, + { + name: 'detailX', + description: 'number of segments in the x-direction
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: 'number of segments in the y-direction
\n', + type: 'Integer', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: 'the z-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: 'the z-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: 'the z-coordinate of the third point
\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: 'the z-coordinate of the fourth point
\n', + type: 'Number' + }, + { + name: 'detailX', + description: '', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: '', + type: 'Integer', + optional: true + } + ], + chainable: 1 + } + ] + }, + rect: { + name: 'rect', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x-coordinate of the rectangle.
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the rectangle.
\n', + type: 'Number' + }, + { + name: 'w', + description: 'width of the rectangle.
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height of the rectangle.
\n', + type: 'Number', + optional: true + }, + { + name: 'tl', + description: 'optional radius of top-left corner.
\n', + type: 'Number', + optional: true + }, + { + name: 'tr', + description: 'optional radius of top-right corner.
\n', + type: 'Number', + optional: true + }, + { + name: 'br', + description: 'optional radius of bottom-right corner.
\n', + type: 'Number', + optional: true + }, + { + name: 'bl', + description: 'optional radius of bottom-left corner.
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'w', + description: '', + type: 'Number' + }, + { + name: 'h', + description: '', + type: 'Number' + }, + { + name: 'detailX', + description: + 'number of segments in the x-direction (for WebGL mode)
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'number of segments in the y-direction (for WebGL mode)
\n', + type: 'Integer', + optional: true + } + ], + chainable: 1 + } + ] + }, + square: { + name: 'square', + params: [ + { + name: 'x', + description: 'x-coordinate of the square.
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the square.
\n', + type: 'Number' + }, + { + name: 's', + description: 'side size of the square.
\n', + type: 'Number' + }, + { + name: 'tl', + description: 'optional radius of top-left corner.
\n', + type: 'Number', + optional: true + }, + { + name: 'tr', + description: 'optional radius of top-right corner.
\n', + type: 'Number', + optional: true + }, + { + name: 'br', + description: 'optional radius of bottom-right corner.
\n', + type: 'Number', + optional: true + }, + { + name: 'bl', + description: 'optional radius of bottom-left corner.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + triangle: { + name: 'triangle', + params: [ + { + name: 'x1', + description: 'x-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'y1', + description: 'y-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: 'x-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'y-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'x3', + description: 'x-coordinate of the third point
\n', + type: 'Number' + }, + { + name: 'y3', + description: 'y-coordinate of the third point
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + ellipseMode: { + name: 'ellipseMode', + params: [ + { + name: 'mode', + description: 'either CENTER, RADIUS, CORNER, or CORNERS
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Shape' + }, + noSmooth: { + name: 'noSmooth', + class: 'p5', + module: 'Shape' + }, + rectMode: { + name: 'rectMode', + params: [ + { + name: 'mode', + description: 'either CORNER, CORNERS, CENTER, or RADIUS
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Shape' + }, + smooth: { + name: 'smooth', + class: 'p5', + module: 'Shape' + }, + strokeCap: { + name: 'strokeCap', + params: [ + { + name: 'cap', + description: 'either ROUND, SQUARE or PROJECT
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Shape' + }, + strokeJoin: { + name: 'strokeJoin', + params: [ + { + name: 'join', + description: 'either MITER, BEVEL, ROUND
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Shape' + }, + strokeWeight: { + name: 'strokeWeight', + params: [ + { + name: 'weight', + description: 'the weight of the stroke (in pixels)
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + bezier: { + name: 'bezier', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x1', + description: 'x-coordinate for the first anchor point
\n', + type: 'Number' + }, + { + name: 'y1', + description: 'y-coordinate for the first anchor point
\n', + type: 'Number' + }, + { + name: 'x2', + description: 'x-coordinate for the first control point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'y-coordinate for the first control point
\n', + type: 'Number' + }, + { + name: 'x3', + description: 'x-coordinate for the second control point
\n', + type: 'Number' + }, + { + name: 'y3', + description: 'y-coordinate for the second control point
\n', + type: 'Number' + }, + { + name: 'x4', + description: 'x-coordinate for the second anchor point
\n', + type: 'Number' + }, + { + name: 'y4', + description: 'y-coordinate for the second anchor point
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: 'z-coordinate for the first anchor point
\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: 'z-coordinate for the first control point
\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: 'z-coordinate for the second control point
\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: 'z-coordinate for the second anchor point
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + bezierDetail: { + name: 'bezierDetail', + params: [ + { + name: 'detail', + description: 'resolution of the curves
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + bezierPoint: { + name: 'bezierPoint', + params: [ + { + name: 'a', + description: 'coordinate of first point on the curve
\n', + type: 'Number' + }, + { + name: 'b', + description: 'coordinate of first control point
\n', + type: 'Number' + }, + { + name: 'c', + description: 'coordinate of second control point
\n', + type: 'Number' + }, + { + name: 'd', + description: 'coordinate of second point on the curve
\n', + type: 'Number' + }, + { + name: 't', + description: 'value between 0 and 1
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + bezierTangent: { + name: 'bezierTangent', + params: [ + { + name: 'a', + description: 'coordinate of first point on the curve
\n', + type: 'Number' + }, + { + name: 'b', + description: 'coordinate of first control point
\n', + type: 'Number' + }, + { + name: 'c', + description: 'coordinate of second control point
\n', + type: 'Number' + }, + { + name: 'd', + description: 'coordinate of second point on the curve
\n', + type: 'Number' + }, + { + name: 't', + description: 'value between 0 and 1
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + curve: { + name: 'curve', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x1', + description: + 'x-coordinate for the beginning control point
\n', + type: 'Number' + }, + { + name: 'y1', + description: + 'y-coordinate for the beginning control point
\n', + type: 'Number' + }, + { + name: 'x2', + description: 'x-coordinate for the first point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'y-coordinate for the first point
\n', + type: 'Number' + }, + { + name: 'x3', + description: 'x-coordinate for the second point
\n', + type: 'Number' + }, + { + name: 'y3', + description: 'y-coordinate for the second point
\n', + type: 'Number' + }, + { + name: 'x4', + description: 'x-coordinate for the ending control point
\n', + type: 'Number' + }, + { + name: 'y4', + description: 'y-coordinate for the ending control point
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: + 'z-coordinate for the beginning control point
\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: 'z-coordinate for the first point
\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: 'z-coordinate for the second point
\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: 'z-coordinate for the ending control point
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + curveDetail: { + name: 'curveDetail', + params: [ + { + name: 'resolution', + description: 'resolution of the curves
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + curveTightness: { + name: 'curveTightness', + params: [ + { + name: 'amount', + description: + 'amount of deformation from the original vertices
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + curvePoint: { + name: 'curvePoint', + params: [ + { + name: 'a', + description: 'coordinate of first control point of the curve
\n', + type: 'Number' + }, + { + name: 'b', + description: 'coordinate of first point
\n', + type: 'Number' + }, + { + name: 'c', + description: 'coordinate of second point
\n', + type: 'Number' + }, + { + name: 'd', + description: 'coordinate of second control point
\n', + type: 'Number' + }, + { + name: 't', + description: 'value between 0 and 1
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + curveTangent: { + name: 'curveTangent', + params: [ + { + name: 'a', + description: 'coordinate of first control point
\n', + type: 'Number' + }, + { + name: 'b', + description: 'coordinate of first point on the curve
\n', + type: 'Number' + }, + { + name: 'c', + description: 'coordinate of second point on the curve
\n', + type: 'Number' + }, + { + name: 'd', + description: 'coordinate of second conrol point
\n', + type: 'Number' + }, + { + name: 't', + description: 'value between 0 and 1
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Shape' + }, + beginContour: { + name: 'beginContour', + class: 'p5', + module: 'Shape' + }, + beginShape: { + name: 'beginShape', + params: [ + { + name: 'kind', + description: + 'either POINTS, LINES, TRIANGLES, TRIANGLE_FAN\n TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + bezierVertex: { + name: 'bezierVertex', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x2', + description: 'x-coordinate for the first control point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'y-coordinate for the first control point
\n', + type: 'Number' + }, + { + name: 'x3', + description: 'x-coordinate for the second control point
\n', + type: 'Number' + }, + { + name: 'y3', + description: 'y-coordinate for the second control point
\n', + type: 'Number' + }, + { + name: 'x4', + description: 'x-coordinate for the anchor point
\n', + type: 'Number' + }, + { + name: 'y4', + description: 'y-coordinate for the anchor point
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: + 'z-coordinate for the first control point (for WebGL mode)
\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: + 'z-coordinate for the second control point (for WebGL mode)
\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: + 'z-coordinate for the anchor point (for WebGL mode)
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + curveVertex: { + name: 'curveVertex', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x-coordinate of the vertex
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the vertex
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: 'z-coordinate of the vertex (for WebGL mode)
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + endContour: { + name: 'endContour', + class: 'p5', + module: 'Shape' + }, + endShape: { + name: 'endShape', + params: [ + { + name: 'mode', + description: 'use CLOSE to close the shape
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + quadraticVertex: { + name: 'quadraticVertex', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'cx', + description: 'x-coordinate for the control point
\n', + type: 'Number' + }, + { + name: 'cy', + description: 'y-coordinate for the control point
\n', + type: 'Number' + }, + { + name: 'x3', + description: 'x-coordinate for the anchor point
\n', + type: 'Number' + }, + { + name: 'y3', + description: 'y-coordinate for the anchor point
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'cx', + description: '', + type: 'Number' + }, + { + name: 'cy', + description: '', + type: 'Number' + }, + { + name: 'cz', + description: + 'z-coordinate for the control point (for WebGL mode)
\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: + 'z-coordinate for the anchor point (for WebGL mode)
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + vertex: { + name: 'vertex', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x-coordinate of the vertex
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the vertex
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: 'z-coordinate of the vertex
\n', + type: 'Number' + }, + { + name: 'u', + description: "the vertex's texture u-coordinate
\n", + type: 'Number', + optional: true + }, + { + name: 'v', + description: "the vertex's texture v-coordinate
\n", + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + VERSION: { + name: 'VERSION', + class: 'p5', + module: 'Constants' + }, + P2D: { + name: 'P2D', + class: 'p5', + module: 'Constants' + }, + WEBGL: { + name: 'WEBGL', + class: 'p5', + module: 'Constants' + }, + ARROW: { + name: 'ARROW', + class: 'p5', + module: 'Constants' + }, + CROSS: { + name: 'CROSS', + class: 'p5', + module: 'Constants' + }, + HAND: { + name: 'HAND', + class: 'p5', + module: 'Constants' + }, + MOVE: { + name: 'MOVE', + class: 'p5', + module: 'Constants' + }, + TEXT: { + name: 'TEXT', + class: 'p5', + module: 'Constants' + }, + WAIT: { + name: 'WAIT', + class: 'p5', + module: 'Constants' + }, + HALF_PI: { + name: 'HALF_PI', + class: 'p5', + module: 'Constants' + }, + PI: { + name: 'PI', + class: 'p5', + module: 'Constants' + }, + QUARTER_PI: { + name: 'QUARTER_PI', + class: 'p5', + module: 'Constants' + }, + TAU: { + name: 'TAU', + class: 'p5', + module: 'Constants' + }, + TWO_PI: { + name: 'TWO_PI', + class: 'p5', + module: 'Constants' + }, + DEGREES: { + name: 'DEGREES', + class: 'p5', + module: 'Constants' + }, + RADIANS: { + name: 'RADIANS', + class: 'p5', + module: 'Constants' + }, + CORNER: { + name: 'CORNER', + class: 'p5', + module: 'Constants' + }, + CORNERS: { + name: 'CORNERS', + class: 'p5', + module: 'Constants' + }, + RADIUS: { + name: 'RADIUS', + class: 'p5', + module: 'Constants' + }, + RIGHT: { + name: 'RIGHT', + class: 'p5', + module: 'Constants' + }, + LEFT: { + name: 'LEFT', + class: 'p5', + module: 'Constants' + }, + CENTER: { + name: 'CENTER', + class: 'p5', + module: 'Constants' + }, + TOP: { + name: 'TOP', + class: 'p5', + module: 'Constants' + }, + BOTTOM: { + name: 'BOTTOM', + class: 'p5', + module: 'Constants' + }, + BASELINE: { + name: 'BASELINE', + class: 'p5', + module: 'Constants' + }, + POINTS: { + name: 'POINTS', + class: 'p5', + module: 'Constants' + }, + LINES: { + name: 'LINES', + class: 'p5', + module: 'Constants' + }, + LINE_STRIP: { + name: 'LINE_STRIP', + class: 'p5', + module: 'Constants' + }, + LINE_LOOP: { + name: 'LINE_LOOP', + class: 'p5', + module: 'Constants' + }, + TRIANGLES: { + name: 'TRIANGLES', + class: 'p5', + module: 'Constants' + }, + TRIANGLE_FAN: { + name: 'TRIANGLE_FAN', + class: 'p5', + module: 'Constants' + }, + TRIANGLE_STRIP: { + name: 'TRIANGLE_STRIP', + class: 'p5', + module: 'Constants' + }, + QUADS: { + name: 'QUADS', + class: 'p5', + module: 'Constants' + }, + QUAD_STRIP: { + name: 'QUAD_STRIP', + class: 'p5', + module: 'Constants' + }, + TESS: { + name: 'TESS', + class: 'p5', + module: 'Constants' + }, + CLOSE: { + name: 'CLOSE', + class: 'p5', + module: 'Constants' + }, + OPEN: { + name: 'OPEN', + class: 'p5', + module: 'Constants' + }, + CHORD: { + name: 'CHORD', + class: 'p5', + module: 'Constants' + }, + PIE: { + name: 'PIE', + class: 'p5', + module: 'Constants' + }, + PROJECT: { + name: 'PROJECT', + class: 'p5', + module: 'Constants' + }, + SQUARE: { + name: 'SQUARE', + class: 'p5', + module: 'Constants' + }, + ROUND: { + name: 'ROUND', + class: 'p5', + module: 'Constants' + }, + BEVEL: { + name: 'BEVEL', + class: 'p5', + module: 'Constants' + }, + MITER: { + name: 'MITER', + class: 'p5', + module: 'Constants' + }, + RGB: { + name: 'RGB', + class: 'p5', + module: 'Constants' + }, + HSB: { + name: 'HSB', + class: 'p5', + module: 'Constants' + }, + HSL: { + name: 'HSL', + class: 'p5', + module: 'Constants' + }, + AUTO: { + name: 'AUTO', + class: 'p5', + module: 'Constants' + }, + ALT: { + name: 'ALT', + class: 'p5', + module: 'Constants' + }, + BACKSPACE: { + name: 'BACKSPACE', + class: 'p5', + module: 'Constants' + }, + CONTROL: { + name: 'CONTROL', + class: 'p5', + module: 'Constants' + }, + DELETE: { + name: 'DELETE', + class: 'p5', + module: 'Constants' + }, + DOWN_ARROW: { + name: 'DOWN_ARROW', + class: 'p5', + module: 'Constants' + }, + ENTER: { + name: 'ENTER', + class: 'p5', + module: 'Constants' + }, + ESCAPE: { + name: 'ESCAPE', + class: 'p5', + module: 'Constants' + }, + LEFT_ARROW: { + name: 'LEFT_ARROW', + class: 'p5', + module: 'Constants' + }, + OPTION: { + name: 'OPTION', + class: 'p5', + module: 'Constants' + }, + RETURN: { + name: 'RETURN', + class: 'p5', + module: 'Constants' + }, + RIGHT_ARROW: { + name: 'RIGHT_ARROW', + class: 'p5', + module: 'Constants' + }, + SHIFT: { + name: 'SHIFT', + class: 'p5', + module: 'Constants' + }, + TAB: { + name: 'TAB', + class: 'p5', + module: 'Constants' + }, + UP_ARROW: { + name: 'UP_ARROW', + class: 'p5', + module: 'Constants' + }, + BLEND: { + name: 'BLEND', + class: 'p5', + module: 'Constants' + }, + REMOVE: { + name: 'REMOVE', + class: 'p5', + module: 'Constants' + }, + ADD: { + name: 'ADD', + class: 'p5', + module: 'Constants' + }, + DARKEST: { + name: 'DARKEST', + class: 'p5', + module: 'Constants' + }, + LIGHTEST: { + name: 'LIGHTEST', + class: 'p5', + module: 'Constants' + }, + DIFFERENCE: { + name: 'DIFFERENCE', + class: 'p5', + module: 'Constants' + }, + SUBTRACT: { + name: 'SUBTRACT', + class: 'p5', + module: 'Constants' + }, + EXCLUSION: { + name: 'EXCLUSION', + class: 'p5', + module: 'Constants' + }, + MULTIPLY: { + name: 'MULTIPLY', + class: 'p5', + module: 'Constants' + }, + SCREEN: { + name: 'SCREEN', + class: 'p5', + module: 'Constants' + }, + REPLACE: { + name: 'REPLACE', + class: 'p5', + module: 'Constants' + }, + OVERLAY: { + name: 'OVERLAY', + class: 'p5', + module: 'Constants' + }, + HARD_LIGHT: { + name: 'HARD_LIGHT', + class: 'p5', + module: 'Constants' + }, + SOFT_LIGHT: { + name: 'SOFT_LIGHT', + class: 'p5', + module: 'Constants' + }, + DODGE: { + name: 'DODGE', + class: 'p5', + module: 'Constants' + }, + BURN: { + name: 'BURN', + class: 'p5', + module: 'Constants' + }, + THRESHOLD: { + name: 'THRESHOLD', + class: 'p5', + module: 'Constants' + }, + GRAY: { + name: 'GRAY', + class: 'p5', + module: 'Constants' + }, + OPAQUE: { + name: 'OPAQUE', + class: 'p5', + module: 'Constants' + }, + INVERT: { + name: 'INVERT', + class: 'p5', + module: 'Constants' + }, + POSTERIZE: { + name: 'POSTERIZE', + class: 'p5', + module: 'Constants' + }, + DILATE: { + name: 'DILATE', + class: 'p5', + module: 'Constants' + }, + ERODE: { + name: 'ERODE', + class: 'p5', + module: 'Constants' + }, + BLUR: { + name: 'BLUR', + class: 'p5', + module: 'Constants' + }, + NORMAL: { + name: 'NORMAL', + class: 'p5', + module: 'Constants' + }, + ITALIC: { + name: 'ITALIC', + class: 'p5', + module: 'Constants' + }, + BOLD: { + name: 'BOLD', + class: 'p5', + module: 'Constants' + }, + BOLDITALIC: { + name: 'BOLDITALIC', + class: 'p5', + module: 'Constants' + }, + LINEAR: { + name: 'LINEAR', + class: 'p5', + module: 'Constants' + }, + QUADRATIC: { + name: 'QUADRATIC', + class: 'p5', + module: 'Constants' + }, + BEZIER: { + name: 'BEZIER', + class: 'p5', + module: 'Constants' + }, + CURVE: { + name: 'CURVE', + class: 'p5', + module: 'Constants' + }, + STROKE: { + name: 'STROKE', + class: 'p5', + module: 'Constants' + }, + FILL: { + name: 'FILL', + class: 'p5', + module: 'Constants' + }, + TEXTURE: { + name: 'TEXTURE', + class: 'p5', + module: 'Constants' + }, + IMMEDIATE: { + name: 'IMMEDIATE', + class: 'p5', + module: 'Constants' + }, + IMAGE: { + name: 'IMAGE', + class: 'p5', + module: 'Constants' + }, + NEAREST: { + name: 'NEAREST', + class: 'p5', + module: 'Constants' + }, + REPEAT: { + name: 'REPEAT', + class: 'p5', + module: 'Constants' + }, + CLAMP: { + name: 'CLAMP', + class: 'p5', + module: 'Constants' + }, + MIRROR: { + name: 'MIRROR', + class: 'p5', + module: 'Constants' + }, + LANDSCAPE: { + name: 'LANDSCAPE', + class: 'p5', + module: 'Constants' + }, + PORTRAIT: { + name: 'PORTRAIT', + class: 'p5', + module: 'Constants' + }, + GRID: { + name: 'GRID', + class: 'p5', + module: 'Constants' + }, + AXES: { + name: 'AXES', + class: 'p5', + module: 'Constants' + }, + LABEL: { + name: 'LABEL', + class: 'p5', + module: 'Constants' + }, + FALLBACK: { + name: 'FALLBACK', + class: 'p5', + module: 'Constants' + }, + print: { + name: 'print', + params: [ + { + name: 'contents', + description: + 'any combination of Number, String, Object, Boolean,\n Array to print
\n', + type: 'Any' + } + ], + class: 'p5', + module: 'Environment' + }, + frameCount: { + name: 'frameCount', + class: 'p5', + module: 'Environment' + }, + deltaTime: { + name: 'deltaTime', + class: 'p5', + module: 'Environment' + }, + focused: { + name: 'focused', + class: 'p5', + module: 'Environment' + }, + cursor: { + name: 'cursor', + params: [ + { + name: 'type', + description: + "Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT\n Native CSS properties: 'grab', 'progress', 'cell' etc.\n External: path for cursor's images\n (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png)\n For more information on Native CSS cursors and url visit:\n https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
\n", + type: 'String|Constant' + }, + { + name: 'x', + description: + 'the horizontal active spot of the cursor (must be less than 32)
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: + 'the vertical active spot of the cursor (must be less than 32)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + frameRate: { + name: 'frameRate', + class: 'p5', + module: 'Environment', + overloads: [ + { + params: [ + { + name: 'fps', + description: + 'number of frames to be displayed every second
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + noCursor: { + name: 'noCursor', + class: 'p5', + module: 'Environment' + }, + displayWidth: { + name: 'displayWidth', + class: 'p5', + module: 'Environment' + }, + displayHeight: { + name: 'displayHeight', + class: 'p5', + module: 'Environment' + }, + windowWidth: { + name: 'windowWidth', + class: 'p5', + module: 'Environment' + }, + windowHeight: { + name: 'windowHeight', + class: 'p5', + module: 'Environment' + }, + windowResized: { + name: 'windowResized', + params: [ + { + name: 'event', + description: 'optional Event callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + width: { + name: 'width', + class: 'p5', + module: 'Environment' + }, + height: { + name: 'height', + class: 'p5', + module: 'Environment' + }, + fullscreen: { + name: 'fullscreen', + params: [ + { + name: 'val', + description: + 'whether the sketch should be in fullscreen mode\nor not
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'Environment' + }, + pixelDensity: { + name: 'pixelDensity', + class: 'p5', + module: 'Environment', + overloads: [ + { + params: [ + { + name: 'val', + description: 'whether or how much the sketch should scale
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + displayDensity: { + name: 'displayDensity', + class: 'p5', + module: 'Environment' + }, + getURL: { + name: 'getURL', + class: 'p5', + module: 'Environment' + }, + getURLPath: { + name: 'getURLPath', + class: 'p5', + module: 'Environment' + }, + getURLParams: { + name: 'getURLParams', + class: 'p5', + module: 'Environment' + }, + preload: { + name: 'preload', + class: 'p5', + module: 'Structure' + }, + setup: { + name: 'setup', + class: 'p5', + module: 'Structure' + }, + draw: { + name: 'draw', + class: 'p5', + module: 'Structure' + }, + remove: { + name: 'remove', + class: 'p5', + module: 'Structure' + }, + disableFriendlyErrors: { + name: 'disableFriendlyErrors', + class: 'p5', + module: 'Structure' + }, + let: { + name: 'let', + class: 'p5', + module: 'Foundation' + }, + const: { + name: 'const', + class: 'p5', + module: 'Foundation' + }, + '===': { + name: '===', + class: 'p5', + module: 'Foundation' + }, + '>': { + name: '>', + class: 'p5', + module: 'Foundation' + }, + '>=': { + name: '>=', + class: 'p5', + module: 'Foundation' + }, + '<': { + name: '<', + class: 'p5', + module: 'Foundation' + }, + '<=': { + name: '<=', + class: 'p5', + module: 'Foundation' + }, + 'if-else': { + name: 'if-else', + class: 'p5', + module: 'Foundation' + }, + function: { + name: 'function', + class: 'p5', + module: 'Foundation' + }, + return: { + name: 'return', + class: 'p5', + module: 'Foundation' + }, + boolean: { + name: 'boolean', + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String|Boolean|Number|Array' + } + ], + class: 'p5', + module: 'Data' + }, + string: { + name: 'string', + class: 'p5', + module: 'Foundation' + }, + number: { + name: 'number', + class: 'p5', + module: 'Foundation' + }, + object: { + name: 'object', + class: 'p5', + module: 'Foundation' + }, + class: { + name: 'class', + class: 'p5', + module: 'Foundation' + }, + for: { + name: 'for', + class: 'p5', + module: 'Foundation' + }, + while: { + name: 'while', + class: 'p5', + module: 'Foundation' + }, + createCanvas: { + name: 'createCanvas', + params: [ + { + name: 'w', + description: 'width of the canvas
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height of the canvas
\n', + type: 'Number' + }, + { + name: 'renderer', + description: 'either P2D or WEBGL
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Rendering' + }, + resizeCanvas: { + name: 'resizeCanvas', + params: [ + { + name: 'w', + description: 'width of the canvas
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height of the canvas
\n', + type: 'Number' + }, + { + name: 'noRedraw', + description: "don't redraw the canvas immediately
\n", + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'Rendering' + }, + noCanvas: { + name: 'noCanvas', + class: 'p5', + module: 'Rendering' + }, + createGraphics: { + name: 'createGraphics', + params: [ + { + name: 'w', + description: 'width of the offscreen graphics buffer
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height of the offscreen graphics buffer
\n', + type: 'Number' + }, + { + name: 'renderer', + description: + 'either P2D or WEBGL\n undefined defaults to p2d
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Rendering' + }, + blendMode: { + name: 'blendMode', + params: [ + { + name: 'mode', + description: + 'blend mode to set for canvas.\n either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY,\n EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Rendering' + }, + drawingContext: { + name: 'drawingContext', + class: 'p5', + module: 'Rendering' + }, + noLoop: { + name: 'noLoop', + class: 'p5', + module: 'Structure' + }, + loop: { + name: 'loop', + class: 'p5', + module: 'Structure' + }, + isLooping: { + name: 'isLooping', + class: 'p5', + module: 'Structure' + }, + push: { + name: 'push', + class: 'p5', + module: 'Structure' + }, + pop: { + name: 'pop', + class: 'p5', + module: 'Structure' + }, + redraw: { + name: 'redraw', + params: [ + { + name: 'n', + description: 'Redraw for n-times. The default value is 1.
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Structure' + }, + p5: { + name: 'p5', + params: [ + { + name: 'sketch', + description: 'a function containing a p5.js sketch
\n', + type: 'Object' + }, + { + name: 'node', + description: + 'ID or pointer to HTML DOM node to contain sketch in
\n', + type: 'String|Object' + } + ], + class: 'p5', + module: 'Structure' + }, + applyMatrix: { + name: 'applyMatrix', + params: [ + { + name: 'a', + description: + 'numbers which define the 2x3 matrix to be multiplied, or an array of numbers
\n', + type: 'Number|Array' + }, + { + name: 'b', + description: + 'numbers which define the 2x3 matrix to be multiplied
\n', + type: 'Number' + }, + { + name: 'c', + description: + 'numbers which define the 2x3 matrix to be multiplied
\n', + type: 'Number' + }, + { + name: 'd', + description: + 'numbers which define the 2x3 matrix to be multiplied
\n', + type: 'Number' + }, + { + name: 'e', + description: + 'numbers which define the 2x3 matrix to be multiplied
\n', + type: 'Number' + }, + { + name: 'f', + description: + 'numbers which define the 2x3 matrix to be multiplied
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Transform' + }, + resetMatrix: { + name: 'resetMatrix', + class: 'p5', + module: 'Transform' + }, + rotate: { + name: 'rotate', + params: [ + { + name: 'angle', + description: + 'the angle of rotation, specified in radians\n or degrees, depending on current angleMode
\n', + type: 'Number' + }, + { + name: 'axis', + description: '(in 3d) the axis to rotate around
\n', + type: 'p5.Vector|Number[]', + optional: true + } + ], + class: 'p5', + module: 'Transform' + }, + rotateX: { + name: 'rotateX', + params: [ + { + name: 'angle', + description: + 'the angle of rotation, specified in radians\n or degrees, depending on current angleMode
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Transform' + }, + rotateY: { + name: 'rotateY', + params: [ + { + name: 'angle', + description: + 'the angle of rotation, specified in radians\n or degrees, depending on current angleMode
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Transform' + }, + rotateZ: { + name: 'rotateZ', + params: [ + { + name: 'angle', + description: + 'the angle of rotation, specified in radians\n or degrees, depending on current angleMode
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Transform' + }, + scale: { + name: 'scale', + class: 'p5', + module: 'Transform', + overloads: [ + { + params: [ + { + name: 's', + description: + 'percent to scale the object, or percentage to\n scale the object in the x-axis if multiple arguments\n are given
\n', + type: 'Number|p5.Vector|Number[]' + }, + { + name: 'y', + description: 'percent to scale the object in the y-axis
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: + 'percent to scale the object in the z-axis (webgl only)
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'scales', + description: 'per-axis percents to scale the object
\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + } + ] + }, + shearX: { + name: 'shearX', + params: [ + { + name: 'angle', + description: + 'angle of shear specified in radians or degrees,\n depending on current angleMode
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Transform' + }, + shearY: { + name: 'shearY', + params: [ + { + name: 'angle', + description: + 'angle of shear specified in radians or degrees,\n depending on current angleMode
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Transform' + }, + translate: { + name: 'translate', + class: 'p5', + module: 'Transform', + overloads: [ + { + params: [ + { + name: 'x', + description: 'left/right translation
\n', + type: 'Number' + }, + { + name: 'y', + description: 'up/down translation
\n', + type: 'Number' + }, + { + name: 'z', + description: 'forward/backward translation (webgl only)
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'vector', + description: 'the vector to translate by
\n', + type: 'p5.Vector' + } + ], + chainable: 1 + } + ] + }, + storeItem: { + name: 'storeItem', + params: [ + { + name: 'key', + description: '', + type: 'String' + }, + { + name: 'value', + description: '', + type: 'String|Number|Object|Boolean|p5.Color|p5.Vector' + } + ], + class: 'p5', + module: 'Data' + }, + getItem: { + name: 'getItem', + params: [ + { + name: 'key', + description: + 'name that you wish to use to store in local storage
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + clearStorage: { + name: 'clearStorage', + class: 'p5', + module: 'Data' + }, + removeItem: { + name: 'removeItem', + params: [ + { + name: 'key', + description: '', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + createStringDict: { + name: 'createStringDict', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'key', + description: '', + type: 'String' + }, + { + name: 'value', + description: '', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'object', + description: 'object
\n', + type: 'Object' + } + ] + } + ] + }, + createNumberDict: { + name: 'createNumberDict', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'key', + description: '', + type: 'Number' + }, + { + name: 'value', + description: '', + type: 'Number' + } + ] + }, + { + params: [ + { + name: 'object', + description: 'object
\n', + type: 'Object' + } + ] + } + ] + }, + select: { + name: 'select', + params: [ + { + name: 'selectors', + description: 'CSS selector string of element to search for
\n', + type: 'String' + }, + { + name: 'container', + description: + 'CSS selector string, p5.Element, or\n HTML element to search within
\n', + type: 'String|p5.Element|HTMLElement', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + selectAll: { + name: 'selectAll', + params: [ + { + name: 'selectors', + description: 'CSS selector string of elements to search for
\n', + type: 'String' + }, + { + name: 'container', + description: + 'CSS selector string, p5.Element\n , or HTML element to search within
\n', + type: 'String|p5.Element|HTMLElement', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + removeElements: { + name: 'removeElements', + class: 'p5', + module: 'DOM' + }, + changed: { + name: 'changed', + params: [ + { + name: 'fxn', + description: + 'function to be fired when the value of\n an element changes.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when any user input is\n detected within the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
inner HTML for element created
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createP: { + name: 'createP', + params: [ + { + name: 'html', + description: 'inner HTML for element created
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createSpan: { + name: 'createSpan', + params: [ + { + name: 'html', + description: 'inner HTML for element created
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createImg: { + name: 'createImg', + class: 'p5', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'src', + description: 'src path or url for image
\n', + type: 'String' + }, + { + name: 'alt', + description: + 'alternate text to be used if image does not load. You can use also an empty string (""
) if that an image is not intended to be viewed.
crossOrigin property of the img
element; use either \'anonymous\' or \'use-credentials\' to retrieve the image with cross-origin access (for later use with canvas
. if an empty string(""
) is passed, CORS is not used
callback to be called once image data is loaded with the p5.Element as argument
\n', + type: 'Function', + optional: true + } + ] + } + ] + }, + createA: { + name: 'createA', + params: [ + { + name: 'href', + description: 'url of page to link to
\n', + type: 'String' + }, + { + name: 'html', + description: 'inner html of link element to display
\n', + type: 'String' + }, + { + name: 'target', + description: + 'target where new link should open,\n could be _blank, _self, _parent, _top.
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createSlider: { + name: 'createSlider', + params: [ + { + name: 'min', + description: 'minimum value of the slider
\n', + type: 'Number' + }, + { + name: 'max', + description: 'maximum value of the slider
\n', + type: 'Number' + }, + { + name: 'value', + description: 'default value of the slider
\n', + type: 'Number', + optional: true + }, + { + name: 'step', + description: + 'step size for each tick of the slider (if step is set to 0, the slider will move continuously from the minimum to the maximum value)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createButton: { + name: 'createButton', + params: [ + { + name: 'label', + description: 'label displayed on the button
\n', + type: 'String' + }, + { + name: 'value', + description: 'value of the button
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createCheckbox: { + name: 'createCheckbox', + params: [ + { + name: 'label', + description: 'label displayed after checkbox
\n', + type: 'String', + optional: true + }, + { + name: 'value', + description: + 'value of the checkbox; checked is true, unchecked is false
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createSelect: { + name: 'createSelect', + class: 'p5', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'multiple', + description: + 'true if dropdown should support multiple selections
\n', + type: 'Boolean', + optional: true + } + ] + }, + { + params: [ + { + name: 'existing', + description: 'DOM select element
\n', + type: 'Object' + } + ] + } + ] + }, + createRadio: { + name: 'createRadio', + class: 'p5', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'containerElement', + description: + 'An container HTML Element either a div\nor span inside which all existing radio inputs will be considered as options.
\n', + type: 'Object' + }, + { + name: 'name', + description: 'A name parameter for each Input Element.
\n', + type: 'String', + optional: true + } + ] + }, + { + params: [ + { + name: 'name', + description: '', + type: 'String' + } + ] + }, + { + params: [] + } + ] + }, + createColorPicker: { + name: 'createColorPicker', + params: [ + { + name: 'value', + description: 'default color of element
\n', + type: 'String|p5.Color', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createInput: { + name: 'createInput', + class: 'p5', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'value', + description: 'default value of the input box
\n', + type: 'String' + }, + { + name: 'type', + description: + 'type of text, ie text, password etc. Defaults to text.\n Needs a value to be specified first.
\n', + type: 'String', + optional: true + } + ] + }, + { + params: [ + { + name: 'value', + description: '', + type: 'String', + optional: true + } + ] + } + ] + }, + createFileInput: { + name: 'createFileInput', + params: [ + { + name: 'callback', + description: 'callback function for when a file is loaded
\n', + type: 'Function' + }, + { + name: 'multiple', + description: + 'optional, to allow multiple files to be selected
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createVideo: { + name: 'createVideo', + params: [ + { + name: 'src', + description: + 'path to a video file, or array of paths for\n supporting different browsers
\n', + type: 'String|String[]' + }, + { + name: 'callback', + description: + "callback function to be called upon\n 'canplaythrough' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content
\n", + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createAudio: { + name: 'createAudio', + params: [ + { + name: 'src', + description: + 'path to an audio file, or array of paths\n for supporting different browsers
\n', + type: 'String|String[]', + optional: true + }, + { + name: 'callback', + description: + "callback function to be called upon\n 'canplaythrough' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content
\n", + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + VIDEO: { + name: 'VIDEO', + class: 'p5', + module: 'DOM' + }, + AUDIO: { + name: 'AUDIO', + class: 'p5', + module: 'DOM' + }, + createCapture: { + name: 'createCapture', + params: [ + { + name: 'type', + description: + 'type of capture, either VIDEO or\n AUDIO if none specified, default both,\n or a Constraints object
\n', + type: 'String|Constant|Object' + }, + { + name: 'callback', + description: + 'function to be called once\n stream has loaded
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + createElement: { + name: 'createElement', + params: [ + { + name: 'tag', + description: 'tag for the new element
\n', + type: 'String' + }, + { + name: 'content', + description: 'html content to be inserted into the element
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'DOM' + }, + deviceOrientation: { + name: 'deviceOrientation', + class: 'p5', + module: 'Events' + }, + accelerationX: { + name: 'accelerationX', + class: 'p5', + module: 'Events' + }, + accelerationY: { + name: 'accelerationY', + class: 'p5', + module: 'Events' + }, + accelerationZ: { + name: 'accelerationZ', + class: 'p5', + module: 'Events' + }, + pAccelerationX: { + name: 'pAccelerationX', + class: 'p5', + module: 'Events' + }, + pAccelerationY: { + name: 'pAccelerationY', + class: 'p5', + module: 'Events' + }, + pAccelerationZ: { + name: 'pAccelerationZ', + class: 'p5', + module: 'Events' + }, + rotationX: { + name: 'rotationX', + class: 'p5', + module: 'Events' + }, + rotationY: { + name: 'rotationY', + class: 'p5', + module: 'Events' + }, + rotationZ: { + name: 'rotationZ', + class: 'p5', + module: 'Events' + }, + pRotationX: { + name: 'pRotationX', + class: 'p5', + module: 'Events' + }, + pRotationY: { + name: 'pRotationY', + class: 'p5', + module: 'Events' + }, + pRotationZ: { + name: 'pRotationZ', + class: 'p5', + module: 'Events' + }, + turnAxis: { + name: 'turnAxis', + class: 'p5', + module: 'Events' + }, + setMoveThreshold: { + name: 'setMoveThreshold', + params: [ + { + name: 'value', + description: 'The threshold value
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Events' + }, + setShakeThreshold: { + name: 'setShakeThreshold', + params: [ + { + name: 'value', + description: 'The threshold value
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Events' + }, + deviceMoved: { + name: 'deviceMoved', + class: 'p5', + module: 'Events' + }, + deviceTurned: { + name: 'deviceTurned', + class: 'p5', + module: 'Events' + }, + deviceShaken: { + name: 'deviceShaken', + class: 'p5', + module: 'Events' + }, + keyIsPressed: { + name: 'keyIsPressed', + class: 'p5', + module: 'Events' + }, + key: { + name: 'key', + class: 'p5', + module: 'Events' + }, + keyCode: { + name: 'keyCode', + class: 'p5', + module: 'Events' + }, + keyPressed: { + name: 'keyPressed', + params: [ + { + name: 'event', + description: 'optional KeyboardEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + keyReleased: { + name: 'keyReleased', + params: [ + { + name: 'event', + description: 'optional KeyboardEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + keyTyped: { + name: 'keyTyped', + params: [ + { + name: 'event', + description: 'optional KeyboardEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + keyIsDown: { + name: 'keyIsDown', + params: [ + { + name: 'code', + description: 'The key to check for.
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Events' + }, + movedX: { + name: 'movedX', + class: 'p5', + module: 'Events' + }, + movedY: { + name: 'movedY', + class: 'p5', + module: 'Events' + }, + mouseX: { + name: 'mouseX', + class: 'p5', + module: 'Events' + }, + mouseY: { + name: 'mouseY', + class: 'p5', + module: 'Events' + }, + pmouseX: { + name: 'pmouseX', + class: 'p5', + module: 'Events' + }, + pmouseY: { + name: 'pmouseY', + class: 'p5', + module: 'Events' + }, + winMouseX: { + name: 'winMouseX', + class: 'p5', + module: 'Events' + }, + winMouseY: { + name: 'winMouseY', + class: 'p5', + module: 'Events' + }, + pwinMouseX: { + name: 'pwinMouseX', + class: 'p5', + module: 'Events' + }, + pwinMouseY: { + name: 'pwinMouseY', + class: 'p5', + module: 'Events' + }, + mouseButton: { + name: 'mouseButton', + class: 'p5', + module: 'Events' + }, + mouseIsPressed: { + name: 'mouseIsPressed', + class: 'p5', + module: 'Events' + }, + mouseMoved: { + name: 'mouseMoved', + params: [ + { + name: 'event', + description: 'optional MouseEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + mouseDragged: { + name: 'mouseDragged', + params: [ + { + name: 'event', + description: 'optional MouseEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + mousePressed: { + name: 'mousePressed', + params: [ + { + name: 'event', + description: 'optional MouseEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + mouseReleased: { + name: 'mouseReleased', + params: [ + { + name: 'event', + description: 'optional MouseEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + mouseClicked: { + name: 'mouseClicked', + params: [ + { + name: 'event', + description: 'optional MouseEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + doubleClicked: { + name: 'doubleClicked', + params: [ + { + name: 'event', + description: 'optional MouseEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + mouseWheel: { + name: 'mouseWheel', + params: [ + { + name: 'event', + description: 'optional WheelEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + requestPointerLock: { + name: 'requestPointerLock', + class: 'p5', + module: 'Events' + }, + exitPointerLock: { + name: 'exitPointerLock', + class: 'p5', + module: 'Events' + }, + touches: { + name: 'touches', + class: 'p5', + module: 'Events' + }, + touchStarted: { + name: 'touchStarted', + params: [ + { + name: 'event', + description: 'optional TouchEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + touchMoved: { + name: 'touchMoved', + params: [ + { + name: 'event', + description: 'optional TouchEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + touchEnded: { + name: 'touchEnded', + params: [ + { + name: 'event', + description: 'optional TouchEvent callback argument.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5', + module: 'Events' + }, + createImage: { + name: 'createImage', + params: [ + { + name: 'width', + description: 'width in pixels
\n', + type: 'Integer' + }, + { + name: 'height', + description: 'height in pixels
\n', + type: 'Integer' + } + ], + class: 'p5', + module: 'Image' + }, + saveCanvas: { + name: 'saveCanvas', + class: 'p5', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'selectedCanvas', + description: + 'a variable\n representing a specific html5 canvas (optional)
\n', + type: 'p5.Element|HTMLCanvasElement' + }, + { + name: 'filename', + description: '', + type: 'String', + optional: true + }, + { + name: 'extension', + description: "'jpg' or 'png'
\n", + type: 'String', + optional: true + } + ] + }, + { + params: [ + { + name: 'filename', + description: '', + type: 'String', + optional: true + }, + { + name: 'extension', + description: '', + type: 'String', + optional: true + } + ] + } + ] + }, + saveFrames: { + name: 'saveFrames', + params: [ + { + name: 'filename', + description: '', + type: 'String' + }, + { + name: 'extension', + description: "'jpg' or 'png'
\n", + type: 'String' + }, + { + name: 'duration', + description: 'Duration in seconds to save the frames for.
\n', + type: 'Number' + }, + { + name: 'framerate', + description: 'Framerate to save the frames in.
\n', + type: 'Number' + }, + { + name: 'callback', + description: + 'A callback function that will be executed\n to handle the image data. This function\n should accept an array as argument. The\n array will contain the specified number of\n frames of objects. Each object has three\n properties: imageData - an\n image/octet-stream, filename and extension.
\n', + type: 'Function(Array)', + optional: true + } + ], + class: 'p5', + module: 'Image' + }, + loadImage: { + name: 'loadImage', + params: [ + { + name: 'path', + description: 'Path of the image to be loaded
\n', + type: 'String' + }, + { + name: 'successCallback', + description: + 'Function to be called once\n the image is loaded. Will be passed the\n p5.Image.
\n', + type: 'function(p5.Image)', + optional: true + }, + { + name: 'failureCallback', + description: + 'called with event error if\n the image fails to load.
\n', + type: 'Function(Event)', + optional: true + } + ], + class: 'p5', + module: 'Image' + }, + image: { + name: 'image', + class: 'p5', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'img', + description: 'the image to display
\n', + type: 'p5.Image|p5.Element' + }, + { + name: 'x', + description: + 'the x-coordinate of the top-left corner of the image
\n', + type: 'Number' + }, + { + name: 'y', + description: + 'the y-coordinate of the top-left corner of the image
\n', + type: 'Number' + }, + { + name: 'width', + description: 'the width to draw the image
\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: 'the height to draw the image
\n', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'img', + description: '', + type: 'p5.Image|p5.Element' + }, + { + name: 'dx', + description: + 'the x-coordinate of the destination\n rectangle in which to draw the source image
\n', + type: 'Number' + }, + { + name: 'dy', + description: + 'the y-coordinate of the destination\n rectangle in which to draw the source image
\n', + type: 'Number' + }, + { + name: 'dWidth', + description: 'the width of the destination rectangle
\n', + type: 'Number' + }, + { + name: 'dHeight', + description: 'the height of the destination rectangle
\n', + type: 'Number' + }, + { + name: 'sx', + description: + 'the x-coordinate of the subsection of the source\nimage to draw into the destination rectangle
\n', + type: 'Number' + }, + { + name: 'sy', + description: + 'the y-coordinate of the subsection of the source\nimage to draw into the destination rectangle
\n', + type: 'Number' + }, + { + name: 'sWidth', + description: + 'the width of the subsection of the\n source image to draw into the destination\n rectangle
\n', + type: 'Number', + optional: true + }, + { + name: 'sHeight', + description: + 'the height of the subsection of the\n source image to draw into the destination rectangle
\n', + type: 'Number', + optional: true + } + ] + } + ] + }, + tint: { + name: 'tint', + class: 'p5', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'value', + description: 'a color string
\n', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'gray', + description: 'a gray value
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red,green,blue &\n and alpha components of the color
\n', + type: 'Number[]' + } + ] + }, + { + params: [ + { + name: 'color', + description: 'the tint color
\n', + type: 'p5.Color' + } + ] + } + ] + }, + noTint: { + name: 'noTint', + class: 'p5', + module: 'Image' + }, + imageMode: { + name: 'imageMode', + params: [ + { + name: 'mode', + description: 'either CORNER, CORNERS, or CENTER
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Image' + }, + pixels: { + name: 'pixels', + class: 'p5', + module: 'Image' + }, + blend: { + name: 'blend', + class: 'p5', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'srcImage', + description: 'source image
\n', + type: 'p5.Image' + }, + { + name: 'sx', + description: + "X coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sy', + description: + "Y coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sw', + description: 'source image width
\n', + type: 'Integer' + }, + { + name: 'sh', + description: 'source image height
\n', + type: 'Integer' + }, + { + name: 'dx', + description: + "X coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dy', + description: + "Y coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dw', + description: 'destination image width
\n', + type: 'Integer' + }, + { + name: 'dh', + description: 'destination image height
\n', + type: 'Integer' + }, + { + name: 'blendMode', + description: + 'the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.
\n', + type: 'Constant' + } + ] + }, + { + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + }, + { + name: 'blendMode', + description: '', + type: 'Constant' + } + ] + } + ] + }, + copy: { + name: 'copy', + class: 'p5', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'srcImage', + description: 'source image
\n', + type: 'p5.Image|p5.Element' + }, + { + name: 'sx', + description: + "X coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sy', + description: + "Y coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sw', + description: 'source image width
\n', + type: 'Integer' + }, + { + name: 'sh', + description: 'source image height
\n', + type: 'Integer' + }, + { + name: 'dx', + description: + "X coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dy', + description: + "Y coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dw', + description: 'destination image width
\n', + type: 'Integer' + }, + { + name: 'dh', + description: 'destination image height
\n', + type: 'Integer' + } + ] + }, + { + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + } + ] + } + ] + }, + filter: { + name: 'filter', + params: [ + { + name: 'filterType', + description: + 'either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, BLUR, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter
\n', + type: 'Constant' + }, + { + name: 'filterParam', + description: + 'an optional parameter unique\n to each filter, see above
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Image' + }, + get: { + name: 'get', + class: 'p5', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'w', + description: 'width
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height
\n', + type: 'Number' + } + ] + }, + { + params: [] + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + } + ] + } + ] + }, + loadPixels: { + name: 'loadPixels', + class: 'p5', + module: 'Image' + }, + set: { + name: 'set', + params: [ + { + name: 'x', + description: 'x-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'c', + description: + 'insert a grayscale value | a pixel array |\n a p5.Color object | a p5.Image to copy
\n', + type: 'Number|Number[]|Object' + } + ], + class: 'p5', + module: 'Image' + }, + updatePixels: { + name: 'updatePixels', + params: [ + { + name: 'x', + description: + 'x-coordinate of the upper-left corner of region\n to update
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: + 'y-coordinate of the upper-left corner of region\n to update
\n', + type: 'Number', + optional: true + }, + { + name: 'w', + description: 'width of region to update
\n', + type: 'Number', + optional: true + }, + { + name: 'h', + description: 'height of region to update
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Image' + }, + loadJSON: { + name: 'loadJSON', + class: 'p5', + module: 'IO', + overloads: [ + { + params: [ + { + name: 'path', + description: 'name of the file or url to load
\n', + type: 'String' + }, + { + name: 'jsonpOptions', + description: 'options object for jsonp related settings
\n', + type: 'Object', + optional: true + }, + { + name: 'datatype', + description: '"json" or "jsonp"
\n', + type: 'String', + optional: true + }, + { + name: 'callback', + description: + 'function to be executed after\n loadJSON() completes, data is passed\n in as first argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'datatype', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function' + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + } + ] + }, + loadStrings: { + name: 'loadStrings', + params: [ + { + name: 'filename', + description: 'name of the file or url to load
\n', + type: 'String' + }, + { + name: 'callback', + description: + 'function to be executed after loadStrings()\n completes, Array is passed in as first\n argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + loadTable: { + name: 'loadTable', + params: [ + { + name: 'filename', + description: 'name of the file or URL to load
\n', + type: 'String' + }, + { + name: 'extension', + description: + 'parse the table by comma-separated values "csv", semicolon-separated\n values "ssv", or tab-separated values "tsv"
\n', + type: 'String', + optional: true + }, + { + name: 'header', + description: '"header" to indicate table has header row
\n', + type: 'String', + optional: true + }, + { + name: 'callback', + description: + 'function to be executed after\n loadTable() completes. On success, the\n Table object is passed in as the\n first argument.
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + loadXML: { + name: 'loadXML', + params: [ + { + name: 'filename', + description: 'name of the file or URL to load
\n', + type: 'String' + }, + { + name: 'callback', + description: + 'function to be executed after loadXML()\n completes, XML object is passed in as\n first argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + loadBytes: { + name: 'loadBytes', + params: [ + { + name: 'file', + description: 'name of the file or URL to load
\n', + type: 'String' + }, + { + name: 'callback', + description: + 'function to be executed after loadBytes()\n completes
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if there\n is an error
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + httpGet: { + name: 'httpGet', + class: 'p5', + module: 'IO', + overloads: [ + { + params: [ + { + name: 'path', + description: 'name of the file or url to load
\n', + type: 'String' + }, + { + name: 'datatype', + description: + '"json", "jsonp", "binary", "arrayBuffer",\n "xml", or "text"
\n', + type: 'String', + optional: true + }, + { + name: 'data', + description: 'param data passed sent with request
\n', + type: 'Object|Boolean', + optional: true + }, + { + name: 'callback', + description: + 'function to be executed after\n httpGet() completes, data is passed in\n as first argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'data', + description: '', + type: 'Object|Boolean' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function' + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + } + ] + }, + httpPost: { + name: 'httpPost', + class: 'p5', + module: 'IO', + overloads: [ + { + params: [ + { + name: 'path', + description: 'name of the file or url to load
\n', + type: 'String' + }, + { + name: 'datatype', + description: + '"json", "jsonp", "xml", or "text".\n If omitted, httpPost() will guess.
\n', + type: 'String', + optional: true + }, + { + name: 'data', + description: 'param data passed sent with request
\n', + type: 'Object|Boolean', + optional: true + }, + { + name: 'callback', + description: + 'function to be executed after\n httpPost() completes, data is passed in\n as first argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'data', + description: '', + type: 'Object|Boolean' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function' + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + } + ] + }, + httpDo: { + name: 'httpDo', + class: 'p5', + module: 'IO', + overloads: [ + { + params: [ + { + name: 'path', + description: 'name of the file or url to load
\n', + type: 'String' + }, + { + name: 'method', + description: + 'either "GET", "POST", or "PUT",\n defaults to "GET"
\n', + type: 'String', + optional: true + }, + { + name: 'datatype', + description: '"json", "jsonp", "xml", or "text"
\n', + type: 'String', + optional: true + }, + { + name: 'data', + description: 'param data passed sent with request
\n', + type: 'Object', + optional: true + }, + { + name: 'callback', + description: + 'function to be executed after\n httpGet() completes, data is passed in\n as first argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to be executed if\n there is an error, response is passed\n in as first argument
\n', + type: 'Function', + optional: true + } + ] + }, + { + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'options', + description: + 'Request object options as documented in the\n "fetch" API\nreference
\n', + type: 'Object' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ] + } + ] + }, + createWriter: { + name: 'createWriter', + params: [ + { + name: 'name', + description: 'name of the file to be created
\n', + type: 'String' + }, + { + name: 'extension', + description: '', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + save: { + name: 'save', + params: [ + { + name: 'objectOrFilename', + description: + 'If filename is provided, will\n save canvas as an image with\n either png or jpg extension\n depending on the filename.\n If object is provided, will\n save depending on the object\n and filename (see examples\n above).
\n', + type: 'Object|String', + optional: true + }, + { + name: 'filename', + description: + 'If an object is provided as the first\n parameter, then the second parameter\n indicates the filename,\n and should include an appropriate\n file extension (see examples above).
\n', + type: 'String', + optional: true + }, + { + name: 'options', + description: + 'Additional options depend on\n filetype. For example, when saving JSON,\n true
indicates that the\n output will be optimized for filesize,\n rather than readability.
If true, removes line breaks\n and spaces from the output\n file to optimize filesize\n (but not readability).
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + saveStrings: { + name: 'saveStrings', + params: [ + { + name: 'list', + description: 'string array to be written
\n', + type: 'String[]' + }, + { + name: 'filename', + description: 'filename for output
\n', + type: 'String' + }, + { + name: 'extension', + description: "the filename's extension
\n", + type: 'String', + optional: true + }, + { + name: 'isCRLF', + description: 'if true, change line-break to CRLF
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + saveTable: { + name: 'saveTable', + params: [ + { + name: 'Table', + description: + 'the Table object to save to a file
\n', + type: 'p5.Table' + }, + { + name: 'filename', + description: 'the filename to which the Table should be saved
\n', + type: 'String' + }, + { + name: 'options', + description: 'can be one of "tsv", "csv", or "html"
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'IO' + }, + abs: { + name: 'abs', + params: [ + { + name: 'n', + description: 'number to compute
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + ceil: { + name: 'ceil', + params: [ + { + name: 'n', + description: 'number to round up
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + constrain: { + name: 'constrain', + params: [ + { + name: 'n', + description: 'number to constrain
\n', + type: 'Number' + }, + { + name: 'low', + description: 'minimum limit
\n', + type: 'Number' + }, + { + name: 'high', + description: 'maximum limit
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + dist: { + name: 'dist', + class: 'p5', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x1', + description: 'x-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'y1', + description: 'y-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: 'x-coordinate of the second point
\n', + type: 'Number' + }, + { + name: 'y2', + description: 'y-coordinate of the second point
\n', + type: 'Number' + } + ] + }, + { + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: 'z-coordinate of the first point
\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: 'z-coordinate of the second point
\n', + type: 'Number' + } + ] + } + ] + }, + exp: { + name: 'exp', + params: [ + { + name: 'n', + description: 'exponent to raise
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + floor: { + name: 'floor', + params: [ + { + name: 'n', + description: 'number to round down
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + lerp: { + name: 'lerp', + params: [ + { + name: 'start', + description: 'first value
\n', + type: 'Number' + }, + { + name: 'stop', + description: 'second value
\n', + type: 'Number' + }, + { + name: 'amt', + description: 'number
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + log: { + name: 'log', + params: [ + { + name: 'n', + description: 'number greater than 0
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + mag: { + name: 'mag', + params: [ + { + name: 'a', + description: 'first value
\n', + type: 'Number' + }, + { + name: 'b', + description: 'second value
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + map: { + name: 'map', + params: [ + { + name: 'value', + description: 'the incoming value to be converted
\n', + type: 'Number' + }, + { + name: 'start1', + description: "lower bound of the value's current range
\n", + type: 'Number' + }, + { + name: 'stop1', + description: "upper bound of the value's current range
\n", + type: 'Number' + }, + { + name: 'start2', + description: "lower bound of the value's target range
\n", + type: 'Number' + }, + { + name: 'stop2', + description: "upper bound of the value's target range
\n", + type: 'Number' + }, + { + name: 'withinBounds', + description: 'constrain the value to the newly mapped range
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'Math' + }, + max: { + name: 'max', + class: 'p5', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'n0', + description: 'Number to compare
\n', + type: 'Number' + }, + { + name: 'n1', + description: 'Number to compare
\n', + type: 'Number' + } + ] + }, + { + params: [ + { + name: 'nums', + description: 'Numbers to compare
\n', + type: 'Number[]' + } + ] + } + ] + }, + min: { + name: 'min', + class: 'p5', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'n0', + description: 'Number to compare
\n', + type: 'Number' + }, + { + name: 'n1', + description: 'Number to compare
\n', + type: 'Number' + } + ] + }, + { + params: [ + { + name: 'nums', + description: 'Numbers to compare
\n', + type: 'Number[]' + } + ] + } + ] + }, + norm: { + name: 'norm', + params: [ + { + name: 'value', + description: 'incoming value to be normalized
\n', + type: 'Number' + }, + { + name: 'start', + description: "lower bound of the value's current range
\n", + type: 'Number' + }, + { + name: 'stop', + description: "upper bound of the value's current range
\n", + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + pow: { + name: 'pow', + params: [ + { + name: 'n', + description: 'base of the exponential expression
\n', + type: 'Number' + }, + { + name: 'e', + description: 'power by which to raise the base
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + round: { + name: 'round', + params: [ + { + name: 'n', + description: 'number to round
\n', + type: 'Number' + }, + { + name: 'decimals', + description: + 'number of decimal places to round to, default is 0
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Math' + }, + sq: { + name: 'sq', + params: [ + { + name: 'n', + description: 'number to square
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + sqrt: { + name: 'sqrt', + params: [ + { + name: 'n', + description: 'non-negative number to square root
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + fract: { + name: 'fract', + params: [ + { + name: 'num', + description: + 'Number whose fractional part needs to be found out
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + createVector: { + name: 'createVector', + params: [ + { + name: 'x', + description: 'x component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: 'y component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'z component of the vector
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Math' + }, + noise: { + name: 'noise', + params: [ + { + name: 'x', + description: 'x-coordinate in noise space
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate in noise space
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'z-coordinate in noise space
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Math' + }, + noiseDetail: { + name: 'noiseDetail', + params: [ + { + name: 'lod', + description: 'number of octaves to be used by the noise
\n', + type: 'Number' + }, + { + name: 'falloff', + description: 'falloff factor for each octave
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + noiseSeed: { + name: 'noiseSeed', + params: [ + { + name: 'seed', + description: 'the seed value
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + randomSeed: { + name: 'randomSeed', + params: [ + { + name: 'seed', + description: 'the seed value
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + random: { + name: 'random', + class: 'p5', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'min', + description: 'the lower bound (inclusive)
\n', + type: 'Number', + optional: true + }, + { + name: 'max', + description: 'the upper bound (exclusive)
\n', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'choices', + description: 'the array to choose from
\n', + type: 'Array' + } + ] + } + ] + }, + randomGaussian: { + name: 'randomGaussian', + params: [ + { + name: 'mean', + description: 'the mean
\n', + type: 'Number', + optional: true + }, + { + name: 'sd', + description: 'the standard deviation
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Math' + }, + acos: { + name: 'acos', + params: [ + { + name: 'value', + description: 'the value whose arc cosine is to be returned
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + asin: { + name: 'asin', + params: [ + { + name: 'value', + description: 'the value whose arc sine is to be returned
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + atan: { + name: 'atan', + params: [ + { + name: 'value', + description: 'the value whose arc tangent is to be returned
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + atan2: { + name: 'atan2', + params: [ + { + name: 'y', + description: 'y-coordinate of the point
\n', + type: 'Number' + }, + { + name: 'x', + description: 'x-coordinate of the point
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + cos: { + name: 'cos', + params: [ + { + name: 'angle', + description: 'the angle
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + sin: { + name: 'sin', + params: [ + { + name: 'angle', + description: 'the angle
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + tan: { + name: 'tan', + params: [ + { + name: 'angle', + description: 'the angle
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + degrees: { + name: 'degrees', + params: [ + { + name: 'radians', + description: 'the radians value to convert to degrees
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + radians: { + name: 'radians', + params: [ + { + name: 'degrees', + description: 'the degree value to convert to radians
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Math' + }, + angleMode: { + name: 'angleMode', + params: [ + { + name: 'mode', + description: 'either RADIANS or DEGREES
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Math' + }, + textAlign: { + name: 'textAlign', + class: 'p5', + module: 'Typography', + overloads: [ + { + params: [ + { + name: 'horizAlign', + description: + 'horizontal alignment, either LEFT,\n CENTER, or RIGHT
\n', + type: 'Constant' + }, + { + name: 'vertAlign', + description: + 'vertical alignment, either TOP,\n BOTTOM, CENTER, or BASELINE
\n', + type: 'Constant', + optional: true + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + textLeading: { + name: 'textLeading', + class: 'p5', + module: 'Typography', + overloads: [ + { + params: [ + { + name: 'leading', + description: + 'the size in pixels for spacing between lines
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + textSize: { + name: 'textSize', + class: 'p5', + module: 'Typography', + overloads: [ + { + params: [ + { + name: 'theSize', + description: 'the size of the letters in units of pixels
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + textStyle: { + name: 'textStyle', + class: 'p5', + module: 'Typography', + overloads: [ + { + params: [ + { + name: 'theStyle', + description: + 'styling for text, either NORMAL,\n ITALIC, BOLD or BOLDITALIC
\n', + type: 'Constant' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + textWidth: { + name: 'textWidth', + params: [ + { + name: 'theText', + description: 'the String of characters to measure
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Typography' + }, + textAscent: { + name: 'textAscent', + class: 'p5', + module: 'Typography' + }, + textDescent: { + name: 'textDescent', + class: 'p5', + module: 'Typography' + }, + loadFont: { + name: 'loadFont', + params: [ + { + name: 'path', + description: 'name of the file or url to load
\n', + type: 'String' + }, + { + name: 'callback', + description: + 'function to be executed after\n loadFont() completes
\n', + type: 'Function', + optional: true + }, + { + name: 'onError', + description: + 'function to be executed if\n an error occurs
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'Typography' + }, + text: { + name: 'text', + params: [ + { + name: 'str', + description: + 'the alphanumeric\n symbols to be displayed
\n', + type: 'String|Object|Array|Number|Boolean' + }, + { + name: 'x', + description: 'x-coordinate of text
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of text
\n', + type: 'Number' + }, + { + name: 'x2', + description: + 'by default, the width of the text box,\n see rectMode() for more info
\n', + type: 'Number', + optional: true + }, + { + name: 'y2', + description: + 'by default, the height of the text box,\n see rectMode() for more info
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Typography' + }, + textFont: { + name: 'textFont', + class: 'p5', + module: 'Typography', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'font', + description: + 'a font loaded via loadFont(),\nor a String representing a web safe font\n(a font that is generally available across all systems)
\n', + type: 'Object|String' + }, + { + name: 'size', + description: 'the font size to use
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + append: { + name: 'append', + params: [ + { + name: 'array', + description: 'Array to append
\n', + type: 'Array' + }, + { + name: 'value', + description: 'to be added to the Array
\n', + type: 'Any' + } + ], + class: 'p5', + module: 'Data' + }, + arrayCopy: { + name: 'arrayCopy', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'src', + description: 'the source Array
\n', + type: 'Array' + }, + { + name: 'srcPosition', + description: 'starting position in the source Array
\n', + type: 'Integer' + }, + { + name: 'dst', + description: 'the destination Array
\n', + type: 'Array' + }, + { + name: 'dstPosition', + description: 'starting position in the destination Array
\n', + type: 'Integer' + }, + { + name: 'length', + description: 'number of Array elements to be copied
\n', + type: 'Integer' + } + ] + }, + { + params: [ + { + name: 'src', + description: '', + type: 'Array' + }, + { + name: 'dst', + description: '', + type: 'Array' + }, + { + name: 'length', + description: '', + type: 'Integer', + optional: true + } + ] + } + ] + }, + concat: { + name: 'concat', + params: [ + { + name: 'a', + description: 'first Array to concatenate
\n', + type: 'Array' + }, + { + name: 'b', + description: 'second Array to concatenate
\n', + type: 'Array' + } + ], + class: 'p5', + module: 'Data' + }, + reverse: { + name: 'reverse', + params: [ + { + name: 'list', + description: 'Array to reverse
\n', + type: 'Array' + } + ], + class: 'p5', + module: 'Data' + }, + shorten: { + name: 'shorten', + params: [ + { + name: 'list', + description: 'Array to shorten
\n', + type: 'Array' + } + ], + class: 'p5', + module: 'Data' + }, + shuffle: { + name: 'shuffle', + params: [ + { + name: 'array', + description: 'Array to shuffle
\n', + type: 'Array' + }, + { + name: 'bool', + description: 'modify passed array
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'Data' + }, + sort: { + name: 'sort', + params: [ + { + name: 'list', + description: 'Array to sort
\n', + type: 'Array' + }, + { + name: 'count', + description: 'number of elements to sort, starting from 0
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Data' + }, + splice: { + name: 'splice', + params: [ + { + name: 'list', + description: 'Array to splice into
\n', + type: 'Array' + }, + { + name: 'value', + description: 'value to be spliced in
\n', + type: 'Any' + }, + { + name: 'position', + description: 'in the array from which to insert data
\n', + type: 'Integer' + } + ], + class: 'p5', + module: 'Data' + }, + subset: { + name: 'subset', + params: [ + { + name: 'list', + description: 'Array to extract from
\n', + type: 'Array' + }, + { + name: 'start', + description: 'position to begin
\n', + type: 'Integer' + }, + { + name: 'count', + description: 'number of values to extract
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Data' + }, + float: { + name: 'float', + params: [ + { + name: 'str', + description: 'float string to parse
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + int: { + name: 'int', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String|Boolean|Number' + }, + { + name: 'radix', + description: 'the radix to convert to (default: 10)
\n', + type: 'Integer', + optional: true + } + ] + }, + { + params: [ + { + name: 'ns', + description: 'values to parse
\n', + type: 'Array' + }, + { + name: 'radix', + description: '', + type: 'Integer', + optional: true + } + ] + } + ] + }, + str: { + name: 'str', + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String|Boolean|Number|Array' + } + ], + class: 'p5', + module: 'Data' + }, + byte: { + name: 'byte', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String|Boolean|Number' + } + ] + }, + { + params: [ + { + name: 'ns', + description: 'values to parse
\n', + type: 'Array' + } + ] + } + ] + }, + char: { + name: 'char', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String|Number' + } + ] + }, + { + params: [ + { + name: 'ns', + description: 'values to parse
\n', + type: 'Array' + } + ] + } + ] + }, + unchar: { + name: 'unchar', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'ns', + description: 'values to parse
\n', + type: 'Array' + } + ] + } + ] + }, + hex: { + name: 'hex', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'Number' + }, + { + name: 'digits', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'ns', + description: 'array of values to parse
\n', + type: 'Number[]' + }, + { + name: 'digits', + description: '', + type: 'Number', + optional: true + } + ] + } + ] + }, + unhex: { + name: 'unhex', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'n', + description: 'value to parse
\n', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'ns', + description: 'values to parse
\n', + type: 'Array' + } + ] + } + ] + }, + join: { + name: 'join', + params: [ + { + name: 'list', + description: 'array of Strings to be joined
\n', + type: 'Array' + }, + { + name: 'separator', + description: 'String to be placed between each item
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + match: { + name: 'match', + params: [ + { + name: 'str', + description: 'the String to be searched
\n', + type: 'String' + }, + { + name: 'regexp', + description: 'the regexp to be used for matching
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + matchAll: { + name: 'matchAll', + params: [ + { + name: 'str', + description: 'the String to be searched
\n', + type: 'String' + }, + { + name: 'regexp', + description: 'the regexp to be used for matching
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + nf: { + name: 'nf', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'num', + description: 'the Number to format
\n', + type: 'Number|String' + }, + { + name: 'left', + description: + 'number of digits to the left of the\n decimal point
\n', + type: 'Integer|String', + optional: true + }, + { + name: 'right', + description: + 'number of digits to the right of the\n decimal point
\n', + type: 'Integer|String', + optional: true + } + ] + }, + { + params: [ + { + name: 'nums', + description: 'the Numbers to format
\n', + type: 'Array' + }, + { + name: 'left', + description: '', + type: 'Integer|String', + optional: true + }, + { + name: 'right', + description: '', + type: 'Integer|String', + optional: true + } + ] + } + ] + }, + nfc: { + name: 'nfc', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'num', + description: 'the Number to format
\n', + type: 'Number|String' + }, + { + name: 'right', + description: + 'number of digits to the right of the\n decimal point
\n', + type: 'Integer|String', + optional: true + } + ] + }, + { + params: [ + { + name: 'nums', + description: 'the Numbers to format
\n', + type: 'Array' + }, + { + name: 'right', + description: '', + type: 'Integer|String', + optional: true + } + ] + } + ] + }, + nfp: { + name: 'nfp', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'num', + description: 'the Number to format
\n', + type: 'Number' + }, + { + name: 'left', + description: + 'number of digits to the left of the decimal\n point
\n', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: + 'number of digits to the right of the\n decimal point
\n', + type: 'Integer', + optional: true + } + ] + }, + { + params: [ + { + name: 'nums', + description: 'the Numbers to format
\n', + type: 'Number[]' + }, + { + name: 'left', + description: '', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: '', + type: 'Integer', + optional: true + } + ] + } + ] + }, + nfs: { + name: 'nfs', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'num', + description: 'the Number to format
\n', + type: 'Number' + }, + { + name: 'left', + description: + 'number of digits to the left of the decimal\n point
\n', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: + 'number of digits to the right of the\n decimal point
\n', + type: 'Integer', + optional: true + } + ] + }, + { + params: [ + { + name: 'nums', + description: 'the Numbers to format
\n', + type: 'Array' + }, + { + name: 'left', + description: '', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: '', + type: 'Integer', + optional: true + } + ] + } + ] + }, + split: { + name: 'split', + params: [ + { + name: 'value', + description: 'the String to be split
\n', + type: 'String' + }, + { + name: 'delim', + description: 'the String used to separate the data
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Data' + }, + splitTokens: { + name: 'splitTokens', + params: [ + { + name: 'value', + description: 'the String to be split
\n', + type: 'String' + }, + { + name: 'delim', + description: + 'list of individual Strings that will be used as\n separators
\n', + type: 'String', + optional: true + } + ], + class: 'p5', + module: 'Data' + }, + trim: { + name: 'trim', + class: 'p5', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'str', + description: 'a String to be trimmed
\n', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'strs', + description: 'an Array of Strings to be trimmed
\n', + type: 'Array' + } + ] + } + ] + }, + day: { + name: 'day', + class: 'p5', + module: 'IO' + }, + hour: { + name: 'hour', + class: 'p5', + module: 'IO' + }, + minute: { + name: 'minute', + class: 'p5', + module: 'IO' + }, + millis: { + name: 'millis', + class: 'p5', + module: 'IO' + }, + month: { + name: 'month', + class: 'p5', + module: 'IO' + }, + second: { + name: 'second', + class: 'p5', + module: 'IO' + }, + year: { + name: 'year', + class: 'p5', + module: 'IO' + }, + plane: { + name: 'plane', + params: [ + { + name: 'width', + description: 'width of the plane
\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: 'height of the plane
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + 'Optional number of triangle\n subdivisions in x-dimension
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'Optional number of triangle\n subdivisions in y-dimension
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + box: { + name: 'box', + params: [ + { + name: 'width', + description: 'width of the box
\n', + type: 'Number', + optional: true + }, + { + name: 'Height', + description: 'height of the box
\n', + type: 'Number', + optional: true + }, + { + name: 'depth', + description: 'depth of the box
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + 'Optional number of triangle\n subdivisions in x-dimension
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'Optional number of triangle\n subdivisions in y-dimension
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + sphere: { + name: 'sphere', + params: [ + { + name: 'radius', + description: 'radius of circle
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: 'optional number of subdivisions in x-dimension
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: 'optional number of subdivisions in y-dimension
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + cylinder: { + name: 'cylinder', + params: [ + { + name: 'radius', + description: 'radius of the surface
\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: 'height of the cylinder
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + 'number of subdivisions in x-dimension;\n default is 24
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'number of subdivisions in y-dimension;\n default is 1
\n', + type: 'Integer', + optional: true + }, + { + name: 'bottomCap', + description: 'whether to draw the bottom of the cylinder
\n', + type: 'Boolean', + optional: true + }, + { + name: 'topCap', + description: 'whether to draw the top of the cylinder
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + cone: { + name: 'cone', + params: [ + { + name: 'radius', + description: 'radius of the bottom surface
\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: 'height of the cone
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + 'number of segments,\n the more segments the smoother geometry\n default is 24
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'number of segments,\n the more segments the smoother geometry\n default is 1
\n', + type: 'Integer', + optional: true + }, + { + name: 'cap', + description: 'whether to draw the base of the cone
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + ellipsoid: { + name: 'ellipsoid', + params: [ + { + name: 'radiusx', + description: 'x-radius of ellipsoid
\n', + type: 'Number', + optional: true + }, + { + name: 'radiusy', + description: 'y-radius of ellipsoid
\n', + type: 'Number', + optional: true + }, + { + name: 'radiusz', + description: 'z-radius of ellipsoid
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + 'number of segments,\n the more segments the smoother geometry\n default is 24. Avoid detail number above\n 150, it may crash the browser.
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'number of segments,\n the more segments the smoother geometry\n default is 16. Avoid detail number above\n 150, it may crash the browser.
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + torus: { + name: 'torus', + params: [ + { + name: 'radius', + description: 'radius of the whole ring
\n', + type: 'Number', + optional: true + }, + { + name: 'tubeRadius', + description: 'radius of the tube
\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + 'number of segments in x-dimension,\n the more segments the smoother geometry\n default is 24
\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + 'number of segments in y-dimension,\n the more segments the smoother geometry\n default is 16
\n', + type: 'Integer', + optional: true + } + ], + class: 'p5', + module: 'Shape' + }, + orbitControl: { + name: 'orbitControl', + params: [ + { + name: 'sensitivityX', + description: 'sensitivity to mouse movement along X axis
\n', + type: 'Number', + optional: true + }, + { + name: 'sensitivityY', + description: 'sensitivity to mouse movement along Y axis
\n', + type: 'Number', + optional: true + }, + { + name: 'sensitivityZ', + description: 'sensitivity to scroll movement along Z axis
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + debugMode: { + name: 'debugMode', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'mode', + description: 'either GRID or AXES
\n', + type: 'Constant' + } + ] + }, + { + params: [ + { + name: 'mode', + description: '', + type: 'Constant' + }, + { + name: 'gridSize', + description: 'size of one side of the grid
\n', + type: 'Number', + optional: true + }, + { + name: 'gridDivisions', + description: 'number of divisions in the grid
\n', + type: 'Number', + optional: true + }, + { + name: 'xOff', + description: 'X axis offset from origin (0,0,0)
\n', + type: 'Number', + optional: true + }, + { + name: 'yOff', + description: 'Y axis offset from origin (0,0,0)
\n', + type: 'Number', + optional: true + }, + { + name: 'zOff', + description: 'Z axis offset from origin (0,0,0)
\n', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'mode', + description: '', + type: 'Constant' + }, + { + name: 'axesSize', + description: 'size of axes icon
\n', + type: 'Number', + optional: true + }, + { + name: 'xOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'yOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'zOff', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'gridSize', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridDivisions', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridXOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridYOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridZOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesSize', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesXOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesYOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesZOff', + description: '', + type: 'Number', + optional: true + } + ] + } + ] + }, + noDebugMode: { + name: 'noDebugMode', + class: 'p5', + module: 'Lights, Camera' + }, + ambientLight: { + name: 'ambientLight', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'alpha', + description: 'the alpha value
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'a color string
\n', + type: 'String' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'gray', + description: 'a gray value
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red,green,blue &\n and alpha components of the color
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'the ambient light color
\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + specularColor: { + name: 'specularColor', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'a color string
\n', + type: 'String' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'gray', + description: 'a gray value
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'values', + description: + 'an array containing the red,green,blue &\n and alpha components of the color
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'the ambient light color
\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + directionalLight: { + name: 'directionalLight', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value (depending on the current\ncolor mode),
\n', + type: 'Number' + }, + { + name: 'v2', + description: 'green or saturation value
\n', + type: 'Number' + }, + { + name: 'v3', + description: 'blue or brightness value
\n', + type: 'Number' + }, + { + name: 'position', + description: 'the direction of the light
\n', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: + 'color Array, CSS color string,\n or p5.Color value
\n', + type: 'Number[]|String|p5.Color' + }, + { + name: 'x', + description: 'x axis direction
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y axis direction
\n', + type: 'Number' + }, + { + name: 'z', + description: 'z axis direction
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + pointLight: { + name: 'pointLight', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value (depending on the current\ncolor mode),
\n', + type: 'Number' + }, + { + name: 'v2', + description: 'green or saturation value
\n', + type: 'Number' + }, + { + name: 'v3', + description: 'blue or brightness value
\n', + type: 'Number' + }, + { + name: 'x', + description: 'x axis position
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y axis position
\n', + type: 'Number' + }, + { + name: 'z', + description: 'z axis position
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'position', + description: 'the position of the light
\n', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: + 'color Array, CSS color string,\nor p5.Color value
\n', + type: 'Number[]|String|p5.Color' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + } + ], + chainable: 1 + } + ] + }, + lights: { + name: 'lights', + class: 'p5', + module: 'Lights, Camera' + }, + lightFalloff: { + name: 'lightFalloff', + params: [ + { + name: 'constant', + description: 'constant value for determining falloff
\n', + type: 'Number' + }, + { + name: 'linear', + description: 'linear value for determining falloff
\n', + type: 'Number' + }, + { + name: 'quadratic', + description: 'quadratic value for determining falloff
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + spotLight: { + name: 'spotLight', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'red or hue value (depending on the current\ncolor mode),
\n', + type: 'Number' + }, + { + name: 'v2', + description: 'green or saturation value
\n', + type: 'Number' + }, + { + name: 'v3', + description: 'blue or brightness value
\n', + type: 'Number' + }, + { + name: 'x', + description: 'x axis position
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y axis position
\n', + type: 'Number' + }, + { + name: 'z', + description: 'z axis position
\n', + type: 'Number' + }, + { + name: 'rx', + description: 'x axis direction of light
\n', + type: 'Number' + }, + { + name: 'ry', + description: 'y axis direction of light
\n', + type: 'Number' + }, + { + name: 'rz', + description: 'z axis direction of light
\n', + type: 'Number' + }, + { + name: 'angle', + description: + 'optional parameter for angle. Defaults to PI/3
\n', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: + 'optional parameter for concentration. Defaults to 100
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: + 'color Array, CSS color string,\nor p5.Color value
\n', + type: 'Number[]|String|p5.Color' + }, + { + name: 'position', + description: 'the position of the light
\n', + type: 'p5.Vector' + }, + { + name: 'direction', + description: 'the direction of the light
\n', + type: 'p5.Vector' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + }, + { + name: 'direction', + description: '', + type: 'p5.Vector' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + }, + { + name: 'direction', + description: '', + type: 'p5.Vector' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + }, + { + name: 'rx', + description: '', + type: 'Number' + }, + { + name: 'ry', + description: '', + type: 'Number' + }, + { + name: 'rz', + description: '', + type: 'Number' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + }, + { + name: 'direction', + description: '', + type: 'p5.Vector' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + }, + { + name: 'rx', + description: '', + type: 'Number' + }, + { + name: 'ry', + description: '', + type: 'Number' + }, + { + name: 'rz', + description: '', + type: 'Number' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + }, + { + name: 'rx', + description: '', + type: 'Number' + }, + { + name: 'ry', + description: '', + type: 'Number' + }, + { + name: 'rz', + description: '', + type: 'Number' + }, + { + name: 'angle', + description: '', + type: 'Number', + optional: true + }, + { + name: 'conc', + description: '', + type: 'Number', + optional: true + } + ] + } + ] + }, + noLights: { + name: 'noLights', + class: 'p5', + module: 'Lights, Camera' + }, + loadModel: { + name: 'loadModel', + class: 'p5', + module: 'Shape', + overloads: [ + { + params: [ + { + name: 'path', + description: 'Path of the model to be loaded
\n', + type: 'String' + }, + { + name: 'normalize', + description: + 'If true, scale the model to a\n standardized size when loading
\n', + type: 'Boolean' + }, + { + name: 'successCallback', + description: + 'Function to be called\n once the model is loaded. Will be passed\n the 3D model object.
\n', + type: 'function(p5.Geometry)', + optional: true + }, + { + name: 'failureCallback', + description: + 'called with event error if\n the model fails to load.
\n', + type: 'Function(Event)', + optional: true + }, + { + name: 'fileType', + description: + 'The file extension of the model\n (.stl
, .obj
).
Loaded 3d model to be rendered
\n', + type: 'p5.Geometry' + } + ], + class: 'p5', + module: 'Shape' + }, + loadShader: { + name: 'loadShader', + params: [ + { + name: 'vertFilename', + description: + 'path to file containing vertex shader\nsource code
\n', + type: 'String' + }, + { + name: 'fragFilename', + description: + 'path to file containing fragment shader\nsource code
\n', + type: 'String' + }, + { + name: 'callback', + description: + 'callback to be executed after loadShader\ncompletes. On success, the Shader object is passed as the first argument.
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'callback to be executed when an error\noccurs inside loadShader. On error, the error is passed as the first\nargument.
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + createShader: { + name: 'createShader', + params: [ + { + name: 'vertSrc', + description: 'source code for the vertex shader
\n', + type: 'String' + }, + { + name: 'fragSrc', + description: 'source code for the fragment shader
\n', + type: 'String' + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + shader: { + name: 'shader', + params: [ + { + name: 's', + description: + 'the desired p5.Shader to use for rendering\nshapes.
\n', + type: 'p5.Shader', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + resetShader: { + name: 'resetShader', + class: 'p5', + module: 'Lights, Camera' + }, + normalMaterial: { + name: 'normalMaterial', + class: 'p5', + module: 'Lights, Camera' + }, + texture: { + name: 'texture', + params: [ + { + name: 'tex', + description: + '2-dimensional graphics\n to render as texture
\n', + type: 'p5.Image|p5.MediaElement|p5.Graphics' + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + textureMode: { + name: 'textureMode', + params: [ + { + name: 'mode', + description: 'either IMAGE or NORMAL
\n', + type: 'Constant' + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + textureWrap: { + name: 'textureWrap', + params: [ + { + name: 'wrapX', + description: 'either CLAMP, REPEAT, or MIRROR
\n', + type: 'Constant' + }, + { + name: 'wrapY', + description: 'either CLAMP, REPEAT, or MIRROR
\n', + type: 'Constant', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + ambientMaterial: { + name: 'ambientMaterial', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'gray value, red or hue value\n (depending on the current color mode),
\n', + type: 'Number' + }, + { + name: 'v2', + description: 'green or saturation value
\n', + type: 'Number', + optional: true + }, + { + name: 'v3', + description: 'blue or brightness value
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'color, color Array, or CSS color string
\n', + type: 'Number[]|String|p5.Color' + } + ], + chainable: 1 + } + ] + }, + emissiveMaterial: { + name: 'emissiveMaterial', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'v1', + description: + 'gray value, red or hue value\n (depending on the current color mode),
\n', + type: 'Number' + }, + { + name: 'v2', + description: 'green or saturation value
\n', + type: 'Number', + optional: true + }, + { + name: 'v3', + description: 'blue or brightness value
\n', + type: 'Number', + optional: true + }, + { + name: 'a', + description: 'opacity
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'color, color Array, or CSS color string
\n', + type: 'Number[]|String|p5.Color' + } + ], + chainable: 1 + } + ] + }, + specularMaterial: { + name: 'specularMaterial', + class: 'p5', + module: 'Lights, Camera', + overloads: [ + { + params: [ + { + name: 'gray', + description: + 'number specifying value between white and black.
\n', + type: 'Number' + }, + { + name: 'alpha', + description: + 'alpha value relative to current color range\n (default is 0-255)
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: + 'red or hue value relative to\n the current color range
\n', + type: 'Number' + }, + { + name: 'v2', + description: + 'green or saturation value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'v3', + description: + 'blue or brightness value\n relative to the current color range
\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'color', + description: 'color Array, or CSS color string
\n', + type: 'Number[]|String|p5.Color' + } + ], + chainable: 1 + } + ] + }, + shininess: { + name: 'shininess', + params: [ + { + name: 'shine', + description: + 'Degree of Shininess.\n Defaults to 1.
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + camera: { + name: 'camera', + params: [ + { + name: 'x', + description: 'camera position value on x axis
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: 'camera position value on y axis
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'camera position value on z axis
\n', + type: 'Number', + optional: true + }, + { + name: 'centerX', + description: 'x coordinate representing center of the sketch
\n', + type: 'Number', + optional: true + }, + { + name: 'centerY', + description: 'y coordinate representing center of the sketch
\n', + type: 'Number', + optional: true + }, + { + name: 'centerZ', + description: 'z coordinate representing center of the sketch
\n', + type: 'Number', + optional: true + }, + { + name: 'upX', + description: "x component of direction 'up' from camera
\n", + type: 'Number', + optional: true + }, + { + name: 'upY', + description: "y component of direction 'up' from camera
\n", + type: 'Number', + optional: true + }, + { + name: 'upZ', + description: "z component of direction 'up' from camera
\n", + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + perspective: { + name: 'perspective', + params: [ + { + name: 'fovy', + description: + 'camera frustum vertical field of view,\n from bottom to top of view, in angleMode units
\n', + type: 'Number', + optional: true + }, + { + name: 'aspect', + description: 'camera frustum aspect ratio
\n', + type: 'Number', + optional: true + }, + { + name: 'near', + description: 'frustum near plane length
\n', + type: 'Number', + optional: true + }, + { + name: 'far', + description: 'frustum far plane length
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + ortho: { + name: 'ortho', + params: [ + { + name: 'left', + description: 'camera frustum left plane
\n', + type: 'Number', + optional: true + }, + { + name: 'right', + description: 'camera frustum right plane
\n', + type: 'Number', + optional: true + }, + { + name: 'bottom', + description: 'camera frustum bottom plane
\n', + type: 'Number', + optional: true + }, + { + name: 'top', + description: 'camera frustum top plane
\n', + type: 'Number', + optional: true + }, + { + name: 'near', + description: 'camera frustum near plane
\n', + type: 'Number', + optional: true + }, + { + name: 'far', + description: 'camera frustum far plane
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + frustum: { + name: 'frustum', + params: [ + { + name: 'left', + description: 'camera frustum left plane
\n', + type: 'Number', + optional: true + }, + { + name: 'right', + description: 'camera frustum right plane
\n', + type: 'Number', + optional: true + }, + { + name: 'bottom', + description: 'camera frustum bottom plane
\n', + type: 'Number', + optional: true + }, + { + name: 'top', + description: 'camera frustum top plane
\n', + type: 'Number', + optional: true + }, + { + name: 'near', + description: 'camera frustum near plane
\n', + type: 'Number', + optional: true + }, + { + name: 'far', + description: 'camera frustum far plane
\n', + type: 'Number', + optional: true + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + createCamera: { + name: 'createCamera', + class: 'p5', + module: 'Lights, Camera' + }, + setCamera: { + name: 'setCamera', + params: [ + { + name: 'cam', + description: 'p5.Camera object
\n', + type: 'p5.Camera' + } + ], + class: 'p5', + module: 'Lights, Camera' + }, + setAttributes: { + name: 'setAttributes', + class: 'p5', + module: 'Rendering', + overloads: [ + { + params: [ + { + name: 'key', + description: 'Name of attribute
\n', + type: 'String' + }, + { + name: 'value', + description: 'New value of named attribute
\n', + type: 'Boolean' + } + ] + }, + { + params: [ + { + name: 'obj', + description: 'object with key-value pairs
\n', + type: 'Object' + } + ] + } + ] + }, + sampleRate: { + name: 'sampleRate', + class: 'p5', + module: 'p5.sound' + }, + freqToMidi: { + name: 'freqToMidi', + params: [ + { + name: 'frequency', + description: + 'A freqeuncy, for example, the "A"\n above Middle C is 440Hz
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'p5.sound' + }, + midiToFreq: { + name: 'midiToFreq', + params: [ + { + name: 'midiNote', + description: 'The number of a MIDI note
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'p5.sound' + }, + soundFormats: { + name: 'soundFormats', + params: [ + { + name: 'formats', + description: "i.e. 'mp3', 'wav', 'ogg'
\n", + type: 'String', + optional: true, + multiple: true + } + ], + class: 'p5', + module: 'p5.sound' + }, + getAudioContext: { + name: 'getAudioContext', + class: 'p5', + module: 'p5.sound' + }, + userStartAudio: { + params: [ + { + name: 'element(s)', + description: + 'This argument can be an Element,\n Selector String, NodeList, p5.Element,\n jQuery Element, or an Array of any of those.
\n', + type: 'Element|Array', + optional: true + }, + { + name: 'callback', + description: + 'Callback to invoke when the AudioContext\n has started
\n', + type: 'Function', + optional: true + } + ], + name: 'userStartAudio', + class: 'p5', + module: 'p5.sound' + }, + loadSound: { + name: 'loadSound', + params: [ + { + name: 'path', + description: + "Path to the sound file, or an array with\n paths to soundfiles in multiple formats\n i.e. ['sound.ogg', 'sound.mp3'].\n Alternately, accepts an object: either\n from the HTML5 File API, or a p5.File.
\n", + type: 'String|Array' + }, + { + name: 'successCallback', + description: 'Name of a function to call once file loads
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'Name of a function to call if there is\n an error loading the file.
\n', + type: 'Function', + optional: true + }, + { + name: 'whileLoading', + description: + 'Name of a function to call while file is loading.\n This function will receive the percentage loaded\n so far, from 0.0 to 1.0.
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'p5.sound' + }, + createConvolver: { + name: 'createConvolver', + params: [ + { + name: 'path', + description: 'path to a sound file
\n', + type: 'String' + }, + { + name: 'callback', + description: + 'function to call if loading is successful.\n The object will be passed in as the argument\n to the callback function.
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'function to call if loading is not successful.\n A custom error will be passed in as the argument\n to the callback function.
\n', + type: 'Function', + optional: true + } + ], + class: 'p5', + module: 'p5.sound' + }, + setBPM: { + name: 'setBPM', + params: [ + { + name: 'BPM', + description: 'Beats Per Minute
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'Seconds from now
\n', + type: 'Number' + } + ], + class: 'p5', + module: 'p5.sound' + }, + saveSound: { + name: 'saveSound', + params: [ + { + name: 'soundFile', + description: 'p5.SoundFile that you wish to save
\n', + type: 'p5.SoundFile' + }, + { + name: 'fileName', + description: 'name of the resulting .wav file.
\n', + type: 'String' + } + ], + class: 'p5', + module: 'p5.sound' + } + }, + 'p5.Color': { + toString: { + name: 'toString', + params: [ + { + name: 'format', + description: + "How the color string will be formatted.\nLeaving this empty formats the string as rgba(r, g, b, a).\n'#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes.\n'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode.\n'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels.\n'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages.
\n", + type: 'String', + optional: true + } + ], + class: 'p5.Color', + module: 'Color' + }, + setRed: { + name: 'setRed', + params: [ + { + name: 'red', + description: 'the new red value
\n', + type: 'Number' + } + ], + class: 'p5.Color', + module: 'Color' + }, + setGreen: { + name: 'setGreen', + params: [ + { + name: 'green', + description: 'the new green value
\n', + type: 'Number' + } + ], + class: 'p5.Color', + module: 'Color' + }, + setBlue: { + name: 'setBlue', + params: [ + { + name: 'blue', + description: 'the new blue value
\n', + type: 'Number' + } + ], + class: 'p5.Color', + module: 'Color' + }, + setAlpha: { + name: 'setAlpha', + params: [ + { + name: 'alpha', + description: 'the new alpha value
\n', + type: 'Number' + } + ], + class: 'p5.Color', + module: 'Color' + } + }, + 'p5.Element': { + elt: { + name: 'elt', + class: 'p5.Element', + module: 'DOM' + }, + parent: { + name: 'parent', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'parent', + description: + 'the ID, DOM node, or p5.Element\n of desired parent element
\n', + type: 'String|p5.Element|Object' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + id: { + name: 'id', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'id', + description: 'ID of the element
\n', + type: 'String' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + class: { + name: 'class', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'class', + description: 'class to add
\n', + type: 'String' + } + ], + chainable: 1 + }, + { + params: [] + } + ] + }, + mousePressed: { + name: 'mousePressed', + params: [ + { + name: 'fxn', + description: + 'function to be fired when mouse is\n pressed over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when mouse is\n double clicked over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when mouse is\n scrolled over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when mouse is\n released over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when mouse is\n clicked over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a mouse moves\n over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a mouse moves\n onto the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a mouse\n moves off of an element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a touch\n starts over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a touch moves over\n the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a touch ends\n over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a file is\n dragged over the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
function to be fired when a file is\n dragged off the element.\n if false
is passed instead, the previously\n firing function will no longer fire.
name of class to add
\n', + type: 'String' + } + ], + class: 'p5.Element', + module: 'DOM' + }, + removeClass: { + name: 'removeClass', + params: [ + { + name: 'class', + description: 'name of class to remove
\n', + type: 'String' + } + ], + class: 'p5.Element', + module: 'DOM' + }, + hasClass: { + name: 'hasClass', + params: [ + { + name: 'c', + description: 'class name of class to check
\n', + type: 'String' + } + ], + class: 'p5.Element', + module: 'DOM' + }, + toggleClass: { + name: 'toggleClass', + params: [ + { + name: 'c', + description: 'class name to toggle
\n', + type: 'String' + } + ], + class: 'p5.Element', + module: 'DOM' + }, + child: { + name: 'child', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'child', + description: + 'the ID, DOM node, or p5.Element\n to add to the current element
\n', + type: 'String|p5.Element', + optional: true + } + ], + chainable: 1 + } + ] + }, + center: { + name: 'center', + params: [ + { + name: 'align', + description: + "passing 'vertical', 'horizontal' aligns element accordingly
\n", + type: 'String', + optional: true + } + ], + class: 'p5.Element', + module: 'DOM' + }, + html: { + name: 'html', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'html', + description: 'the HTML to be placed inside the element
\n', + type: 'String', + optional: true + }, + { + name: 'append', + description: 'whether to append HTML to existing
\n', + type: 'Boolean', + optional: true + } + ], + chainable: 1 + } + ] + }, + position: { + name: 'position', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'x', + description: + 'x-position relative to upper left of window (optional)
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: + 'y-position relative to upper left of window (optional)
\n', + type: 'Number', + optional: true + }, + { + name: 'positionType', + description: + 'it can be static, fixed, relative, sticky, initial or inherit (optional)
\n', + type: 'String' + } + ], + chainable: 1 + } + ] + }, + style: { + name: 'style', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [ + { + name: 'property', + description: 'property to be set
\n', + type: 'String' + } + ] + }, + { + params: [ + { + name: 'property', + description: '', + type: 'String' + }, + { + name: 'value', + description: 'value to assign to property
\n', + type: 'String|p5.Color' + } + ], + chainable: 1 + } + ] + }, + attribute: { + name: 'attribute', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'attr', + description: 'attribute to set
\n', + type: 'String' + }, + { + name: 'value', + description: 'value to assign to attribute
\n', + type: 'String' + } + ], + chainable: 1 + } + ] + }, + removeAttribute: { + name: 'removeAttribute', + params: [ + { + name: 'attr', + description: 'attribute to remove
\n', + type: 'String' + } + ], + class: 'p5.Element', + module: 'DOM' + }, + value: { + name: 'value', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'value', + description: '', + type: 'String|Number' + } + ], + chainable: 1 + } + ] + }, + show: { + name: 'show', + class: 'p5.Element', + module: 'DOM' + }, + hide: { + name: 'hide', + class: 'p5.Element', + module: 'DOM' + }, + size: { + name: 'size', + class: 'p5.Element', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'w', + description: + 'width of the element, either AUTO, or a number
\n', + type: 'Number|Constant' + }, + { + name: 'h', + description: + 'height of the element, either AUTO, or a number
\n', + type: 'Number|Constant', + optional: true + } + ], + chainable: 1 + } + ] + }, + remove: { + name: 'remove', + class: 'p5.Element', + module: 'DOM' + }, + drop: { + name: 'drop', + params: [ + { + name: 'callback', + description: + 'callback to receive loaded file, called for each file dropped.
\n', + type: 'Function' + }, + { + name: 'fxn', + description: + 'callback triggered once when files are dropped with the drop event.
\n', + type: 'Function', + optional: true + } + ], + class: 'p5.Element', + module: 'DOM' + } + }, + 'p5.Graphics': { + reset: { + name: 'reset', + class: 'p5.Graphics', + module: 'Rendering' + }, + remove: { + name: 'remove', + class: 'p5.Graphics', + module: 'Rendering' + } + }, + JSON: { + stringify: { + name: 'stringify', + params: [ + { + name: 'object', + description: + ':Javascript object that you would like to convert to JSON
\n', + type: 'Object' + } + ], + class: 'JSON', + module: 'Foundation' + } + }, + console: { + log: { + name: 'log', + params: [ + { + name: 'message', + description: + ':Message that you would like to print to the console
\n', + type: 'String|Expression|Object' + } + ], + class: 'console', + module: 'Foundation' + } + }, + 'p5.TypedDict': { + size: { + name: 'size', + class: 'p5.TypedDict', + module: 'Data' + }, + hasKey: { + name: 'hasKey', + params: [ + { + name: 'key', + description: 'that you want to look up
\n', + type: 'Number|String' + } + ], + class: 'p5.TypedDict', + module: 'Data' + }, + get: { + name: 'get', + params: [ + { + name: 'the', + description: 'key you want to access
\n', + type: 'Number|String' + } + ], + class: 'p5.TypedDict', + module: 'Data' + }, + set: { + name: 'set', + params: [ + { + name: 'key', + description: '', + type: 'Number|String' + }, + { + name: 'value', + description: '', + type: 'Number|String' + } + ], + class: 'p5.TypedDict', + module: 'Data' + }, + create: { + name: 'create', + class: 'p5.TypedDict', + module: 'Data', + overloads: [ + { + params: [ + { + name: 'key', + description: '', + type: 'Number|String' + }, + { + name: 'value', + description: '', + type: 'Number|String' + } + ] + }, + { + params: [ + { + name: 'obj', + description: 'key/value pair
\n', + type: 'Object' + } + ] + } + ] + }, + clear: { + name: 'clear', + class: 'p5.TypedDict', + module: 'Data' + }, + remove: { + name: 'remove', + params: [ + { + name: 'key', + description: 'for the pair to remove
\n', + type: 'Number|String' + } + ], + class: 'p5.TypedDict', + module: 'Data' + }, + print: { + name: 'print', + class: 'p5.TypedDict', + module: 'Data' + }, + saveTable: { + name: 'saveTable', + class: 'p5.TypedDict', + module: 'Data' + }, + saveJSON: { + name: 'saveJSON', + class: 'p5.TypedDict', + module: 'Data' + } + }, + 'p5.NumberDict': { + add: { + name: 'add', + params: [ + { + name: 'Key', + description: 'for the value you wish to add to
\n', + type: 'Number' + }, + { + name: 'Number', + description: 'to add to the value
\n', + type: 'Number' + } + ], + class: 'p5.NumberDict', + module: 'Data' + }, + sub: { + name: 'sub', + params: [ + { + name: 'Key', + description: 'for the value you wish to subtract from
\n', + type: 'Number' + }, + { + name: 'Number', + description: 'to subtract from the value
\n', + type: 'Number' + } + ], + class: 'p5.NumberDict', + module: 'Data' + }, + mult: { + name: 'mult', + params: [ + { + name: 'Key', + description: 'for value you wish to multiply
\n', + type: 'Number' + }, + { + name: 'Amount', + description: 'to multiply the value by
\n', + type: 'Number' + } + ], + class: 'p5.NumberDict', + module: 'Data' + }, + div: { + name: 'div', + params: [ + { + name: 'Key', + description: 'for value you wish to divide
\n', + type: 'Number' + }, + { + name: 'Amount', + description: 'to divide the value by
\n', + type: 'Number' + } + ], + class: 'p5.NumberDict', + module: 'Data' + }, + minValue: { + name: 'minValue', + class: 'p5.NumberDict', + module: 'Data' + }, + maxValue: { + name: 'maxValue', + class: 'p5.NumberDict', + module: 'Data' + }, + minKey: { + name: 'minKey', + class: 'p5.NumberDict', + module: 'Data' + }, + maxKey: { + name: 'maxKey', + class: 'p5.NumberDict', + module: 'Data' + } + }, + 'p5.MediaElement': { + src: { + name: 'src', + class: 'p5.MediaElement', + module: 'DOM' + }, + play: { + name: 'play', + class: 'p5.MediaElement', + module: 'DOM' + }, + stop: { + name: 'stop', + class: 'p5.MediaElement', + module: 'DOM' + }, + pause: { + name: 'pause', + class: 'p5.MediaElement', + module: 'DOM' + }, + loop: { + name: 'loop', + class: 'p5.MediaElement', + module: 'DOM' + }, + noLoop: { + name: 'noLoop', + class: 'p5.MediaElement', + module: 'DOM' + }, + autoplay: { + name: 'autoplay', + params: [ + { + name: 'shouldAutoplay', + description: 'whether the element should autoplay
\n', + type: 'Boolean' + } + ], + class: 'p5.MediaElement', + module: 'DOM' + }, + volume: { + name: 'volume', + class: 'p5.MediaElement', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'val', + description: 'volume between 0.0 and 1.0
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + speed: { + name: 'speed', + class: 'p5.MediaElement', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'speed', + description: 'speed multiplier for element playback
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + time: { + name: 'time', + class: 'p5.MediaElement', + module: 'DOM', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'time', + description: 'time to jump to (in seconds)
\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + duration: { + name: 'duration', + class: 'p5.MediaElement', + module: 'DOM' + }, + onended: { + name: 'onended', + params: [ + { + name: 'callback', + description: + 'function to call when the\n soundfile has ended. The\n media element will be passed\n in as the argument to the\n callback.
\n', + type: 'Function' + } + ], + class: 'p5.MediaElement', + module: 'DOM' + }, + connect: { + name: 'connect', + params: [ + { + name: 'audioNode', + description: + 'AudioNode from the Web Audio API,\nor an object from the p5.sound library
\n', + type: 'AudioNode|Object' + } + ], + class: 'p5.MediaElement', + module: 'DOM' + }, + disconnect: { + name: 'disconnect', + class: 'p5.MediaElement', + module: 'DOM' + }, + showControls: { + name: 'showControls', + class: 'p5.MediaElement', + module: 'DOM' + }, + hideControls: { + name: 'hideControls', + class: 'p5.MediaElement', + module: 'DOM' + }, + addCue: { + name: 'addCue', + params: [ + { + name: 'time', + description: + "Time in seconds, relative to this media\n element's playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.
\n", + type: 'Number' + }, + { + name: 'callback', + description: + 'Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.
\n', + type: 'Function' + }, + { + name: 'value', + description: + 'An object to be passed as the\n second parameter to the\n callback function.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.MediaElement', + module: 'DOM' + }, + removeCue: { + name: 'removeCue', + params: [ + { + name: 'id', + description: 'ID of the cue, as returned by addCue
\n', + type: 'Number' + } + ], + class: 'p5.MediaElement', + module: 'DOM' + }, + clearCues: { + name: 'clearCues', + params: [ + { + name: 'id', + description: 'ID of the cue, as returned by addCue
\n', + type: 'Number' + } + ], + class: 'p5.MediaElement', + module: 'DOM' + } + }, + 'p5.File': { + file: { + name: 'file', + class: 'p5.File', + module: 'DOM' + }, + type: { + name: 'type', + class: 'p5.File', + module: 'DOM' + }, + subtype: { + name: 'subtype', + class: 'p5.File', + module: 'DOM' + }, + name: { + name: 'name', + class: 'p5.File', + module: 'DOM' + }, + size: { + name: 'size', + class: 'p5.File', + module: 'DOM' + }, + data: { + name: 'data', + class: 'p5.File', + module: 'DOM' + } + }, + 'p5.Image': { + width: { + name: 'width', + class: 'p5.Image', + module: 'Image' + }, + height: { + name: 'height', + class: 'p5.Image', + module: 'Image' + }, + pixels: { + name: 'pixels', + class: 'p5.Image', + module: 'Image' + }, + loadPixels: { + name: 'loadPixels', + class: 'p5.Image', + module: 'Image' + }, + updatePixels: { + name: 'updatePixels', + class: 'p5.Image', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'x', + description: + 'x-offset of the target update area for the\n underlying canvas
\n', + type: 'Integer' + }, + { + name: 'y', + description: + 'y-offset of the target update area for the\n underlying canvas
\n', + type: 'Integer' + }, + { + name: 'w', + description: + 'height of the target update area for the\n underlying canvas
\n', + type: 'Integer' + }, + { + name: 'h', + description: + 'height of the target update area for the\n underlying canvas
\n', + type: 'Integer' + } + ] + }, + { + params: [] + } + ] + }, + get: { + name: 'get', + class: 'p5.Image', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'w', + description: 'width
\n', + type: 'Number' + }, + { + name: 'h', + description: 'height
\n', + type: 'Number' + } + ] + }, + { + params: [] + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + } + ] + } + ] + }, + set: { + name: 'set', + params: [ + { + name: 'x', + description: 'x-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-coordinate of the pixel
\n', + type: 'Number' + }, + { + name: 'a', + description: + 'grayscale value | pixel array |\n a p5.Color | image to copy
\n', + type: 'Number|Number[]|Object' + } + ], + class: 'p5.Image', + module: 'Image' + }, + resize: { + name: 'resize', + params: [ + { + name: 'width', + description: 'the resized image width
\n', + type: 'Number' + }, + { + name: 'height', + description: 'the resized image height
\n', + type: 'Number' + } + ], + class: 'p5.Image', + module: 'Image' + }, + copy: { + name: 'copy', + class: 'p5.Image', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'srcImage', + description: 'source image
\n', + type: 'p5.Image|p5.Element' + }, + { + name: 'sx', + description: + "X coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sy', + description: + "Y coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sw', + description: 'source image width
\n', + type: 'Integer' + }, + { + name: 'sh', + description: 'source image height
\n', + type: 'Integer' + }, + { + name: 'dx', + description: + "X coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dy', + description: + "Y coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dw', + description: 'destination image width
\n', + type: 'Integer' + }, + { + name: 'dh', + description: 'destination image height
\n', + type: 'Integer' + } + ] + }, + { + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + } + ] + } + ] + }, + mask: { + name: 'mask', + params: [ + { + name: 'srcImage', + description: 'source image
\n', + type: 'p5.Image' + } + ], + class: 'p5.Image', + module: 'Image' + }, + filter: { + name: 'filter', + params: [ + { + name: 'filterType', + description: + 'either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter
\n', + type: 'Constant' + }, + { + name: 'filterParam', + description: + 'an optional parameter unique\n to each filter, see above
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Image', + module: 'Image' + }, + blend: { + name: 'blend', + class: 'p5.Image', + module: 'Image', + overloads: [ + { + params: [ + { + name: 'srcImage', + description: 'source image
\n', + type: 'p5.Image' + }, + { + name: 'sx', + description: + "X coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sy', + description: + "Y coordinate of the source's upper left corner
\n", + type: 'Integer' + }, + { + name: 'sw', + description: 'source image width
\n', + type: 'Integer' + }, + { + name: 'sh', + description: 'source image height
\n', + type: 'Integer' + }, + { + name: 'dx', + description: + "X coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dy', + description: + "Y coordinate of the destination's upper left corner
\n", + type: 'Integer' + }, + { + name: 'dw', + description: 'destination image width
\n', + type: 'Integer' + }, + { + name: 'dh', + description: 'destination image height
\n', + type: 'Integer' + }, + { + name: 'blendMode', + description: + 'the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.
\nAvailable blend modes are: normal | multiply | screen | overlay |\n darken | lighten | color-dodge | color-burn | hard-light |\n soft-light | difference | exclusion | hue | saturation |\n color | luminosity
\nhttp://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/
\n', + type: 'Constant' + } + ] + }, + { + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + }, + { + name: 'blendMode', + description: '', + type: 'Constant' + } + ] + } + ] + }, + save: { + name: 'save', + params: [ + { + name: 'filename', + description: 'give your file a name
\n', + type: 'String' + }, + { + name: 'extension', + description: "'png' or 'jpg'
\n", + type: 'String' + } + ], + class: 'p5.Image', + module: 'Image' + }, + reset: { + name: 'reset', + class: 'p5.Image', + module: 'Image' + }, + getCurrentFrame: { + name: 'getCurrentFrame', + class: 'p5.Image', + module: 'Image' + }, + setFrame: { + name: 'setFrame', + params: [ + { + name: 'index', + description: + 'the index for the frame that should be displayed
\n', + type: 'Number' + } + ], + class: 'p5.Image', + module: 'Image' + }, + numFrames: { + name: 'numFrames', + class: 'p5.Image', + module: 'Image' + }, + play: { + name: 'play', + class: 'p5.Image', + module: 'Image' + }, + pause: { + name: 'pause', + class: 'p5.Image', + module: 'Image' + }, + delay: { + name: 'delay', + params: [ + { + name: 'd', + description: + 'the amount in milliseconds to delay between switching frames
\n', + type: 'Number' + }, + { + name: 'index', + description: + 'the index of the frame that should have the new delay value {optional}
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Image', + module: 'Image' + } + }, + 'p5.PrintWriter': { + write: { + name: 'write', + params: [ + { + name: 'data', + description: 'all data to be written by the PrintWriter
\n', + type: 'Array' + } + ], + class: 'p5.PrintWriter', + module: 'IO' + }, + print: { + name: 'print', + params: [ + { + name: 'data', + description: 'all data to be printed by the PrintWriter
\n', + type: 'Array' + } + ], + class: 'p5.PrintWriter', + module: 'IO' + }, + clear: { + name: 'clear', + class: 'p5.PrintWriter', + module: 'IO' + }, + close: { + name: 'close', + class: 'p5.PrintWriter', + module: 'IO' + } + }, + 'p5.Table': { + columns: { + name: 'columns', + class: 'p5.Table', + module: 'IO' + }, + rows: { + name: 'rows', + class: 'p5.Table', + module: 'IO' + }, + addRow: { + name: 'addRow', + params: [ + { + name: 'row', + description: 'row to be added to the table
\n', + type: 'p5.TableRow', + optional: true + } + ], + class: 'p5.Table', + module: 'IO' + }, + removeRow: { + name: 'removeRow', + params: [ + { + name: 'id', + description: 'ID number of the row to remove
\n', + type: 'Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + getRow: { + name: 'getRow', + params: [ + { + name: 'rowID', + description: 'ID number of the row to get
\n', + type: 'Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + getRows: { + name: 'getRows', + class: 'p5.Table', + module: 'IO' + }, + findRow: { + name: 'findRow', + params: [ + { + name: 'value', + description: 'The value to match
\n', + type: 'String' + }, + { + name: 'column', + description: + 'ID number or title of the\n column to search
\n', + type: 'Integer|String' + } + ], + class: 'p5.Table', + module: 'IO' + }, + findRows: { + name: 'findRows', + params: [ + { + name: 'value', + description: 'The value to match
\n', + type: 'String' + }, + { + name: 'column', + description: + 'ID number or title of the\n column to search
\n', + type: 'Integer|String' + } + ], + class: 'p5.Table', + module: 'IO' + }, + matchRow: { + name: 'matchRow', + params: [ + { + name: 'regexp', + description: 'The regular expression to match
\n', + type: 'String|RegExp' + }, + { + name: 'column', + description: + 'The column ID (number) or\n title (string)
\n', + type: 'String|Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + matchRows: { + name: 'matchRows', + params: [ + { + name: 'regexp', + description: 'The regular expression to match
\n', + type: 'String' + }, + { + name: 'column', + description: + 'The column ID (number) or\n title (string)
\n', + type: 'String|Integer', + optional: true + } + ], + class: 'p5.Table', + module: 'IO' + }, + getColumn: { + name: 'getColumn', + params: [ + { + name: 'column', + description: 'String or Number of the column to return
\n', + type: 'String|Number' + } + ], + class: 'p5.Table', + module: 'IO' + }, + clearRows: { + name: 'clearRows', + class: 'p5.Table', + module: 'IO' + }, + addColumn: { + name: 'addColumn', + params: [ + { + name: 'title', + description: 'title of the given column
\n', + type: 'String', + optional: true + } + ], + class: 'p5.Table', + module: 'IO' + }, + getColumnCount: { + name: 'getColumnCount', + class: 'p5.Table', + module: 'IO' + }, + getRowCount: { + name: 'getRowCount', + class: 'p5.Table', + module: 'IO' + }, + removeTokens: { + name: 'removeTokens', + params: [ + { + name: 'chars', + description: 'String listing characters to be removed
\n', + type: 'String' + }, + { + name: 'column', + description: + 'Column ID (number)\n or name (string)
\n', + type: 'String|Integer', + optional: true + } + ], + class: 'p5.Table', + module: 'IO' + }, + trim: { + name: 'trim', + params: [ + { + name: 'column', + description: + 'Column ID (number)\n or name (string)
\n', + type: 'String|Integer', + optional: true + } + ], + class: 'p5.Table', + module: 'IO' + }, + removeColumn: { + name: 'removeColumn', + params: [ + { + name: 'column', + description: 'columnName (string) or ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + set: { + name: 'set', + params: [ + { + name: 'row', + description: 'row ID
\n', + type: 'Integer' + }, + { + name: 'column', + description: + 'column ID (Number)\n or title (String)
\n', + type: 'String|Integer' + }, + { + name: 'value', + description: 'value to assign
\n', + type: 'String|Number' + } + ], + class: 'p5.Table', + module: 'IO' + }, + setNum: { + name: 'setNum', + params: [ + { + name: 'row', + description: 'row ID
\n', + type: 'Integer' + }, + { + name: 'column', + description: + 'column ID (Number)\n or title (String)
\n', + type: 'String|Integer' + }, + { + name: 'value', + description: 'value to assign
\n', + type: 'Number' + } + ], + class: 'p5.Table', + module: 'IO' + }, + setString: { + name: 'setString', + params: [ + { + name: 'row', + description: 'row ID
\n', + type: 'Integer' + }, + { + name: 'column', + description: + 'column ID (Number)\n or title (String)
\n', + type: 'String|Integer' + }, + { + name: 'value', + description: 'value to assign
\n', + type: 'String' + } + ], + class: 'p5.Table', + module: 'IO' + }, + get: { + name: 'get', + params: [ + { + name: 'row', + description: 'row ID
\n', + type: 'Integer' + }, + { + name: 'column', + description: + 'columnName (string) or\n ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + getNum: { + name: 'getNum', + params: [ + { + name: 'row', + description: 'row ID
\n', + type: 'Integer' + }, + { + name: 'column', + description: + 'columnName (string) or\n ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + getString: { + name: 'getString', + params: [ + { + name: 'row', + description: 'row ID
\n', + type: 'Integer' + }, + { + name: 'column', + description: + 'columnName (string) or\n ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.Table', + module: 'IO' + }, + getObject: { + name: 'getObject', + params: [ + { + name: 'headerColumn', + description: + 'Name of the column which should be used to\n title each row object (optional)
\n', + type: 'String', + optional: true + } + ], + class: 'p5.Table', + module: 'IO' + }, + getArray: { + name: 'getArray', + class: 'p5.Table', + module: 'IO' + } + }, + 'p5.TableRow': { + set: { + name: 'set', + params: [ + { + name: 'column', + description: + 'Column ID (Number)\n or Title (String)
\n', + type: 'String|Integer' + }, + { + name: 'value', + description: 'The value to be stored
\n', + type: 'String|Number' + } + ], + class: 'p5.TableRow', + module: 'IO' + }, + setNum: { + name: 'setNum', + params: [ + { + name: 'column', + description: + 'Column ID (Number)\n or Title (String)
\n', + type: 'String|Integer' + }, + { + name: 'value', + description: + 'The value to be stored\n as a Float
\n', + type: 'Number|String' + } + ], + class: 'p5.TableRow', + module: 'IO' + }, + setString: { + name: 'setString', + params: [ + { + name: 'column', + description: + 'Column ID (Number)\n or Title (String)
\n', + type: 'String|Integer' + }, + { + name: 'value', + description: + 'The value to be stored\n as a String
\n', + type: 'String|Number|Boolean|Object' + } + ], + class: 'p5.TableRow', + module: 'IO' + }, + get: { + name: 'get', + params: [ + { + name: 'column', + description: + 'columnName (string) or\n ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.TableRow', + module: 'IO' + }, + getNum: { + name: 'getNum', + params: [ + { + name: 'column', + description: + 'columnName (string) or\n ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.TableRow', + module: 'IO' + }, + getString: { + name: 'getString', + params: [ + { + name: 'column', + description: + 'columnName (string) or\n ID (number)
\n', + type: 'String|Integer' + } + ], + class: 'p5.TableRow', + module: 'IO' + } + }, + 'p5.XML': { + getParent: { + name: 'getParent', + class: 'p5.XML', + module: 'IO' + }, + getName: { + name: 'getName', + class: 'p5.XML', + module: 'IO' + }, + setName: { + name: 'setName', + params: [ + { + name: 'the', + description: 'new name of the node
\n', + type: 'String' + } + ], + class: 'p5.XML', + module: 'IO' + }, + hasChildren: { + name: 'hasChildren', + class: 'p5.XML', + module: 'IO' + }, + listChildren: { + name: 'listChildren', + class: 'p5.XML', + module: 'IO' + }, + getChildren: { + name: 'getChildren', + params: [ + { + name: 'name', + description: 'element name
\n', + type: 'String', + optional: true + } + ], + class: 'p5.XML', + module: 'IO' + }, + getChild: { + name: 'getChild', + params: [ + { + name: 'name', + description: 'element name or index
\n', + type: 'String|Integer' + } + ], + class: 'p5.XML', + module: 'IO' + }, + addChild: { + name: 'addChild', + params: [ + { + name: 'node', + description: + 'a p5.XML Object which will be the child to be added
\n', + type: 'p5.XML' + } + ], + class: 'p5.XML', + module: 'IO' + }, + removeChild: { + name: 'removeChild', + params: [ + { + name: 'name', + description: 'element name or index
\n', + type: 'String|Integer' + } + ], + class: 'p5.XML', + module: 'IO' + }, + getAttributeCount: { + name: 'getAttributeCount', + class: 'p5.XML', + module: 'IO' + }, + listAttributes: { + name: 'listAttributes', + class: 'p5.XML', + module: 'IO' + }, + hasAttribute: { + name: 'hasAttribute', + params: [ + { + name: 'the', + description: 'attribute to be checked
\n', + type: 'String' + } + ], + class: 'p5.XML', + module: 'IO' + }, + getNum: { + name: 'getNum', + params: [ + { + name: 'name', + description: 'the non-null full name of the attribute
\n', + type: 'String' + }, + { + name: 'defaultValue', + description: 'the default value of the attribute
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.XML', + module: 'IO' + }, + getString: { + name: 'getString', + params: [ + { + name: 'name', + description: 'the non-null full name of the attribute
\n', + type: 'String' + }, + { + name: 'defaultValue', + description: 'the default value of the attribute
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.XML', + module: 'IO' + }, + setAttribute: { + name: 'setAttribute', + params: [ + { + name: 'name', + description: 'the full name of the attribute
\n', + type: 'String' + }, + { + name: 'value', + description: 'the value of the attribute
\n', + type: 'Number|String|Boolean' + } + ], + class: 'p5.XML', + module: 'IO' + }, + getContent: { + name: 'getContent', + params: [ + { + name: 'defaultValue', + description: 'value returned if no content is found
\n', + type: 'String', + optional: true + } + ], + class: 'p5.XML', + module: 'IO' + }, + setContent: { + name: 'setContent', + params: [ + { + name: 'text', + description: 'the new content
\n', + type: 'String' + } + ], + class: 'p5.XML', + module: 'IO' + }, + serialize: { + name: 'serialize', + class: 'p5.XML', + module: 'IO' + } + }, + 'p5.Vector': { + x: { + name: 'x', + class: 'p5.Vector', + module: 'Math' + }, + y: { + name: 'y', + class: 'p5.Vector', + module: 'Math' + }, + z: { + name: 'z', + class: 'p5.Vector', + module: 'Math' + }, + toString: { + name: 'toString', + class: 'p5.Vector', + module: 'Math' + }, + set: { + name: 'set', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: 'the y component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'the z component of the vector
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'the vector to set
\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + } + ] + }, + copy: { + name: 'copy', + class: 'p5.Vector', + module: 'Math' + }, + add: { + name: 'add', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x component of the vector to be added
\n', + type: 'Number' + }, + { + name: 'y', + description: 'the y component of the vector to be added
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'the z component of the vector to be added
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'the vector to add
\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: + 'a p5.Vector to add
\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + 'a p5.Vector to add
\n', + type: 'p5.Vector' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + rem: { + name: 'rem', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x component of divisor vector
\n', + type: 'Number' + }, + { + name: 'y', + description: 'the y component of divisor vector
\n', + type: 'Number' + }, + { + name: 'z', + description: 'the z component of divisor vector
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'divisor vector
\n', + type: 'p5.Vector | Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: + 'dividend p5.Vector
\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: 'divisor p5.Vector
\n', + type: 'p5.Vector' + } + ], + static: 1 + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'v2', + description: '', + type: 'p5.Vector' + } + ], + static: 1 + } + ] + }, + sub: { + name: 'sub', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x component of the vector to subtract
\n', + type: 'Number' + }, + { + name: 'y', + description: 'the y component of the vector to subtract
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'the z component of the vector to subtract
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'value', + description: 'the vector to subtract
\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: + 'a p5.Vector to subtract from
\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + 'a p5.Vector to subtract
\n', + type: 'p5.Vector' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + mult: { + name: 'mult', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'n', + description: 'The number to multiply with the vector
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: + 'The number to multiply with the x component of the vector
\n', + type: 'Number' + }, + { + name: 'y', + description: + 'The number to multiply with the y component of the vector
\n', + type: 'Number' + }, + { + name: 'z', + description: + 'The number to multiply with the z component of the vector
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'arr', + description: + 'The array to multiply with the components of the vector
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v', + description: + 'The vector to multiply with the components of the original vector
\n', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number', + optional: true + } + ], + static: 1 + }, + { + params: [ + { + name: 'v', + description: '', + type: 'p5.Vector' + }, + { + name: 'n', + description: '', + type: 'Number' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + }, + { + params: [ + { + name: 'v0', + description: '', + type: 'p5.Vector' + }, + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'target', + description: '', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + }, + { + params: [ + { + name: 'v0', + description: '', + type: 'p5.Vector' + }, + { + name: 'arr', + description: '', + type: 'Number[]' + }, + { + name: 'target', + description: '', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + div: { + name: 'div', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'n', + description: 'The number to divide the vector by
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: + 'The number to divide with the x component of the vector
\n', + type: 'Number' + }, + { + name: 'y', + description: + 'The number to divide with the y component of the vector
\n', + type: 'Number' + }, + { + name: 'z', + description: + 'The number to divide with the z component of the vector
\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'arr', + description: + 'The array to divide the components of the vector by
\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v', + description: + 'The vector to divide the components of the original vector by
\n', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number', + optional: true + } + ], + static: 1 + }, + { + params: [ + { + name: 'v', + description: '', + type: 'p5.Vector' + }, + { + name: 'n', + description: '', + type: 'Number' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + }, + { + params: [ + { + name: 'v0', + description: '', + type: 'p5.Vector' + }, + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'target', + description: '', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + }, + { + params: [ + { + name: 'v0', + description: '', + type: 'p5.Vector' + }, + { + name: 'arr', + description: '', + type: 'Number[]' + }, + { + name: 'target', + description: '', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + mag: { + name: 'mag', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'vecT', + description: 'the vector to return the magnitude of
\n', + type: 'p5.Vector' + } + ], + static: 1 + } + ] + }, + magSq: { + name: 'magSq', + class: 'p5.Vector', + module: 'Math' + }, + dot: { + name: 'dot', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'x component of the vector
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'z component of the vector
\n', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'value', + description: + 'value component of the vector or a p5.Vector
\n', + type: 'p5.Vector' + } + ] + }, + { + params: [ + { + name: 'v1', + description: + 'the first p5.Vector
\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + 'the second p5.Vector
\n', + type: 'p5.Vector' + } + ], + static: 1 + } + ] + }, + cross: { + name: 'cross', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'v', + description: + 'p5.Vector to be crossed
\n', + type: 'p5.Vector' + } + ] + }, + { + params: [ + { + name: 'v1', + description: + 'the first p5.Vector
\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + 'the second p5.Vector
\n', + type: 'p5.Vector' + } + ], + static: 1 + } + ] + }, + dist: { + name: 'dist', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'v', + description: + 'the x, y, and z coordinates of a p5.Vector
\n', + type: 'p5.Vector' + } + ] + }, + { + params: [ + { + name: 'v1', + description: + 'the first p5.Vector
\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + 'the second p5.Vector
\n', + type: 'p5.Vector' + } + ], + static: 1 + } + ] + }, + normalize: { + name: 'normalize', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [] + }, + { + params: [ + { + name: 'v', + description: 'the vector to normalize
\n', + type: 'p5.Vector' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + limit: { + name: 'limit', + params: [ + { + name: 'max', + description: 'the maximum magnitude for the vector
\n', + type: 'Number' + } + ], + class: 'p5.Vector', + module: 'Math' + }, + setMag: { + name: 'setMag', + params: [ + { + name: 'len', + description: 'the new length for this vector
\n', + type: 'Number' + } + ], + class: 'p5.Vector', + module: 'Math' + }, + heading: { + name: 'heading', + class: 'p5.Vector', + module: 'Math' + }, + setHeading: { + name: 'setHeading', + params: [ + { + name: 'angle', + description: 'the angle of rotation
\n', + type: 'Number' + } + ], + class: 'p5.Vector', + module: 'Math' + }, + rotate: { + name: 'rotate', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'angle', + description: 'the angle of rotation
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v', + description: '', + type: 'p5.Vector' + }, + { + name: 'angle', + description: '', + type: 'Number' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + angleBetween: { + name: 'angleBetween', + params: [ + { + name: 'value', + description: + 'the x, y, and z components of a p5.Vector
\n', + type: 'p5.Vector' + } + ], + class: 'p5.Vector', + module: 'Math' + }, + lerp: { + name: 'lerp', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x component
\n', + type: 'Number' + }, + { + name: 'y', + description: 'the y component
\n', + type: 'Number' + }, + { + name: 'z', + description: 'the z component
\n', + type: 'Number' + }, + { + name: 'amt', + description: + 'the amount of interpolation; some value between 0.0\n (old vector) and 1.0 (new vector). 0.9 is very near\n the new vector. 0.5 is halfway in between.
\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v', + description: + 'the p5.Vector to lerp to
\n', + type: 'p5.Vector' + }, + { + name: 'amt', + description: '', + type: 'Number' + } + ], + chainable: 1 + }, + { + params: [ + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'v2', + description: '', + type: 'p5.Vector' + }, + { + name: 'amt', + description: '', + type: 'Number' + }, + { + name: 'target', + description: 'the vector to receive the result (Optional)
\n', + type: 'p5.Vector', + optional: true + } + ], + static: 1 + } + ] + }, + reflect: { + name: 'reflect', + params: [ + { + name: 'surfaceNormal', + description: + 'the p5.Vector to reflect about, will be normalized by this method
\n', + type: 'p5.Vector' + } + ], + class: 'p5.Vector', + module: 'Math' + }, + array: { + name: 'array', + class: 'p5.Vector', + module: 'Math' + }, + equals: { + name: 'equals', + class: 'p5.Vector', + module: 'Math', + overloads: [ + { + params: [ + { + name: 'x', + description: 'the x component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: 'the y component of the vector
\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: 'the z component of the vector
\n', + type: 'Number', + optional: true + } + ] + }, + { + params: [ + { + name: 'value', + description: 'the vector to compare
\n', + type: 'p5.Vector|Array' + } + ] + } + ] + }, + fromAngle: { + name: 'fromAngle', + params: [ + { + name: 'angle', + description: + 'the desired angle, in radians (unaffected by angleMode)
\n', + type: 'Number' + }, + { + name: 'length', + description: 'the length of the new vector (defaults to 1)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Vector', + module: 'Math' + }, + fromAngles: { + name: 'fromAngles', + params: [ + { + name: 'theta', + description: 'the polar angle, in radians (zero is up)
\n', + type: 'Number' + }, + { + name: 'phi', + description: + 'the azimuthal angle, in radians\n (zero is out of the screen)
\n', + type: 'Number' + }, + { + name: 'length', + description: 'the length of the new vector (defaults to 1)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Vector', + module: 'Math' + }, + random2D: { + name: 'random2D', + class: 'p5.Vector', + module: 'Math' + }, + random3D: { + name: 'random3D', + class: 'p5.Vector', + module: 'Math' + } + }, + 'p5.Font': { + font: { + name: 'font', + class: 'p5.Font', + module: 'Typography' + }, + textBounds: { + name: 'textBounds', + params: [ + { + name: 'line', + description: 'a line of text
\n', + type: 'String' + }, + { + name: 'x', + description: 'x-position
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-position
\n', + type: 'Number' + }, + { + name: 'fontSize', + description: 'font size to use (optional) Default is 12.
\n', + type: 'Number', + optional: true + }, + { + name: 'options', + description: + "opentype options (optional)\n opentype fonts contains alignment and baseline options.\n Default is 'LEFT' and 'alphabetic'
\n", + type: 'Object', + optional: true + } + ], + class: 'p5.Font', + module: 'Typography' + }, + textToPoints: { + name: 'textToPoints', + params: [ + { + name: 'txt', + description: 'a line of text
\n', + type: 'String' + }, + { + name: 'x', + description: 'x-position
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y-position
\n', + type: 'Number' + }, + { + name: 'fontSize', + description: 'font size to use (optional)
\n', + type: 'Number' + }, + { + name: 'options', + description: + 'an (optional) object that can contain:
\n
sampleFactor - the ratio of path-length to number of samples\n(default=.1); higher values yield more points and are therefore\nmore precise
simplifyThreshold - if set to a non-zero value, collinear points will be\nbe removed from the polygon; the value represents the threshold angle to use\nwhen determining whether two edges are collinear
amount to rotate camera in current\nangleMode units.\nGreater than 0 values rotate counterclockwise (to the left).
\n', + type: 'Number' + } + ], + class: 'p5.Camera', + module: 'Lights, Camera' + }, + tilt: { + name: 'tilt', + params: [ + { + name: 'angle', + description: + 'amount to rotate camera in current\nangleMode units.\nGreater than 0 values rotate counterclockwise (to the left).
\n', + type: 'Number' + } + ], + class: 'p5.Camera', + module: 'Lights, Camera' + }, + lookAt: { + name: 'lookAt', + params: [ + { + name: 'x', + description: 'x position of a point in world space
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y position of a point in world space
\n', + type: 'Number' + }, + { + name: 'z', + description: 'z position of a point in world space
\n', + type: 'Number' + } + ], + class: 'p5.Camera', + module: 'Lights, Camera' + }, + camera: { + name: 'camera', + class: 'p5.Camera', + module: 'Lights, Camera' + }, + move: { + name: 'move', + params: [ + { + name: 'x', + description: "amount to move along camera's left-right axis
\n", + type: 'Number' + }, + { + name: 'y', + description: "amount to move along camera's up-down axis
\n", + type: 'Number' + }, + { + name: 'z', + description: + "amount to move along camera's forward-backward axis
\n", + type: 'Number' + } + ], + class: 'p5.Camera', + module: 'Lights, Camera' + }, + setPosition: { + name: 'setPosition', + params: [ + { + name: 'x', + description: 'x position of a point in world space
\n', + type: 'Number' + }, + { + name: 'y', + description: 'y position of a point in world space
\n', + type: 'Number' + }, + { + name: 'z', + description: 'z position of a point in world space
\n', + type: 'Number' + } + ], + class: 'p5.Camera', + module: 'Lights, Camera' + } + }, + 'p5.Geometry': { + computeFaces: { + name: 'computeFaces', + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + computeNormals: { + name: 'computeNormals', + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + averageNormals: { + name: 'averageNormals', + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + averagePoleNormals: { + name: 'averagePoleNormals', + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + normalize: { + name: 'normalize', + class: 'p5.Geometry', + module: 'Lights, Camera' + } + }, + 'p5.Shader': { + setUniform: { + name: 'setUniform', + params: [ + { + name: 'uniformName', + description: 'the name of the uniform in the\nshader program
\n', + type: 'String' + }, + { + name: 'data', + description: + 'the data to be associated\nwith that uniform; type varies (could be a single numerical value, array,\nmatrix, or texture / sampler reference)
\n', + type: 'Object|Number|Boolean|Number[]' + } + ], + class: 'p5.Shader', + module: 'Lights, Camera' + } + }, + 'p5.sound': { + getMasterVolume: { + name: 'getMasterVolume', + class: 'p5.sound', + module: 'p5.sound' + }, + masterVolume: { + name: 'masterVolume', + params: [ + { + name: 'volume', + description: + 'Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator
\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: 'Fade for t seconds
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'Schedule this event to happen at\n t seconds in the future
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.sound', + module: 'p5.sound' + }, + soundOut: { + name: 'soundOut', + class: 'p5.sound', + module: 'p5.sound' + } + }, + 'p5.Effect': { + amp: { + name: 'amp', + params: [ + { + name: 'vol', + description: 'amplitude between 0 and 1.0
\n', + type: 'Number', + optional: true + }, + { + name: 'rampTime', + description: 'create a fade that lasts until rampTime
\n', + type: 'Number', + optional: true + }, + { + name: 'tFromNow', + description: + 'schedule this event to happen in tFromNow seconds
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Effect', + module: 'p5.sound' + }, + chain: { + name: 'chain', + params: [ + { + name: 'arguments', + description: 'Chain together multiple sound objects
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.Effect', + module: 'p5.sound' + }, + drywet: { + name: 'drywet', + params: [ + { + name: 'fade', + description: 'The desired drywet value (0 - 1.0)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Effect', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Effect', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.Effect', + module: 'p5.sound' + } + }, + 'p5.Filter': { + biquadFilter: { + name: 'biquadFilter', + class: 'p5.Filter', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'Signal', + description: 'An object that outputs audio
\n', + type: 'Object' + }, + { + name: 'freq', + description: 'Frequency in Hz, from 10 to 22050
\n', + type: 'Number', + optional: true + }, + { + name: 'res', + description: + 'Resonance/Width of the filter frequency\n from 0.001 to 1000
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Filter', + module: 'p5.sound' + }, + set: { + name: 'set', + params: [ + { + name: 'freq', + description: 'Frequency in Hz, from 10 to 22050
\n', + type: 'Number', + optional: true + }, + { + name: 'res', + description: 'Resonance (Q) from 0.001 to 1000
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Filter', + module: 'p5.sound' + }, + freq: { + name: 'freq', + params: [ + { + name: 'freq', + description: 'Filter Frequency
\n', + type: 'Number' + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Filter', + module: 'p5.sound' + }, + res: { + name: 'res', + params: [ + { + name: 'res', + description: + 'Resonance/Width of filter freq\n from 0.001 to 1000
\n', + type: 'Number' + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Filter', + module: 'p5.sound' + }, + gain: { + name: 'gain', + params: [ + { + name: 'gain', + description: '', + type: 'Number' + } + ], + class: 'p5.Filter', + module: 'p5.sound' + }, + toggle: { + name: 'toggle', + class: 'p5.Filter', + module: 'p5.sound' + }, + setType: { + name: 'setType', + params: [ + { + name: 't', + description: '', + type: 'String' + } + ], + class: 'p5.Filter', + module: 'p5.sound' + } + }, + 'p5.Oscillator': { + start: { + name: 'start', + params: [ + { + name: 'time', + description: 'startTime in seconds from now.
\n', + type: 'Number', + optional: true + }, + { + name: 'frequency', + description: 'frequency in Hz.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + stop: { + name: 'stop', + params: [ + { + name: 'secondsFromNow', + description: 'Time, in seconds from now.
\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + amp: { + name: 'amp', + params: [ + { + name: 'vol', + description: + 'between 0 and 1.0\n or a modulating signal/oscillator
\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: 'create a fade that lasts rampTime
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + freq: { + name: 'freq', + params: [ + { + name: 'Frequency', + description: + 'Frequency in Hz\n or modulating signal/oscillator
\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: 'Ramp time (in seconds)
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'Schedule this event to happen\n at x seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + setType: { + name: 'setType', + params: [ + { + name: 'type', + description: "'sine', 'triangle', 'sawtooth' or 'square'.
\n", + type: 'String' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: 'A p5.sound or Web Audio object
\n', + type: 'Object' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.Oscillator', + module: 'p5.sound' + }, + pan: { + name: 'pan', + params: [ + { + name: 'panning', + description: 'Number between -1 and 1
\n', + type: 'Number' + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + phase: { + name: 'phase', + params: [ + { + name: 'phase', + description: 'float between 0.0 and 1.0
\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + add: { + name: 'add', + params: [ + { + name: 'number', + description: 'Constant number to add
\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + mult: { + name: 'mult', + params: [ + { + name: 'number', + description: 'Constant number to multiply
\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + }, + scale: { + name: 'scale', + params: [ + { + name: 'inMin', + description: 'input range minumum
\n', + type: 'Number' + }, + { + name: 'inMax', + description: 'input range maximum
\n', + type: 'Number' + }, + { + name: 'outMin', + description: 'input range minumum
\n', + type: 'Number' + }, + { + name: 'outMax', + description: 'input range maximum
\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound' + } + }, + 'p5.MonoSynth': { + play: { + name: 'play', + params: [ + { + name: 'note', + description: + 'the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See \n Tone. Defaults to 440 hz.
\n', + type: 'String | Number' + }, + { + name: 'velocity', + description: + 'velocity of the note to play (ranging from 0 to 1)
\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: 'time from now (in seconds) at which to play
\n', + type: 'Number', + optional: true + }, + { + name: 'sustainTime', + description: + 'time to sustain before releasing the envelope. Defaults to 0.15 seconds.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + triggerAttack: { + params: [ + { + name: 'note', + description: + 'the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See \n Tone. Defaults to 440 hz
\n', + type: 'String | Number' + }, + { + name: 'velocity', + description: + 'velocity of the note to play (ranging from 0 to 1)
\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: 'time from now (in seconds) at which to play
\n', + type: 'Number', + optional: true + } + ], + name: 'triggerAttack', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + triggerRelease: { + params: [ + { + name: 'secondsFromNow', + description: 'time to trigger the release
\n', + type: 'Number' + } + ], + name: 'triggerRelease', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + setADSR: { + name: 'setADSR', + params: [ + { + name: 'attackTime', + description: + 'Time (in seconds before envelope\n reaches Attack Level
\n', + type: 'Number' + }, + { + name: 'decayTime', + description: + 'Time (in seconds) before envelope\n reaches Decay/Sustain Level
\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + 'Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange
),\n then decayLevel would increase proportionally, to become 0.5.
Time in seconds from now (defaults to 0)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + attack: { + name: 'attack', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + decay: { + name: 'decay', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + sustain: { + name: 'sustain', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + release: { + name: 'release', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + amp: { + name: 'amp', + params: [ + { + name: 'vol', + description: 'desired volume
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'Time to reach new volume
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: 'A p5.sound or Web Audio object
\n', + type: 'Object' + } + ], + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.MonoSynth', + module: 'p5.sound' + }, + dispose: { + name: 'dispose', + class: 'p5.MonoSynth', + module: 'p5.sound' + } + }, + 'p5.AudioVoice': { + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.AudioVoice', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.AudioVoice', + module: 'p5.sound' + } + }, + 'p5.PolySynth': { + notes: { + name: 'notes', + class: 'p5.PolySynth', + module: 'p5.sound' + }, + polyvalue: { + name: 'polyvalue', + class: 'p5.PolySynth', + module: 'p5.sound' + }, + AudioVoice: { + name: 'AudioVoice', + class: 'p5.PolySynth', + module: 'p5.sound' + }, + play: { + name: 'play', + params: [ + { + name: 'note', + description: + 'midi note to play (ranging from 0 to 127 - 60 being a middle C)
\n', + type: 'Number', + optional: true + }, + { + name: 'velocity', + description: + 'velocity of the note to play (ranging from 0 to 1)
\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: 'time from now (in seconds) at which to play
\n', + type: 'Number', + optional: true + }, + { + name: 'sustainTime', + description: 'time to sustain before releasing the envelope
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound' + }, + noteADSR: { + name: 'noteADSR', + params: [ + { + name: 'note', + description: 'Midi note on which ADSR should be set.
\n', + type: 'Number', + optional: true + }, + { + name: 'attackTime', + description: + 'Time (in seconds before envelope\n reaches Attack Level
\n', + type: 'Number', + optional: true + }, + { + name: 'decayTime', + description: + 'Time (in seconds) before envelope\n reaches Decay/Sustain Level
\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + 'Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange
),\n then decayLevel would increase proportionally, to become 0.5.
Time in seconds from now (defaults to 0)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound' + }, + setADSR: { + name: 'setADSR', + params: [ + { + name: 'attackTime', + description: + 'Time (in seconds before envelope\n reaches Attack Level
\n', + type: 'Number', + optional: true + }, + { + name: 'decayTime', + description: + 'Time (in seconds) before envelope\n reaches Decay/Sustain Level
\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + 'Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange
),\n then decayLevel would increase proportionally, to become 0.5.
Time in seconds from now (defaults to 0)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound' + }, + noteAttack: { + name: 'noteAttack', + params: [ + { + name: 'note', + description: 'midi note on which attack should be triggered.
\n', + type: 'Number', + optional: true + }, + { + name: 'velocity', + description: + 'velocity of the note to play (ranging from 0 to 1)/
\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: 'time from now (in seconds)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound' + }, + noteRelease: { + name: 'noteRelease', + params: [ + { + name: 'note', + description: + 'midi note on which attack should be triggered.\n If no value is provided, all notes will be released.
\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: 'time to trigger the release
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: 'A p5.sound or Web Audio object
\n', + type: 'Object' + } + ], + class: 'p5.PolySynth', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.PolySynth', + module: 'p5.sound' + }, + dispose: { + name: 'dispose', + class: 'p5.PolySynth', + module: 'p5.sound' + } + }, + 'p5.SoundFile': { + isLoaded: { + name: 'isLoaded', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + play: { + name: 'play', + params: [ + { + name: 'startTime', + description: + '(optional) schedule playback to start (in seconds from now).
\n', + type: 'Number', + optional: true + }, + { + name: 'rate', + description: '(optional) playback rate
\n', + type: 'Number', + optional: true + }, + { + name: 'amp', + description: + '(optional) amplitude (volume)\n of playback
\n', + type: 'Number', + optional: true + }, + { + name: 'cueStart', + description: '(optional) cue start time in seconds
\n', + type: 'Number', + optional: true + }, + { + name: 'duration', + description: '(optional) duration of playback in seconds
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + playMode: { + name: 'playMode', + params: [ + { + name: 'str', + description: "'restart' or 'sustain' or 'untilDone'
\n", + type: 'String' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + pause: { + name: 'pause', + params: [ + { + name: 'startTime', + description: + '(optional) schedule event to occur\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + loop: { + name: 'loop', + params: [ + { + name: 'startTime', + description: + '(optional) schedule event to occur\n seconds from now
\n', + type: 'Number', + optional: true + }, + { + name: 'rate', + description: '(optional) playback rate
\n', + type: 'Number', + optional: true + }, + { + name: 'amp', + description: '(optional) playback volume
\n', + type: 'Number', + optional: true + }, + { + name: 'cueLoopStart', + description: '(optional) startTime in seconds
\n', + type: 'Number', + optional: true + }, + { + name: 'duration', + description: '(optional) loop duration in seconds
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + setLoop: { + name: 'setLoop', + params: [ + { + name: 'Boolean', + description: 'set looping to true or false
\n', + type: 'Boolean' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + isLooping: { + name: 'isLooping', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + isPlaying: { + name: 'isPlaying', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + isPaused: { + name: 'isPaused', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + stop: { + name: 'stop', + params: [ + { + name: 'startTime', + description: + '(optional) schedule event to occur\n in seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + setVolume: { + name: 'setVolume', + params: [ + { + name: 'volume', + description: + 'Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator
\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: 'Fade for t seconds
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'Schedule this event to happen at\n t seconds in the future
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + pan: { + name: 'pan', + params: [ + { + name: 'panValue', + description: 'Set the stereo panner
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + getPan: { + name: 'getPan', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + rate: { + name: 'rate', + params: [ + { + name: 'playbackRate', + description: + 'Set the playback rate. 1.0 is normal,\n .5 is half-speed, 2.0 is twice as fast.\n Values less than zero play backwards.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + duration: { + name: 'duration', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + currentTime: { + name: 'currentTime', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + jump: { + name: 'jump', + params: [ + { + name: 'cueTime', + description: 'cueTime of the soundFile in seconds.
\n', + type: 'Number' + }, + { + name: 'duration', + description: 'duration in seconds.
\n', + type: 'Number' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + channels: { + name: 'channels', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + sampleRate: { + name: 'sampleRate', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + frames: { + name: 'frames', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + getPeaks: { + name: 'getPeaks', + params: [ + { + name: 'length', + description: + 'length is the size of the returned array.\n Larger length results in more precision.\n Defaults to 5*width of the browser window.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + reverseBuffer: { + name: 'reverseBuffer', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + onended: { + name: 'onended', + params: [ + { + name: 'callback', + description: + 'function to call when the\n soundfile has ended.
\n', + type: 'Function' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'object', + description: 'Audio object that accepts an input
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + setPath: { + name: 'setPath', + params: [ + { + name: 'path', + description: 'path to audio file
\n', + type: 'String' + }, + { + name: 'callback', + description: 'Callback
\n', + type: 'Function' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + setBuffer: { + name: 'setBuffer', + params: [ + { + name: 'buf', + description: + 'Array of Float32 Array(s). 2 Float32 Arrays\n will create a stereo source. 1 will create\n a mono source.
\n', + type: 'Array' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + processPeaks: { + name: 'processPeaks', + params: [ + { + name: 'callback', + description: 'a function to call once this data is returned
\n', + type: 'Function' + }, + { + name: 'initThreshold', + description: 'initial threshold defaults to 0.9
\n', + type: 'Number', + optional: true + }, + { + name: 'minThreshold', + description: 'minimum threshold defaults to 0.22
\n', + type: 'Number', + optional: true + }, + { + name: 'minPeaks', + description: 'minimum number of peaks defaults to 200
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + addCue: { + name: 'addCue', + params: [ + { + name: 'time', + description: + "Time in seconds, relative to this media\n element's playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.
\n", + type: 'Number' + }, + { + name: 'callback', + description: + 'Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.
\n', + type: 'Function' + }, + { + name: 'value', + description: + 'An object to be passed as the\n second parameter to the\n callback function.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + removeCue: { + name: 'removeCue', + params: [ + { + name: 'id', + description: 'ID of the cue, as returned by addCue
\n', + type: 'Number' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + clearCues: { + name: 'clearCues', + class: 'p5.SoundFile', + module: 'p5.sound' + }, + save: { + name: 'save', + params: [ + { + name: 'fileName', + description: 'name of the resulting .wav file.
\n', + type: 'String', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound' + }, + getBlob: { + name: 'getBlob', + class: 'p5.SoundFile', + module: 'p5.sound' + } + }, + 'p5.Amplitude': { + setInput: { + name: 'setInput', + params: [ + { + name: 'snd', + description: + 'set the sound source\n (optional, defaults to\n master output)
\n', + type: 'SoundObject|undefined', + optional: true + }, + { + name: 'smoothing', + description: + 'a range between 0.0 and 1.0\n to smooth amplitude readings
\n', + type: 'Number|undefined', + optional: true + } + ], + class: 'p5.Amplitude', + module: 'p5.sound' + }, + getLevel: { + name: 'getLevel', + params: [ + { + name: 'channel', + description: + 'Optionally return only channel 0 (left) or 1 (right)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Amplitude', + module: 'p5.sound' + }, + toggleNormalize: { + name: 'toggleNormalize', + params: [ + { + name: 'boolean', + description: 'set normalize to true (1) or false (0)
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5.Amplitude', + module: 'p5.sound' + }, + smooth: { + name: 'smooth', + params: [ + { + name: 'set', + description: 'smoothing from 0.0 <= 1
\n', + type: 'Number' + } + ], + class: 'p5.Amplitude', + module: 'p5.sound' + } + }, + 'p5.FFT': { + setInput: { + name: 'setInput', + params: [ + { + name: 'source', + description: 'p5.sound object (or web audio API source node)
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + waveform: { + name: 'waveform', + params: [ + { + name: 'bins', + description: + 'Must be a power of two between\n 16 and 1024. Defaults to 1024.
\n', + type: 'Number', + optional: true + }, + { + name: 'precision', + description: + 'If any value is provided, will return results\n in a Float32 Array which is more precise\n than a regular array.
\n', + type: 'String', + optional: true + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + analyze: { + name: 'analyze', + params: [ + { + name: 'bins', + description: + 'Must be a power of two between\n 16 and 1024. Defaults to 1024.
\n', + type: 'Number', + optional: true + }, + { + name: 'scale', + description: + 'If "dB," returns decibel\n float measurements between\n -140 and 0 (max).\n Otherwise returns integers from 0-255.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + getEnergy: { + name: 'getEnergy', + params: [ + { + name: 'frequency1', + description: + 'Will return a value representing\n energy at this frequency. Alternately,\n the strings "bass", "lowMid" "mid",\n "highMid", and "treble" will return\n predefined frequency ranges.
\n', + type: 'Number|String' + }, + { + name: 'frequency2', + description: + 'If a second frequency is given,\n will return average amount of\n energy that exists between the\n two frequencies.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + getCentroid: { + name: 'getCentroid', + class: 'p5.FFT', + module: 'p5.sound' + }, + smooth: { + name: 'smooth', + params: [ + { + name: 'smoothing', + description: + '0.0 < smoothing < 1.0.\n Defaults to 0.8.
\n', + type: 'Number' + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + linAverages: { + name: 'linAverages', + params: [ + { + name: 'N', + description: 'Number of returned frequency groups
\n', + type: 'Number' + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + logAverages: { + name: 'logAverages', + params: [ + { + name: 'octaveBands', + description: 'Array of Octave Bands objects for grouping
\n', + type: 'Array' + } + ], + class: 'p5.FFT', + module: 'p5.sound' + }, + getOctaveBands: { + name: 'getOctaveBands', + params: [ + { + name: 'N', + description: + 'Specifies the 1/N type of generated octave bands
\n', + type: 'Number' + }, + { + name: 'fCtr0', + description: 'Minimum central frequency for the lowest band
\n', + type: 'Number' + } + ], + class: 'p5.FFT', + module: 'p5.sound' + } + }, + 'p5.Signal': { + fade: { + name: 'fade', + params: [ + { + name: 'value', + description: 'Value to set this signal
\n', + type: 'Number' + }, + { + name: 'secondsFromNow', + description: 'Length of fade, in seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Signal', + module: 'p5.sound' + }, + setInput: { + name: 'setInput', + params: [ + { + name: 'input', + description: '', + type: 'Object' + } + ], + class: 'p5.Signal', + module: 'p5.sound' + }, + add: { + name: 'add', + params: [ + { + name: 'number', + description: '', + type: 'Number' + } + ], + class: 'p5.Signal', + module: 'p5.sound' + }, + mult: { + name: 'mult', + params: [ + { + name: 'number', + description: 'to multiply
\n', + type: 'Number' + } + ], + class: 'p5.Signal', + module: 'p5.sound' + }, + scale: { + name: 'scale', + params: [ + { + name: 'number', + description: 'to multiply
\n', + type: 'Number' + }, + { + name: 'inMin', + description: 'input range minumum
\n', + type: 'Number' + }, + { + name: 'inMax', + description: 'input range maximum
\n', + type: 'Number' + }, + { + name: 'outMin', + description: 'input range minumum
\n', + type: 'Number' + }, + { + name: 'outMax', + description: 'input range maximum
\n', + type: 'Number' + } + ], + class: 'p5.Signal', + module: 'p5.sound' + } + }, + 'p5.Envelope': { + attackTime: { + name: 'attackTime', + class: 'p5.Envelope', + module: 'p5.sound' + }, + attackLevel: { + name: 'attackLevel', + class: 'p5.Envelope', + module: 'p5.sound' + }, + decayTime: { + name: 'decayTime', + class: 'p5.Envelope', + module: 'p5.sound' + }, + decayLevel: { + name: 'decayLevel', + class: 'p5.Envelope', + module: 'p5.sound' + }, + releaseTime: { + name: 'releaseTime', + class: 'p5.Envelope', + module: 'p5.sound' + }, + releaseLevel: { + name: 'releaseLevel', + class: 'p5.Envelope', + module: 'p5.sound' + }, + set: { + name: 'set', + params: [ + { + name: 'attackTime', + description: + 'Time (in seconds) before level\n reaches attackLevel
\n', + type: 'Number' + }, + { + name: 'attackLevel', + description: + 'Typically an amplitude between\n 0.0 and 1.0
\n', + type: 'Number' + }, + { + name: 'decayTime', + description: 'Time
\n', + type: 'Number' + }, + { + name: 'decayLevel', + description: + 'Amplitude (In a standard ADSR envelope,\n decayLevel = sustainLevel)
\n', + type: 'Number' + }, + { + name: 'releaseTime', + description: 'Release Time (in seconds)
\n', + type: 'Number' + }, + { + name: 'releaseLevel', + description: 'Amplitude
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + setADSR: { + name: 'setADSR', + params: [ + { + name: 'attackTime', + description: + 'Time (in seconds before envelope\n reaches Attack Level
\n', + type: 'Number' + }, + { + name: 'decayTime', + description: + 'Time (in seconds) before envelope\n reaches Decay/Sustain Level
\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + 'Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange
),\n then decayLevel would increase proportionally, to become 0.5.
Time in seconds from now (defaults to 0)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + setRange: { + name: 'setRange', + params: [ + { + name: 'aLevel', + description: 'attack level (defaults to 1)
\n', + type: 'Number' + }, + { + name: 'rLevel', + description: 'release level (defaults to 0)
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + setInput: { + name: 'setInput', + params: [ + { + name: 'inputs', + description: + 'A p5.sound object or\n Web Audio Param.
\n', + type: 'Object', + optional: true, + multiple: true + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + setExp: { + name: 'setExp', + params: [ + { + name: 'isExp', + description: 'true is exponential, false is linear
\n', + type: 'Boolean' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + play: { + name: 'play', + params: [ + { + name: 'unit', + description: + 'A p5.sound object or\n Web Audio Param.
\n', + type: 'Object' + }, + { + name: 'startTime', + description: 'time from now (in seconds) at which to play
\n', + type: 'Number', + optional: true + }, + { + name: 'sustainTime', + description: 'time to sustain before releasing the envelope
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + triggerAttack: { + name: 'triggerAttack', + params: [ + { + name: 'unit', + description: 'p5.sound Object or Web Audio Param
\n', + type: 'Object' + }, + { + name: 'secondsFromNow', + description: 'time from now (in seconds)
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + triggerRelease: { + name: 'triggerRelease', + params: [ + { + name: 'unit', + description: 'p5.sound Object or Web Audio Param
\n', + type: 'Object' + }, + { + name: 'secondsFromNow', + description: 'time to trigger the release
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + ramp: { + name: 'ramp', + params: [ + { + name: 'unit', + description: 'p5.sound Object or Web Audio Param
\n', + type: 'Object' + }, + { + name: 'secondsFromNow', + description: 'When to trigger the ramp
\n', + type: 'Number' + }, + { + name: 'v', + description: 'Target value
\n', + type: 'Number' + }, + { + name: 'v2', + description: 'Second target value (optional)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + add: { + name: 'add', + params: [ + { + name: 'number', + description: 'Constant number to add
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + mult: { + name: 'mult', + params: [ + { + name: 'number', + description: 'Constant number to multiply
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + }, + scale: { + name: 'scale', + params: [ + { + name: 'inMin', + description: 'input range minumum
\n', + type: 'Number' + }, + { + name: 'inMax', + description: 'input range maximum
\n', + type: 'Number' + }, + { + name: 'outMin', + description: 'input range minumum
\n', + type: 'Number' + }, + { + name: 'outMax', + description: 'input range maximum
\n', + type: 'Number' + } + ], + class: 'p5.Envelope', + module: 'p5.sound' + } + }, + 'p5.Pulse': { + width: { + name: 'width', + params: [ + { + name: 'width', + description: + 'Width between the pulses (0 to 1.0,\n defaults to 0)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Pulse', + module: 'p5.sound' + } + }, + 'p5.Noise': { + setType: { + name: 'setType', + params: [ + { + name: 'type', + description: "'white', 'pink' or 'brown'
\n", + type: 'String', + optional: true + } + ], + class: 'p5.Noise', + module: 'p5.sound' + } + }, + 'p5.AudioIn': { + input: { + name: 'input', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + output: { + name: 'output', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + stream: { + name: 'stream', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + mediaStream: { + name: 'mediaStream', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + currentSource: { + name: 'currentSource', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + enabled: { + name: 'enabled', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + amplitude: { + name: 'amplitude', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + start: { + name: 'start', + params: [ + { + name: 'successCallback', + description: + 'Name of a function to call on\n success.
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'Name of a function to call if\n there was an error. For example,\n some browsers do not support\n getUserMedia.
\n', + type: 'Function', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound' + }, + stop: { + name: 'stop', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: + 'An object that accepts audio input,\n such as an FFT
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.AudioIn', + module: 'p5.sound' + }, + getLevel: { + name: 'getLevel', + params: [ + { + name: 'smoothing', + description: + 'Smoothing is 0.0 by default.\n Smooths values based on previous values.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound' + }, + amp: { + name: 'amp', + params: [ + { + name: 'vol', + description: 'between 0 and 1.0
\n', + type: 'Number' + }, + { + name: 'time', + description: 'ramp time (optional)
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound' + }, + getSources: { + name: 'getSources', + params: [ + { + name: 'successCallback', + description: + 'This callback function handles the sources when they\n have been enumerated. The callback function\n receives the deviceList array as its only argument
\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + 'This optional callback receives the error\n message as its argument.
\n', + type: 'Function', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound' + }, + setSource: { + name: 'setSource', + params: [ + { + name: 'num', + description: 'position of input source in the array
\n', + type: 'Number' + } + ], + class: 'p5.AudioIn', + module: 'p5.sound' + } + }, + 'p5.EQ': { + bands: { + name: 'bands', + class: 'p5.EQ', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'src', + description: 'Audio source
\n', + type: 'Object' + } + ], + class: 'p5.EQ', + module: 'p5.sound' + } + }, + 'p5.Panner3D': { + panner: { + name: 'panner', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'src', + description: 'Input source
\n', + type: 'Object' + } + ], + class: 'p5.Panner3D', + module: 'p5.sound' + }, + set: { + name: 'set', + params: [ + { + name: 'xVal', + description: '', + type: 'Number' + }, + { + name: 'yVal', + description: '', + type: 'Number' + }, + { + name: 'zVal', + description: '', + type: 'Number' + }, + { + name: 'time', + description: '', + type: 'Number' + } + ], + class: 'p5.Panner3D', + module: 'p5.sound' + }, + positionX: { + name: 'positionX', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + positionY: { + name: 'positionY', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + positionZ: { + name: 'positionZ', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + orient: { + name: 'orient', + params: [ + { + name: 'xVal', + description: '', + type: 'Number' + }, + { + name: 'yVal', + description: '', + type: 'Number' + }, + { + name: 'zVal', + description: '', + type: 'Number' + }, + { + name: 'time', + description: '', + type: 'Number' + } + ], + class: 'p5.Panner3D', + module: 'p5.sound' + }, + orientX: { + name: 'orientX', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + orientY: { + name: 'orientY', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + orientZ: { + name: 'orientZ', + class: 'p5.Panner3D', + module: 'p5.sound' + }, + setFalloff: { + name: 'setFalloff', + params: [ + { + name: 'maxDistance', + description: '', + type: 'Number', + optional: true + }, + { + name: 'rolloffFactor', + description: '', + type: 'Number', + optional: true + } + ], + class: 'p5.Panner3D', + module: 'p5.sound' + }, + maxDist: { + name: 'maxDist', + params: [ + { + name: 'maxDistance', + description: '', + type: 'Number' + } + ], + class: 'p5.Panner3D', + module: 'p5.sound' + }, + rollof: { + name: 'rollof', + params: [ + { + name: 'rolloffFactor', + description: '', + type: 'Number' + } + ], + class: 'p5.Panner3D', + module: 'p5.sound' + } + }, + 'p5.Delay': { + leftDelay: { + name: 'leftDelay', + class: 'p5.Delay', + module: 'p5.sound' + }, + rightDelay: { + name: 'rightDelay', + class: 'p5.Delay', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'Signal', + description: 'An object that outputs audio
\n', + type: 'Object' + }, + { + name: 'delayTime', + description: + 'Time (in seconds) of the delay/echo.\n Some browsers limit delayTime to\n 1 second.
\n', + type: 'Number', + optional: true + }, + { + name: 'feedback', + description: + 'sends the delay back through itself\n in a loop that decreases in volume\n each time.
\n', + type: 'Number', + optional: true + }, + { + name: 'lowPass', + description: + 'Cutoff frequency. Only frequencies\n below the lowPass will be part of the\n delay.
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + delayTime: { + name: 'delayTime', + params: [ + { + name: 'delayTime', + description: 'Time (in seconds) of the delay
\n', + type: 'Number' + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + feedback: { + name: 'feedback', + params: [ + { + name: 'feedback', + description: + '0.0 to 1.0, or an object such as an\n Oscillator that can be used to\n modulate this param
\n', + type: 'Number|Object' + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + filter: { + name: 'filter', + params: [ + { + name: 'cutoffFreq', + description: + 'A lowpass filter will cut off any\n frequencies higher than the filter frequency.
\n', + type: 'Number|Object' + }, + { + name: 'res', + description: + 'Resonance of the filter frequency\n cutoff, or an object (i.e. a p5.Oscillator)\n that can be used to modulate this parameter.\n High numbers (i.e. 15) will produce a resonance,\n low numbers (i.e. .2) will produce a slope.
\n', + type: 'Number|Object' + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + setType: { + name: 'setType', + params: [ + { + name: 'type', + description: "'pingPong' (1) or 'default' (0)
\n", + type: 'String|Number' + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + amp: { + name: 'amp', + params: [ + { + name: 'volume', + description: 'amplitude between 0 and 1.0
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'create a fade that lasts rampTime
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Delay', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.Delay', + module: 'p5.sound' + } + }, + 'p5.Reverb': { + process: { + name: 'process', + params: [ + { + name: 'src', + description: + 'p5.sound / Web Audio object with a sound\n output.
\n', + type: 'Object' + }, + { + name: 'seconds', + description: + 'Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.
\n', + type: 'Number', + optional: true + }, + { + name: 'decayRate', + description: + 'Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.
\n', + type: 'Number', + optional: true + }, + { + name: 'reverse', + description: 'Play the reverb backwards or forwards.
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5.Reverb', + module: 'p5.sound' + }, + set: { + name: 'set', + params: [ + { + name: 'seconds', + description: + 'Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.
\n', + type: 'Number', + optional: true + }, + { + name: 'decayRate', + description: + 'Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.
\n', + type: 'Number', + optional: true + }, + { + name: 'reverse', + description: 'Play the reverb backwards or forwards.
\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5.Reverb', + module: 'p5.sound' + }, + amp: { + name: 'amp', + params: [ + { + name: 'volume', + description: 'amplitude between 0 and 1.0
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'create a fade that lasts rampTime
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Reverb', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Reverb', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.Reverb', + module: 'p5.sound' + } + }, + 'p5.Convolver': { + convolverNode: { + name: 'convolverNode', + class: 'p5.Convolver', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'src', + description: + 'p5.sound / Web Audio object with a sound\n output.
\n', + type: 'Object' + } + ], + class: 'p5.Convolver', + module: 'p5.sound' + }, + impulses: { + name: 'impulses', + class: 'p5.Convolver', + module: 'p5.sound' + }, + addImpulse: { + name: 'addImpulse', + params: [ + { + name: 'path', + description: 'path to a sound file
\n', + type: 'String' + }, + { + name: 'callback', + description: 'function (optional)
\n', + type: 'Function' + }, + { + name: 'errorCallback', + description: 'function (optional)
\n', + type: 'Function' + } + ], + class: 'p5.Convolver', + module: 'p5.sound' + }, + resetImpulse: { + name: 'resetImpulse', + params: [ + { + name: 'path', + description: 'path to a sound file
\n', + type: 'String' + }, + { + name: 'callback', + description: 'function (optional)
\n', + type: 'Function' + }, + { + name: 'errorCallback', + description: 'function (optional)
\n', + type: 'Function' + } + ], + class: 'p5.Convolver', + module: 'p5.sound' + }, + toggleImpulse: { + name: 'toggleImpulse', + params: [ + { + name: 'id', + description: + 'Identify the impulse by its original filename\n (String), or by its position in the\n .impulses
Array (Number).
Beats Per Minute
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'Seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + getBPM: { + name: 'getBPM', + class: 'p5.Part', + module: 'p5.sound' + }, + start: { + name: 'start', + params: [ + { + name: 'time', + description: 'seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + loop: { + name: 'loop', + params: [ + { + name: 'time', + description: 'seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + noLoop: { + name: 'noLoop', + class: 'p5.Part', + module: 'p5.sound' + }, + stop: { + name: 'stop', + params: [ + { + name: 'time', + description: 'seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + pause: { + name: 'pause', + params: [ + { + name: 'time', + description: 'seconds from now
\n', + type: 'Number' + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + addPhrase: { + name: 'addPhrase', + params: [ + { + name: 'phrase', + description: 'reference to a p5.Phrase
\n', + type: 'p5.Phrase' + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + removePhrase: { + name: 'removePhrase', + params: [ + { + name: 'phraseName', + description: '', + type: 'String' + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + getPhrase: { + name: 'getPhrase', + params: [ + { + name: 'phraseName', + description: '', + type: 'String' + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + replaceSequence: { + name: 'replaceSequence', + params: [ + { + name: 'phraseName', + description: '', + type: 'String' + }, + { + name: 'sequence', + description: + 'Array of values to pass into the callback\n at each step of the phrase.
\n', + type: 'Array' + } + ], + class: 'p5.Part', + module: 'p5.sound' + }, + onStep: { + name: 'onStep', + params: [ + { + name: 'callback', + description: + 'The name of the callback\n you want to fire\n on every beat/tatum.
\n', + type: 'Function' + } + ], + class: 'p5.Part', + module: 'p5.sound' + } + }, + 'p5.Score': { + start: { + name: 'start', + class: 'p5.Score', + module: 'p5.sound' + }, + stop: { + name: 'stop', + class: 'p5.Score', + module: 'p5.sound' + }, + pause: { + name: 'pause', + class: 'p5.Score', + module: 'p5.sound' + }, + loop: { + name: 'loop', + class: 'p5.Score', + module: 'p5.sound' + }, + noLoop: { + name: 'noLoop', + class: 'p5.Score', + module: 'p5.sound' + }, + setBPM: { + name: 'setBPM', + params: [ + { + name: 'BPM', + description: 'Beats Per Minute
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'Seconds from now
\n', + type: 'Number' + } + ], + class: 'p5.Score', + module: 'p5.sound' + } + }, + 'p5.SoundLoop': { + musicalTimeMode: { + name: 'musicalTimeMode', + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + maxIterations: { + name: 'maxIterations', + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + start: { + name: 'start', + params: [ + { + name: 'timeFromNow', + description: 'schedule a starting time
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + stop: { + name: 'stop', + params: [ + { + name: 'timeFromNow', + description: 'schedule a stopping time
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + pause: { + name: 'pause', + params: [ + { + name: 'timeFromNow', + description: 'schedule a pausing time
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + syncedStart: { + name: 'syncedStart', + params: [ + { + name: 'otherLoop', + description: 'a p5.SoundLoop to sync with
\n', + type: 'Object' + }, + { + name: 'timeFromNow', + description: + 'Start the loops in sync after timeFromNow seconds
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + bpm: { + name: 'bpm', + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + timeSignature: { + name: 'timeSignature', + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + interval: { + name: 'interval', + class: 'p5.SoundLoop', + module: 'p5.sound' + }, + iterations: { + name: 'iterations', + class: 'p5.SoundLoop', + module: 'p5.sound' + } + }, + 'p5.Compressor': { + compressor: { + name: 'compressor', + class: 'p5.Compressor', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'src', + description: 'Sound source to be connected
\n', + type: 'Object' + }, + { + name: 'attack', + description: + 'The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1
\n', + type: 'Number', + optional: true + }, + { + name: 'knee', + description: + 'A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40
\n', + type: 'Number', + optional: true + }, + { + name: 'ratio', + description: + 'The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20
\n', + type: 'Number', + optional: true + }, + { + name: 'threshold', + description: + 'The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0
\n', + type: 'Number', + optional: true + }, + { + name: 'release', + description: + 'The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + set: { + name: 'set', + params: [ + { + name: 'attack', + description: + 'The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1
\n', + type: 'Number' + }, + { + name: 'knee', + description: + 'A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40
\n', + type: 'Number' + }, + { + name: 'ratio', + description: + 'The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20
\n', + type: 'Number' + }, + { + name: 'threshold', + description: + 'The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0
\n', + type: 'Number' + }, + { + name: 'release', + description: + 'The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1
\n', + type: 'Number' + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + attack: { + name: 'attack', + params: [ + { + name: 'attack', + description: + 'Attack is the amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1
\n', + type: 'Number', + optional: true + }, + { + name: 'time', + description: + 'Assign time value to schedule the change in value
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + knee: { + name: 'knee', + params: [ + { + name: 'knee', + description: + 'A decibel value representing the range above the\n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40
\n', + type: 'Number', + optional: true + }, + { + name: 'time', + description: + 'Assign time value to schedule the change in value
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + ratio: { + name: 'ratio', + params: [ + { + name: 'ratio', + description: + 'The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20
\n', + type: 'Number', + optional: true + }, + { + name: 'time', + description: + 'Assign time value to schedule the change in value
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + threshold: { + name: 'threshold', + params: [ + { + name: 'threshold', + description: + 'The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0
\n', + type: 'Number' + }, + { + name: 'time', + description: + 'Assign time value to schedule the change in value
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + release: { + name: 'release', + params: [ + { + name: 'release', + description: + 'The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1
\n', + type: 'Number' + }, + { + name: 'time', + description: + 'Assign time value to schedule the change in value
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound' + }, + reduction: { + name: 'reduction', + class: 'p5.Compressor', + module: 'p5.sound' + } + }, + 'p5.SoundRecorder': { + setInput: { + name: 'setInput', + params: [ + { + name: 'unit', + description: + 'p5.sound object or a web audio unit\n that outputs sound
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.SoundRecorder', + module: 'p5.sound' + }, + record: { + name: 'record', + params: [ + { + name: 'soundFile', + description: 'p5.SoundFile
\n', + type: 'p5.SoundFile' + }, + { + name: 'duration', + description: 'Time (in seconds)
\n', + type: 'Number', + optional: true + }, + { + name: 'callback', + description: + 'The name of a function that will be\n called once the recording completes
\n', + type: 'Function', + optional: true + } + ], + class: 'p5.SoundRecorder', + module: 'p5.sound' + }, + stop: { + name: 'stop', + class: 'p5.SoundRecorder', + module: 'p5.sound' + } + }, + 'p5.PeakDetect': { + isDetected: { + name: 'isDetected', + class: 'p5.PeakDetect', + module: 'p5.sound' + }, + update: { + name: 'update', + params: [ + { + name: 'fftObject', + description: 'A p5.FFT object
\n', + type: 'p5.FFT' + } + ], + class: 'p5.PeakDetect', + module: 'p5.sound' + }, + onPeak: { + name: 'onPeak', + params: [ + { + name: 'callback', + description: + 'Name of a function that will\n be called when a peak is\n detected.
\n', + type: 'Function' + }, + { + name: 'val', + description: + 'Optional value to pass\n into the function when\n a peak is detected.
\n', + type: 'Object', + optional: true + } + ], + class: 'p5.PeakDetect', + module: 'p5.sound' + } + }, + 'p5.Gain': { + setInput: { + name: 'setInput', + params: [ + { + name: 'src', + description: + 'p5.sound / Web Audio object with a sound\n output.
\n', + type: 'Object' + } + ], + class: 'p5.Gain', + module: 'p5.sound' + }, + connect: { + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Gain', + module: 'p5.sound' + }, + disconnect: { + name: 'disconnect', + class: 'p5.Gain', + module: 'p5.sound' + }, + amp: { + name: 'amp', + params: [ + { + name: 'volume', + description: 'amplitude between 0 and 1.0
\n', + type: 'Number' + }, + { + name: 'rampTime', + description: 'create a fade that lasts rampTime
\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + 'schedule this event to happen\n seconds from now
\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Gain', + module: 'p5.sound' + } + }, + 'p5.Distortion': { + WaveShaperNode: { + name: 'WaveShaperNode', + class: 'p5.Distortion', + module: 'p5.sound' + }, + process: { + name: 'process', + params: [ + { + name: 'amount', + description: + 'Unbounded distortion amount.\n Normal values range from 0-1.
\n', + type: 'Number', + optional: true, + optdefault: '0.25' + }, + { + name: 'oversample', + description: "'none', '2x', or '4x'.
\n", + type: 'String', + optional: true, + optdefault: "'none'" + } + ], + class: 'p5.Distortion', + module: 'p5.sound' + }, + set: { + name: 'set', + params: [ + { + name: 'amount', + description: + 'Unbounded distortion amount.\n Normal values range from 0-1.
\n', + type: 'Number', + optional: true, + optdefault: '0.25' + }, + { + name: 'oversample', + description: "'none', '2x', or '4x'.
\n", + type: 'String', + optional: true, + optdefault: "'none'" + } + ], + class: 'p5.Distortion', + module: 'p5.sound' + }, + getAmount: { + name: 'getAmount', + class: 'p5.Distortion', + module: 'p5.sound' + }, + getOversample: { + name: 'getOversample', + class: 'p5.Distortion', + module: 'p5.sound' + } + } + }; + }, + {} + ], + 2: [ + function(_dereq_, module, exports) { + function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; + } + + module.exports = _arrayWithHoles; + }, + {} + ], + 3: [ + function(_dereq_, module, exports) { + function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { + arr2[i] = arr[i]; + } + + return arr2; + } + } + + module.exports = _arrayWithoutHoles; + }, + {} + ], + 4: [ + function(_dereq_, module, exports) { + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError( + "this hasn't been initialised - super() hasn't been called" + ); + } + + return self; + } + + module.exports = _assertThisInitialized; + }, + {} + ], + 5: [ + function(_dereq_, module, exports) { + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function'); + } + } + + module.exports = _classCallCheck; + }, + {} + ], + 6: [ + function(_dereq_, module, exports) { + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ('value' in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + module.exports = _createClass; + }, + {} + ], + 7: [ + function(_dereq_, module, exports) { + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + module.exports = _defineProperty; + }, + {} + ], + 8: [ + function(_dereq_, module, exports) { + function _getPrototypeOf(o) { + module.exports = _getPrototypeOf = Object.setPrototypeOf + ? Object.getPrototypeOf + : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + module.exports = _getPrototypeOf; + }, + {} + ], + 9: [ + function(_dereq_, module, exports) { + var setPrototypeOf = _dereq_('./setPrototypeOf'); + + function _inherits(subClass, superClass) { + if (typeof superClass !== 'function' && superClass !== null) { + throw new TypeError('Super expression must either be null or a function'); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) setPrototypeOf(subClass, superClass); + } + + module.exports = _inherits; + }, + { './setPrototypeOf': 16 } + ], + 10: [ + function(_dereq_, module, exports) { + function _iterableToArray(iter) { + if ( + Symbol.iterator in Object(iter) || + Object.prototype.toString.call(iter) === '[object Arguments]' + ) + return Array.from(iter); + } + + module.exports = _iterableToArray; + }, + {} + ], + 11: [ + function(_dereq_, module, exports) { + function _iterableToArrayLimit(arr, i) { + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for ( + var _i = arr[Symbol.iterator](), _s; + !(_n = (_s = _i.next()).done); + _n = true + ) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i['return'] != null) _i['return'](); + } finally { + if (_d) throw _e; + } + } + + return _arr; + } + + module.exports = _iterableToArrayLimit; + }, + {} + ], + 12: [ + function(_dereq_, module, exports) { + function _nonIterableRest() { + throw new TypeError('Invalid attempt to destructure non-iterable instance'); + } + + module.exports = _nonIterableRest; + }, + {} + ], + 13: [ + function(_dereq_, module, exports) { + function _nonIterableSpread() { + throw new TypeError('Invalid attempt to spread non-iterable instance'); + } + + module.exports = _nonIterableSpread; + }, + {} + ], + 14: [ + function(_dereq_, module, exports) { + var defineProperty = _dereq_('./defineProperty'); + + function _objectSpread(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + var ownKeys = Object.keys(source); + + if (typeof Object.getOwnPropertySymbols === 'function') { + ownKeys = ownKeys.concat( + Object.getOwnPropertySymbols(source).filter(function(sym) { + return Object.getOwnPropertyDescriptor(source, sym).enumerable; + }) + ); + } + + ownKeys.forEach(function(key) { + defineProperty(target, key, source[key]); + }); + } + + return target; + } + + module.exports = _objectSpread; + }, + { './defineProperty': 7 } + ], + 15: [ + function(_dereq_, module, exports) { + var _typeof = _dereq_('../helpers/typeof'); + + var assertThisInitialized = _dereq_('./assertThisInitialized'); + + function _possibleConstructorReturn(self, call) { + if (call && (_typeof(call) === 'object' || typeof call === 'function')) { + return call; + } + + return assertThisInitialized(self); + } + + module.exports = _possibleConstructorReturn; + }, + { '../helpers/typeof': 19, './assertThisInitialized': 4 } + ], + 16: [ + function(_dereq_, module, exports) { + function _setPrototypeOf(o, p) { + module.exports = _setPrototypeOf = + Object.setPrototypeOf || + function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + module.exports = _setPrototypeOf; + }, + {} + ], + 17: [ + function(_dereq_, module, exports) { + var arrayWithHoles = _dereq_('./arrayWithHoles'); + + var iterableToArrayLimit = _dereq_('./iterableToArrayLimit'); + + var nonIterableRest = _dereq_('./nonIterableRest'); + + function _slicedToArray(arr, i) { + return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest(); + } + + module.exports = _slicedToArray; + }, + { './arrayWithHoles': 2, './iterableToArrayLimit': 11, './nonIterableRest': 12 } + ], + 18: [ + function(_dereq_, module, exports) { + var arrayWithoutHoles = _dereq_('./arrayWithoutHoles'); + + var iterableToArray = _dereq_('./iterableToArray'); + + var nonIterableSpread = _dereq_('./nonIterableSpread'); + + function _toConsumableArray(arr) { + return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread(); + } + + module.exports = _toConsumableArray; + }, + { './arrayWithoutHoles': 3, './iterableToArray': 10, './nonIterableSpread': 13 } + ], + 19: [ + function(_dereq_, module, exports) { + function _typeof2(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof2 = function _typeof2(obj) { + return typeof obj; + }; + } else { + _typeof2 = function _typeof2(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof2(obj); + } + + function _typeof(obj) { + if (typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol') { + module.exports = _typeof = function _typeof(obj) { + return _typeof2(obj); + }; + } else { + module.exports = _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : _typeof2(obj); + }; + } + + return _typeof(obj); + } + + module.exports = _typeof; + }, + {} + ], + 20: [ + function(_dereq_, module, exports) { + 'use strict'; + + exports.byteLength = byteLength; + exports.toByteArray = toByteArray; + exports.fromByteArray = fromByteArray; + + var lookup = []; + var revLookup = []; + var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; + + var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i]; + revLookup[code.charCodeAt(i)] = i; + } + + // Support decoding URL-safe base64 strings, as Node.js does. + // See: https://en.wikipedia.org/wiki/Base64#URL_applications + revLookup['-'.charCodeAt(0)] = 62; + revLookup['_'.charCodeAt(0)] = 63; + + function getLens(b64) { + var len = b64.length; + + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4'); + } + + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('='); + if (validLen === -1) validLen = len; + + var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; + + return [validLen, placeHoldersLen]; + } + + // base64 is 4/3 + up to two characters of the original data + function byteLength(b64) { + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + + function _byteLength(b64, validLen, placeHoldersLen) { + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + + function toByteArray(b64) { + var tmp; + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); + + var curByte = 0; + + // if there are placeholders, only get up to the last complete 4 chars + var len = placeHoldersLen > 0 ? validLen - 4 : validLen; + + var i; + for (i = 0; i < len; i += 4) { + tmp = + (revLookup[b64.charCodeAt(i)] << 18) | + (revLookup[b64.charCodeAt(i + 1)] << 12) | + (revLookup[b64.charCodeAt(i + 2)] << 6) | + revLookup[b64.charCodeAt(i + 3)]; + arr[curByte++] = (tmp >> 16) & 0xff; + arr[curByte++] = (tmp >> 8) & 0xff; + arr[curByte++] = tmp & 0xff; + } + + if (placeHoldersLen === 2) { + tmp = + (revLookup[b64.charCodeAt(i)] << 2) | + (revLookup[b64.charCodeAt(i + 1)] >> 4); + arr[curByte++] = tmp & 0xff; + } + + if (placeHoldersLen === 1) { + tmp = + (revLookup[b64.charCodeAt(i)] << 10) | + (revLookup[b64.charCodeAt(i + 1)] << 4) | + (revLookup[b64.charCodeAt(i + 2)] >> 2); + arr[curByte++] = (tmp >> 8) & 0xff; + arr[curByte++] = tmp & 0xff; + } + + return arr; + } + + function tripletToBase64(num) { + return ( + lookup[(num >> 18) & 0x3f] + + lookup[(num >> 12) & 0x3f] + + lookup[(num >> 6) & 0x3f] + + lookup[num & 0x3f] + ); + } + + function encodeChunk(uint8, start, end) { + var tmp; + var output = []; + for (var i = start; i < end; i += 3) { + tmp = + ((uint8[i] << 16) & 0xff0000) + + ((uint8[i + 1] << 8) & 0xff00) + + (uint8[i + 2] & 0xff); + output.push(tripletToBase64(tmp)); + } + return output.join(''); + } + + function fromByteArray(uint8) { + var tmp; + var len = uint8.length; + var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes + var parts = []; + var maxChunkLength = 16383; // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push( + encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength) + ); + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1]; + parts.push(lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3f] + '=='); + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + uint8[len - 1]; + parts.push( + lookup[tmp >> 10] + + lookup[(tmp >> 4) & 0x3f] + + lookup[(tmp << 2) & 0x3f] + + '=' + ); + } + + return parts.join(''); + } + }, + {} + ], + 21: [function(_dereq_, module, exports) {}, {}], + 22: [ + function(_dereq_, module, exports) { + (function(Buffer) { + /*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijehdescribe(text, LABEL)
displays
+ * the description to all users as a
+ * tombstone or exhibit label/caption in a
+ * <div class="p5Label"></div>
+ * adjacent to the canvas. You can style it as you wish in your CSS.
+ *
+ * describe(text, FALLBACK)
makes the
+ * description accessible to screen-reader users only, in
+ *
+ * a sub DOM inside the canvas element. If a second parameter is not
+ * specified, by default, the description will only be available to
+ * screen-reader users.
+ *
+ * @method describe
+ * @param {String} text description of the canvas
+ * @param {Constant} [display] either LABEL or FALLBACK (Optional)
+ *
+ * @example
+ *
+ * describe('pink square with red heart in the bottom right corner', LABEL);
+ * background('pink');
+ * fill('red');
+ * noStroke();
+ * ellipse(67, 67, 20, 20);
+ * ellipse(83, 67, 20, 20);
+ * triangle(91, 73, 75, 95, 59, 73);
+ *
+ *
+ * let x = 0;
+ * function draw() {
+ * if (x > 100) {
+ * x = 0;
+ * }
+ * background(220);
+ * fill(0, 255, 0);
+ * ellipse(x, 50, 40, 40);
+ * x = x + 0.1;
+ * describe('green circle at x pos ' + round(x) + ' moving to the right');
+ * }
+ *
+ * describeElement(name, text, LABEL)
+ * displays the element description to all users as a
+ *
+ * tombstone or exhibit label/caption in a
+ * <div class="p5Label"></div>
+ * adjacent to the canvas. You can style it as you wish in your CSS.
+ *
+ * describeElement(name, text, FALLBACK)
+ * makes the element description accessible to screen-reader users
+ * only, in
+ * a sub DOM inside the canvas element. If a second parameter is not
+ * specified, by default, the element description will only be available
+ * to screen-reader users.
+ *
+ * @method describeElement
+ * @param {String} name name of the element
+ * @param {String} text description of the element
+ * @param {Constant} [display] either LABEL or FALLBACK (Optional)
+ *
+ * @example
+ *
+ * describe('Heart and yellow circle over pink background', LABEL);
+ * noStroke();
+ * background('pink');
+ * describeElement('Circle', 'Yellow circle in the top left corner', LABEL);
+ * fill('yellow');
+ * ellipse(25, 25, 40, 40);
+ * describeElement('Heart', 'red heart in the bottom right corner', LABEL);
+ * fill('red');
+ * ellipse(66.6, 66.6, 20, 20);
+ * ellipse(83.2, 66.6, 20, 20);
+ * triangle(91.2, 72.6, 75, 95, 58.6, 72.6);
+ *
+ * for fallback description + this.dummyDOM.querySelector('#'.concat(cnvId)).innerHTML = html; + } else { + //create description container +
for fallback description before outputs + this.dummyDOM + .querySelector('#'.concat(cnvId, 'accessibleOutput')) + .insertAdjacentHTML('beforebegin', html); + } + } else { + //if describeElement() has already created the container and added a table of elements + //create fallback description
before the table + this.dummyDOM + .querySelector('#' + cnvId + fallbackTableId) + .insertAdjacentHTML( + 'beforebegin', + '
') + ); + } + //if the container for the description exists + this.descriptions.fallback = this.dummyDOM.querySelector( + '#'.concat(cnvId).concat(fallbackDescId) + ); + + this.descriptions.fallback.innerHTML = text; + return; + } else if (type === 'label') { + //if there is no label container + if (!this.dummyDOM.querySelector('#'.concat(cnvId + labelContainer))) { + var _html = 'for label description + this.dummyDOM + .querySelector('#' + cnvId) + .insertAdjacentHTML('afterend', _html); + } else { + //create label container +
for label description before outputs + this.dummyDOM + .querySelector('#'.concat(cnvId, 'accessibleOutputLabel')) + .insertAdjacentHTML('beforebegin', _html); + } + } else if (this.dummyDOM.querySelector('#'.concat(cnvId + labelTableId))) { + //if describeElement() has already created the container and added a table of elements + //create label description
before the table + this.dummyDOM + .querySelector('#'.concat(cnvId + labelTableId)) + .insertAdjacentHTML( + 'beforebegin', + '
') + ); + } + this.descriptions.label = this.dummyDOM.querySelector( + '#' + cnvId + labelDescId + ); + + this.descriptions.label.innerHTML = text; + return; + } + }; + + /* + * Helper functions for describeElement(). + */ + + //check that name is not LABEL or FALLBACK and ensure text ends with colon + function _elementName(name) { + if (name === 'label' || name === 'fallback') { + throw new Error('element name should not be LABEL or FALLBACK'); + } + //check if last character of string n is '.', ';', or ',' + if (name.endsWith('.') || name.endsWith(';') || name.endsWith(',')) { + //replace last character with ':' + name = name.replace(/.$/, ':'); + } else if (!name.endsWith(':')) { + //if string n does not end with ':' + //add ':'' at the end of string + name = name + ':'; + } + return name; + } + + //creates HTML structure for element descriptions + _main.default.prototype._describeElementHTML = function(type, name, text) { + var cnvId = this.canvas.id; + if (type === 'fallback') { + //if there is no description container + if (!this.dummyDOM.querySelector('#'.concat(cnvId + descContainer))) { + //if there are no accessible outputs (see textOutput() and gridOutput()) + var html = 'textOutput()
creates a screenreader
+ * accessible output that describes the shapes present on the canvas.
+ * The general description of the canvas includes canvas size,
+ * canvas color, and number of elements in the canvas
+ * (example: 'Your output is a, 400 by 400 pixels, lavender blue
+ * canvas containing the following 4 shapes:'). This description
+ * is followed by a list of shapes where the color, position, and area
+ * of each shape are described (example: "orange ellipse at top left
+ * covering 1% of the canvas"). Each element can be selected to get
+ * more details. A table of elements is also provided. In this table,
+ * shape, color, location, coordinates and area are described
+ * (example: "orange ellipse location=top left area=2").
+ *
+ * textOutput()
and texOutput(FALLBACK)
+ * make the output available in
+ * a sub DOM inside the canvas element which is accessible to screen readers.
+ * textOutput(LABEL)
creates an
+ * additional div with the output adjacent to the canvas, this is useful
+ * for non-screen reader users that might want to display the output outside
+ * of the canvas' sub DOM as they code. However, using LABEL will create
+ * unnecessary redundancy for screen reader users. We recommend using LABEL
+ * only as part of the development process of a sketch and removing it before
+ * publishing or sharing with screen reader users.
+ *
+ * @method textOutput
+ * @param {Constant} [display] either FALLBACK or LABEL (Optional)
+ *
+ * @example
+ *
+ * textOutput();
+ * background(148, 196, 0);
+ * fill(255, 0, 0);
+ * ellipse(20, 20, 20, 20);
+ * fill(0, 0, 255);
+ * rect(50, 50, 50, 50);
+ *
+ *
+ * let x = 0;
+ * function draw() {
+ * textOutput();
+ * background(148, 196, 0);
+ * fill(255, 0, 0);
+ * ellipse(x, 20, 20, 20);
+ * fill(0, 0, 255);
+ * rect(50, 50, 50, 50);
+ * ellipse(20, 20, 20, 20);
+ * x += 0.1;
+ * }
+ *
+ * gridOutput()
lays out the
+ * content of the canvas in the form of a grid (html table) based
+ * on the spatial location of each shape. A brief
+ * description of the canvas is available before the table output.
+ * This description includes: color of the background, size of the canvas,
+ * number of objects, and object types (example: "lavender blue canvas is
+ * 200 by 200 and contains 4 objects - 3 ellipses 1 rectangle"). The grid
+ * describes the content spatially, each element is placed on a cell of the
+ * table depending on its position. Within each cell an element the color
+ * and type of shape of that element are available (example: "orange ellipse").
+ * These descriptions can be selected individually to get more details.
+ * A list of elements where shape, color, location, and area are described
+ * (example: "orange ellipse location=top left area=1%") is also available.
+ *
+ * gridOutput()
and gridOutput(FALLBACK)
+ * make the output available in
+ * a sub DOM inside the canvas element which is accessible to screen readers.
+ * gridOutput(LABEL)
creates an
+ * additional div with the output adjacent to the canvas, this is useful
+ * for non-screen reader users that might want to display the output outside
+ * of the canvas' sub DOM as they code. However, using LABEL will create
+ * unnecessary redundancy for screen reader users. We recommend using LABEL
+ * only as part of the development process of a sketch and removing it before
+ * publishing or sharing with screen reader users.
+ *
+ * @method gridOutput
+ * @param {Constant} [display] either FALLBACK or LABEL (Optional)
+ *
+ * @example
+ *
+ * gridOutput();
+ * background(148, 196, 0);
+ * fill(255, 0, 0);
+ * ellipse(20, 20, 20, 20);
+ * fill(0, 0, 255);
+ * rect(50, 50, 50, 50);
+ *
+ *
+ * let x = 0;
+ * function draw() {
+ * gridOutput();
+ * background(148, 196, 0);
+ * fill(255, 0, 0);
+ * ellipse(x, 20, 20, 20);
+ * fill(0, 0, 255);
+ * rect(50, 50, 50, 50);
+ * ellipse(20, 20, 20, 20);
+ * x += 0.1;
+ * }
+ *
+ *
+ * noStroke();
+ * let c = color(0, 126, 255, 102);
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ * let value = alpha(c); // Sets 'value' to 102
+ * fill(value);
+ * rect(50, 15, 35, 70);
+ *
+ *
+ * let c = color(175, 100, 220);
+ * fill(c);
+ * rect(15, 20, 35, 60); // Draw left rectangle
+ * let blueValue = blue(c);
+ * fill(0, 0, blueValue);
+ * rect(50, 20, 35, 60); // Draw right rectangle
+ *
+ *
+ * noStroke();
+ * colorMode(HSB, 255);
+ * let c = color(0, 126, 255);
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ * let value = brightness(c); // Sets 'value' to 255
+ * fill(value);
+ * rect(50, 20, 35, 60);
+ *
+ *
+ * noStroke();
+ * colorMode(HSB, 255);
+ * let c = color('hsb(60, 100%, 50%)');
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ * let value = brightness(c); // A 'value' of 50% is 127.5
+ * fill(value);
+ * rect(50, 20, 35, 60);
+ *
+ *
+ * let c = color(255, 204, 0);
+ * fill(c);
+ * noStroke();
+ * rect(30, 20, 55, 55);
+ *
+ *
+ * let c = color(255, 204, 0);
+ * fill(c);
+ * noStroke();
+ * ellipse(25, 25, 80, 80); // Draw left circle
+ * // Using only one value generates a grayscale value.
+ * c = color(65);
+ * fill(c);
+ * ellipse(75, 75, 80, 80);
+ *
+ *
+ * // You can use named SVG & CSS colors
+ * let c = color('magenta');
+ * fill(c);
+ * noStroke();
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // Example of hex color codes
+ * noStroke();
+ * let c = color('#0f0');
+ * fill(c);
+ * rect(0, 10, 45, 80);
+ * c = color('#00ff00');
+ * fill(c);
+ * rect(55, 10, 45, 80);
+ *
+ *
+ * // RGB and RGBA color strings are also supported
+ * // these all set to the same color (solid blue)
+ * let c;
+ * noStroke();
+ * c = color('rgb(0,0,255)');
+ * fill(c);
+ * rect(10, 10, 35, 35); // Draw rectangle
+ * c = color('rgb(0%, 0%, 100%)');
+ * fill(c);
+ * rect(55, 10, 35, 35); // Draw rectangle
+ * c = color('rgba(0, 0, 255, 1)');
+ * fill(c);
+ * rect(10, 55, 35, 35); // Draw rectangle
+ * c = color('rgba(0%, 0%, 100%, 1)');
+ * fill(c);
+ * rect(55, 55, 35, 35); // Draw rectangle
+ *
+ *
+ * // HSL color can also be specified by value
+ * let c = color('hsl(160, 100%, 50%)');
+ * noStroke();
+ * fill(c);
+ * rect(0, 10, 45, 80); // Draw rectangle
+ * c = color('hsla(160, 100%, 50%, 0.5)');
+ * fill(c);
+ * rect(55, 10, 45, 80); // Draw rectangle
+ *
+ *
+ * // HSB color can also be specified
+ * let c = color('hsb(160, 100%, 50%)');
+ * noStroke();
+ * fill(c);
+ * rect(0, 10, 45, 80); // Draw rectangle
+ * c = color('hsba(160, 100%, 50%, 0.5)');
+ * fill(c);
+ * rect(55, 10, 45, 80); // Draw rectangle
+ *
+ *
+ * noStroke();
+ * let c = color(50, 55, 100);
+ * fill(c);
+ * rect(0, 10, 45, 80); // Draw left rect
+ * colorMode(HSB, 100);
+ * c = color(50, 55, 100);
+ * fill(c);
+ * rect(55, 10, 45, 80);
+ *
+ *
+ * let c = color(20, 75, 200); // Define color 'c'
+ * fill(c); // Use color variable 'c' as fill color
+ * rect(15, 20, 35, 60); // Draw left rectangle
+ *
+ * let greenValue = green(c); // Get green in 'c'
+ * print(greenValue); // Print "75.0"
+ * fill(0, greenValue, 0); // Use 'greenValue' in new fill
+ * rect(50, 20, 35, 60); // Draw right rectangle
+ *
+ *
+ * noStroke();
+ * colorMode(HSB, 255);
+ * let c = color(0, 126, 255);
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ * let value = hue(c); // Sets 'value' to "0"
+ * fill(value);
+ * rect(50, 20, 35, 60);
+ *
+ *
+ * colorMode(RGB);
+ * stroke(255);
+ * background(51);
+ * let from = color(218, 165, 32);
+ * let to = color(72, 61, 139);
+ * colorMode(RGB); // Try changing to HSB.
+ * let interA = lerpColor(from, to, 0.33);
+ * let interB = lerpColor(from, to, 0.66);
+ * fill(from);
+ * rect(10, 20, 20, 60);
+ * fill(interA);
+ * rect(30, 20, 20, 60);
+ * fill(interB);
+ * rect(50, 20, 20, 60);
+ * fill(to);
+ * rect(70, 20, 20, 60);
+ *
+ *
+ * noStroke();
+ * colorMode(HSL);
+ * let c = color(156, 100, 50, 1);
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ * let value = lightness(c); // Sets 'value' to 50
+ * fill(value);
+ * rect(50, 20, 35, 60);
+ *
+ *
+ * let c = color(255, 204, 0); // Define color 'c'
+ * fill(c); // Use color variable 'c' as fill color
+ * rect(15, 20, 35, 60); // Draw left rectangle
+ *
+ * let redValue = red(c); // Get red in 'c'
+ * print(redValue); // Print "255.0"
+ * fill(redValue, 0, 0); // Use 'redValue' in new fill
+ * rect(50, 20, 35, 60); // Draw right rectangle
+ *
+ *
+ * colorMode(RGB, 255); // Sets the range for red, green, and blue to 255
+ * let c = color(127, 255, 0);
+ * colorMode(RGB, 1); // Sets the range for red, green, and blue to 1
+ * let myColor = red(c);
+ * print(myColor); // 0.4980392156862745
+ *
+ *
+ * noStroke();
+ * colorMode(HSB, 255);
+ * let c = color(0, 126, 255);
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ * let value = saturation(c); // Sets 'value' to 126
+ * fill(value);
+ * rect(50, 20, 35, 60);
+ *
+ *
+ * createCanvas(200, 100);
+ * let myColor;
+ * stroke(255);
+ * myColor = color(100, 100, 250);
+ * fill(myColor);
+ * rotate(HALF_PI);
+ * text(myColor.toString(), 0, -5);
+ * text(myColor.toString('#rrggbb'), 0, -30);
+ * text(myColor.toString('rgba%'), 0, -55);
+ *
+ *
+ * let myColor = color(100, 130, 250);
+ * text(myColor.toString('#rrggbb'), 25, 25);
+ *
+ *
+ * let backgroundColor;
+ *
+ * function setup() {
+ * backgroundColor = color(100, 50, 150);
+ * }
+ *
+ * function draw() {
+ * backgroundColor.setRed(128 + 128 * sin(millis() / 1000));
+ * background(backgroundColor);
+ * }
+ *
+ *
+ * let backgroundColor = color(100, 50, 150);
+ * function draw() {
+ * backgroundColor.setGreen(128 + 128 * sin(millis() / 1000));
+ * background(backgroundColor);
+ * }
+ *
+ *
+ * let backgroundColor = color(100, 50, 150);
+ * function draw() {
+ * backgroundColor.setBlue(128 + 128 * sin(millis() / 1000));
+ * background(backgroundColor);
+ * }
+ *
+ *
+ * function draw() {
+ * clear();
+ * background(200);
+ * squareColor = color(100, 50, 100);
+ * squareColor.setAlpha(128 + 128 * sin(millis() / 1000));
+ * fill(squareColor);
+ * rect(13, 13, width - 26, height - 26);
+ * }
+ *
+ *
+ * // todo
+ *
+ *
+ * // Grayscale integer value
+ * background(51);
+ *
+ *
+ * // R, G & B integer values
+ * background(255, 204, 0);
+ *
+ *
+ * // H, S & B integer values
+ * colorMode(HSB);
+ * background(255, 204, 100);
+ *
+ *
+ * // Named SVG/CSS color string
+ * background('red');
+ *
+ *
+ * // three-digit hexadecimal RGB notation
+ * background('#fae');
+ *
+ *
+ * // six-digit hexadecimal RGB notation
+ * background('#222222');
+ *
+ *
+ * // integer RGB notation
+ * background('rgb(0,255,0)');
+ *
+ *
+ * // integer RGBA notation
+ * background('rgba(0,255,0, 0.25)');
+ *
+ *
+ * // percentage RGB notation
+ * background('rgb(100%,0%,10%)');
+ *
+ *
+ * // percentage RGBA notation
+ * background('rgba(100%,0%,100%,0.5)');
+ *
+ *
+ * // p5 Color object
+ * background(color(0, 0, 255));
+ *
+ *
+ * // Clear the screen on mouse press.
+ * function draw() {
+ * ellipse(mouseX, mouseY, 20, 20);
+ * }
+ * function mousePressed() {
+ * clear();
+ * background(128);
+ * }
+ *
+ *
+ * noStroke();
+ * colorMode(RGB, 100);
+ * for (let i = 0; i < 100; i++) {
+ * for (let j = 0; j < 100; j++) {
+ * stroke(i, j, 0);
+ * point(i, j);
+ * }
+ * }
+ *
+ *
+ * noStroke();
+ * colorMode(HSB, 100);
+ * for (let i = 0; i < 100; i++) {
+ * for (let j = 0; j < 100; j++) {
+ * stroke(i, j, 100);
+ * point(i, j);
+ * }
+ * }
+ *
+ *
+ * colorMode(RGB, 255);
+ * let c = color(127, 255, 0);
+ * colorMode(RGB, 1);
+ * let myColor = c._getRed();
+ * text(myColor, 10, 10, 80, 80);
+ *
+ *
+ * noFill();
+ * colorMode(RGB, 255, 255, 255, 1);
+ * background(255);
+ * strokeWeight(4);
+ * stroke(255, 0, 10, 0.3);
+ * ellipse(40, 40, 50, 50);
+ * ellipse(50, 50, 40, 40);
+ *
+ *
+ * // Grayscale integer value
+ * fill(51);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // R, G & B integer values
+ * fill(255, 204, 0);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // H, S & B integer values
+ * colorMode(HSB);
+ * fill(255, 204, 100);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // Named SVG/CSS color string
+ * fill('red');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // three-digit hexadecimal RGB notation
+ * fill('#fae');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // six-digit hexadecimal RGB notation
+ * fill('#222222');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // integer RGB notation
+ * fill('rgb(0,255,0)');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // integer RGBA notation
+ * fill('rgba(0,255,0, 0.25)');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // percentage RGB notation
+ * fill('rgb(100%,0%,10%)');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // percentage RGBA notation
+ * fill('rgba(100%,0%,100%,0.5)');
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // p5 Color object
+ * fill(color(0, 0, 255));
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * rect(15, 10, 55, 55);
+ * noFill();
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * noFill();
+ * stroke(100, 100, 240);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * box(45, 45, 45);
+ * }
+ *
+ *
+ * noStroke();
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * noStroke();
+ * fill(240, 150, 150);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * box(45, 45, 45);
+ * }
+ *
+ *
+ * // Grayscale integer value
+ * strokeWeight(4);
+ * stroke(51);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // R, G & B integer values
+ * stroke(255, 204, 0);
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // H, S & B integer values
+ * colorMode(HSB);
+ * strokeWeight(4);
+ * stroke(255, 204, 100);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // Named SVG/CSS color string
+ * stroke('red');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // three-digit hexadecimal RGB notation
+ * stroke('#fae');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // six-digit hexadecimal RGB notation
+ * stroke('#222222');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // integer RGB notation
+ * stroke('rgb(0,255,0)');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // integer RGBA notation
+ * stroke('rgba(0,255,0,0.25)');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // percentage RGB notation
+ * stroke('rgb(100%,0%,10%)');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // percentage RGBA notation
+ * stroke('rgba(100%,0%,100%,0.5)');
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * // p5 Color object
+ * stroke(color(0, 0, 255));
+ * strokeWeight(4);
+ * rect(20, 20, 60, 60);
+ *
+ *
+ * background(100, 100, 250);
+ * fill(250, 100, 100);
+ * rect(20, 20, 60, 60);
+ * erase();
+ * ellipse(25, 30, 30);
+ * noErase();
+ *
+ *
+ * background(150, 250, 150);
+ * fill(100, 100, 250);
+ * rect(20, 20, 60, 60);
+ * strokeWeight(5);
+ * erase(150, 255);
+ * triangle(50, 10, 70, 50, 90, 10);
+ * noErase();
+ *
+ *
+ * function setup() {
+ * smooth();
+ * createCanvas(100, 100, WEBGL);
+ * // Make a <p> element and put it behind the canvas
+ * let p = createP('I am a dom element');
+ * p.center();
+ * p.style('font-size', '20px');
+ * p.style('text-align', 'center');
+ * p.style('z-index', '-9999');
+ * }
+ *
+ * function draw() {
+ * background(250, 250, 150);
+ * fill(15, 195, 185);
+ * noStroke();
+ * sphere(30);
+ * erase();
+ * rotateY(frameCount * 0.02);
+ * translate(0, 0, 40);
+ * torus(15, 5);
+ * noErase();
+ * }
+ *
+ *
+ * background(235, 145, 15);
+ * noStroke();
+ * fill(30, 45, 220);
+ * rect(30, 10, 10, 80);
+ * erase();
+ * ellipse(50, 50, 60);
+ * noErase();
+ * rect(70, 10, 10, 80);
+ *
+ *
+ * arc(50, 50, 80, 80, 0, HALF_PI);
+ *
+ * arc(50, 50, 80, 80, 0, PI);
+ *
+ * arc(50, 50, 80, 80, 0, QUARTER_PI);
+ *
+ * arc(50, 50, 80, 80, 0, TAU);
+ *
+ * arc(50, 50, 80, 80, 0, TWO_PI);
+ *
+ * function setup() {
+ * angleMode(DEGREES);
+ * }
+ *
+ * function setup() {
+ * angleMode(RADIANS);
+ * }
+ *
+ * let x = 10;
+ * print('The value of x is ' + x);
+ * // prints "The value of x is 10"
+ *
+ * function setup() {
+ * frameRate(30);
+ * textSize(30);
+ * textAlign(CENTER);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * text(frameCount, width / 2, height / 2);
+ * }
+ *
+ * let rectX = 0;
+ * let fr = 30; //starting FPS
+ * let clr;
+ *
+ * function setup() {
+ * background(200);
+ * frameRate(fr); // Attempt to refresh at starting FPS
+ * clr = color(255, 0, 0);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rectX = rectX + 1 * (deltaTime / 50); // Move Rectangle in relation to deltaTime
+ *
+ * if (rectX >= width) {
+ * // If you go off screen.
+ * if (fr === 30) {
+ * clr = color(0, 0, 255);
+ * fr = 10;
+ * frameRate(fr); // make frameRate 10 FPS
+ * } else {
+ * clr = color(255, 0, 0);
+ * fr = 30;
+ * frameRate(fr); // make frameRate 30 FPS
+ * }
+ * rectX = 0;
+ * }
+ * fill(clr);
+ * rect(rectX, 40, 20, 20);
+ * }
+ *
+ * // To demonstrate, put two windows side by side.
+ * // Click on the window that the p5 sketch isn't in!
+ * function draw() {
+ * background(200);
+ * noStroke();
+ * fill(0, 200, 0);
+ * ellipse(25, 25, 50, 50);
+ *
+ * if (!focused) {
+ // or "if (focused === false)"
+ * stroke(200, 0, 0);
+ * line(0, 0, 100, 100);
+ * line(100, 0, 0, 100);
+ * }
+ * }
+ *
+ * // Move the mouse across the quadrants
+ * // to see the cursor change
+ * function draw() {
+ * line(width / 2, 0, width / 2, height);
+ * line(0, height / 2, width, height / 2);
+ * if (mouseX < 50 && mouseY < 50) {
+ * cursor(CROSS);
+ * } else if (mouseX > 50 && mouseY < 50) {
+ * cursor('progress');
+ * } else if (mouseX > 50 && mouseY > 50) {
+ * cursor('https://avatars0.githubusercontent.com/u/1617169?s=16');
+ * } else {
+ * cursor('grab');
+ * }
+ * }
+ *
+ * let rectX = 0;
+ * let fr = 30; //starting FPS
+ * let clr;
+ *
+ * function setup() {
+ * background(200);
+ * frameRate(fr); // Attempt to refresh at starting FPS
+ * clr = color(255, 0, 0);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rectX = rectX += 1; // Move Rectangle
+ *
+ * if (rectX >= width) {
+ // If you go off screen.
+ * if (fr === 30) {
+ * clr = color(0, 0, 255);
+ * fr = 10;
+ * frameRate(fr); // make frameRate 10 FPS
+ * } else {
+ * clr = color(255, 0, 0);
+ * fr = 30;
+ * frameRate(fr); // make frameRate 30 FPS
+ * }
+ * rectX = 0;
+ * }
+ * fill(clr);
+ * rect(rectX, 40, 20, 20);
+ * }
+ *
+ * function setup() {
+ * noCursor();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * ellipse(mouseX, mouseY, 10, 10);
+ * }
+ *
+ * createCanvas(displayWidth, displayHeight);
+ *
+ * createCanvas(displayWidth, displayHeight);
+ *
+ * createCanvas(windowWidth, windowHeight);
+ *
+ * createCanvas(windowWidth, windowHeight);
+ *
+ * function setup() {
+ * createCanvas(windowWidth, windowHeight);
+ * }
+ *
+ * function draw() {
+ * background(0, 100, 200);
+ * }
+ *
+ * function windowResized() {
+ * resizeCanvas(windowWidth, windowHeight);
+ * }
+ *
+ * // Clicking in the box toggles fullscreen on and off.
+ * function setup() {
+ * background(200);
+ * }
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * let fs = fullscreen();
+ * fullscreen(!fs);
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * pixelDensity(1);
+ * createCanvas(100, 100);
+ * background(200);
+ * ellipse(width / 2, height / 2, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * pixelDensity(3.0);
+ * createCanvas(100, 100);
+ * background(200);
+ * ellipse(width / 2, height / 2, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * let density = displayDensity();
+ * pixelDensity(density);
+ * createCanvas(100, 100);
+ * background(200);
+ * ellipse(width / 2, height / 2, 50, 50);
+ * }
+ *
+ *
+ * let url;
+ * let x = 100;
+ *
+ * function setup() {
+ * fill(0);
+ * noStroke();
+ * url = getURL();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * text(url, x, height / 2);
+ * x--;
+ * }
+ *
+ *
+ * function setup() {
+ * let urlPath = getURLPath();
+ * for (let i = 0; i < urlPath.length; i++) {
+ * text(urlPath[i], 10, i * 20 + 20);
+ * }
+ * }
+ *
+ * // Example: http://p5js.org?year=2014&month=May&day=15
+ *
+ * function setup() {
+ * let params = getURLParams();
+ * text(params.day, 10, 20);
+ * text(params.month, 10, 40);
+ * text(params.year, 10, 60);
+ * }
+ *
+ *
+ * let img;
+ * let c;
+ * function preload() {
+ * // preload() runs once
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * // setup() waits until preload() is done
+ * img.loadPixels();
+ * // get color of middle pixel
+ * c = img.get(img.width / 2, img.height / 2);
+ * }
+ *
+ * function draw() {
+ * background(c);
+ * image(img, 25, 25, 50, 50);
+ * }
+ *
+ * let a = 0;
+ *
+ * function setup() {
+ * background(0);
+ * noStroke();
+ * fill(102);
+ * }
+ *
+ * function draw() {
+ * rect(a++ % width, 10, 2, 80);
+ * }
+ *
+ * let yPos = 0;
+ * function setup() {
+ * // setup() runs once
+ * frameRate(30);
+ * }
+ * function draw() {
+ * // draw() loops forever, until stopped
+ * background(204);
+ * yPos = yPos - 1;
+ * if (yPos < 0) {
+ * yPos = height;
+ * }
+ * line(0, yPos, width, yPos);
+ * }
+ *
+ * function draw() {
+ * ellipse(50, 50, 10, 10);
+ * }
+ *
+ * function mousePressed() {
+ * remove(); // remove whole sketch on mouse press
+ * }
+ *
+ * p5.disableFriendlyErrors = true;
+ *
+ * function setup() {
+ * createCanvas(100, 50);
+ * }
+ *
+ * function setup() {
+ * let c = createCanvas(50, 50);
+ * c.elt.style.border = '5px solid red';
+ * }
+ *
+ * function draw() {
+ * background(220);
+ * }
+ *
+ *
+ * // Add the following comment to html file.
+ * // <div id="myContainer"></div>
+ *
+ * // The js code
+ * let cnv = createCanvas(100, 100);
+ * cnv.parent('myContainer');
+ *
+ * let div0 = createDiv('this is the parent');
+ * let div1 = createDiv('this is the child');
+ * div1.parent(div0); // use p5.Element
+ *
+ * let div0 = createDiv('this is the parent');
+ * div0.id('apples');
+ * let div1 = createDiv('this is the child');
+ * div1.parent('apples'); // use id
+ *
+ * let elt = document.getElementById('myParentDiv');
+ * let div1 = createDiv('this is the child');
+ * div1.parent(elt); // use element from page
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ * // Assigns a CSS selector ID to
+ * // the canvas element.
+ * cnv.id('mycanvas');
+ * }
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ * // Assigns a CSS selector class 'small'
+ * // to the canvas element.
+ * cnv.class('small');
+ * }
+ *
+ * let cnv, d, g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mousePressed(changeGray); // attach listener for
+ * // canvas click only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires with any click anywhere
+ * function mousePressed() {
+ * d = d + 10;
+ * }
+ *
+ * // this function fires only when cnv is clicked
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ * let cnv, d, g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.doubleClicked(changeGray); // attach listener for
+ * // canvas double click only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires with any double click anywhere
+ * function doubleClicked() {
+ * d = d + 10;
+ * }
+ *
+ * // this function fires only when cnv is double clicked
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ * let cnv, d, g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mouseWheel(changeSize); // attach listener for
+ * // activity on canvas only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires with mousewheel movement
+ * // anywhere on screen
+ * function mouseWheel() {
+ * g = g + 10;
+ * }
+ *
+ * // this function fires with mousewheel movement
+ * // over canvas only
+ * function changeSize(event) {
+ * if (event.deltaY > 0) {
+ * d = d + 10;
+ * } else {
+ * d = d - 10;
+ * }
+ * }
+ *
+ * let cnv, d, g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mouseReleased(changeGray); // attach listener for
+ * // activity on canvas only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires after the mouse has been
+ * // released
+ * function mouseReleased() {
+ * d = d + 10;
+ * }
+ *
+ * // this function fires after the mouse has been
+ * // released while on canvas
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ * let cnv, d, g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mouseClicked(changeGray); // attach listener for
+ * // activity on canvas only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires after the mouse has been
+ * // clicked anywhere
+ * function mouseClicked() {
+ * d = d + 10;
+ * }
+ *
+ * // this function fires after the mouse has been
+ * // clicked on canvas
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ *
+ * let cnv;
+ * let d = 30;
+ * let g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mouseMoved(changeSize); // attach listener for
+ * // activity on canvas only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * fill(200);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires when mouse moves anywhere on
+ * // page
+ * function mouseMoved() {
+ * g = g + 5;
+ * if (g > 255) {
+ * g = 0;
+ * }
+ * }
+ *
+ * // this function fires when mouse moves over canvas
+ * function changeSize() {
+ * d = d + 2;
+ * if (d > 100) {
+ * d = 0;
+ * }
+ * }
+ *
+ * let cnv;
+ * let d;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mouseOver(changeGray);
+ * d = 10;
+ * }
+ *
+ * function draw() {
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * function changeGray() {
+ * d = d + 10;
+ * if (d > 100) {
+ * d = 0;
+ * }
+ * }
+ *
+ * let cnv;
+ * let d;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.mouseOut(changeGray);
+ * d = 10;
+ * }
+ *
+ * function draw() {
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * function changeGray() {
+ * d = d + 10;
+ * if (d > 100) {
+ * d = 0;
+ * }
+ * }
+ *
+ * let cnv;
+ * let d;
+ * let g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.touchStarted(changeGray); // attach listener for
+ * // canvas click only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires with any touch anywhere
+ * function touchStarted() {
+ * d = d + 10;
+ * }
+ *
+ * // this function fires only when cnv is clicked
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ * let cnv;
+ * let g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.touchMoved(changeGray); // attach listener for
+ * // canvas click only
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * }
+ *
+ * // this function fires only when cnv is clicked
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ * let cnv;
+ * let d;
+ * let g;
+ * function setup() {
+ * cnv = createCanvas(100, 100);
+ * cnv.touchEnded(changeGray); // attach listener for
+ * // canvas click only
+ * d = 10;
+ * g = 100;
+ * }
+ *
+ * function draw() {
+ * background(g);
+ * ellipse(width / 2, height / 2, d, d);
+ * }
+ *
+ * // this function fires with any touch anywhere
+ * function touchEnded() {
+ * d = d + 10;
+ * }
+ *
+ * // this function fires only when cnv is clicked
+ * function changeGray() {
+ * g = random(0, 255);
+ * }
+ *
+ * // To test this sketch, simply drag a
+ * // file over the canvas
+ * function setup() {
+ * let c = createCanvas(100, 100);
+ * background(200);
+ * textAlign(CENTER);
+ * text('Drag file', width / 2, height / 2);
+ * c.dragOver(dragOverCallback);
+ * }
+ *
+ * // This function will be called whenever
+ * // a file is dragged over the canvas
+ * function dragOverCallback() {
+ * background(240);
+ * text('Dragged over', width / 2, height / 2);
+ * }
+ *
+ * // To test this sketch, simply drag a file
+ * // over and then out of the canvas area
+ * function setup() {
+ * let c = createCanvas(100, 100);
+ * background(200);
+ * textAlign(CENTER);
+ * text('Drag file', width / 2, height / 2);
+ * c.dragLeave(dragLeaveCallback);
+ * }
+ *
+ * // This function will be called whenever
+ * // a file is dragged out of the canvas
+ * function dragLeaveCallback() {
+ * background(240);
+ * text('Dragged off', width / 2, height / 2);
+ * }
+ *
+ * let pg;
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(0);
+ * pg = createGraphics(50, 100);
+ * pg.fill(0);
+ * frameRate(5);
+ * }
+ *
+ * function draw() {
+ * image(pg, width / 2, 0);
+ * pg.background(255);
+ * // p5.Graphics object behave a bit differently in some cases
+ * // The normal canvas on the left resets the translate
+ * // with every loop through draw()
+ * // the graphics object on the right doesn't automatically reset
+ * // so translate() is additive and it moves down the screen
+ * rect(0, 0, width / 2, 5);
+ * pg.rect(0, 0, width / 2, 5);
+ * translate(0, 5, 0);
+ * pg.translate(0, 5, 0);
+ * }
+ * function mouseClicked() {
+ * // if you click you will see that
+ * // reset() resets the translate back to the initial state
+ * // of the Graphics object
+ * pg.reset();
+ * }
+ *
+ * let bg;
+ * function setup() {
+ * bg = createCanvas(100, 100);
+ * bg.background(0);
+ * image(bg, 0, 0);
+ * bg.remove();
+ * }
+ *
+ * let bg;
+ * function setup() {
+ * pixelDensity(1);
+ * createCanvas(100, 100);
+ * stroke(255);
+ * fill(0);
+ *
+ * // create and draw the background image
+ * bg = createGraphics(100, 100);
+ * bg.background(200);
+ * bg.ellipse(50, 50, 80, 80);
+ * }
+ * function draw() {
+ * let t = millis() / 1000;
+ * // draw the background
+ * if (bg) {
+ * image(bg, frameCount % 100, 0);
+ * image(bg, frameCount % 100 - 100, 0);
+ * }
+ * // draw the foreground
+ * let p = p5.Vector.fromAngle(t, 35).add(50, 50);
+ * ellipse(p.x, p.y, 30);
+ * }
+ * function mouseClicked() {
+ * // remove the background
+ * if (bg) {
+ * bg.remove();
+ * bg = null;
+ * }
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 50);
+ * background(153);
+ * line(0, 0, width, height);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(windowWidth, windowHeight);
+ * }
+ *
+ * function draw() {
+ * background(0, 100, 200);
+ * }
+ *
+ * function windowResized() {
+ * resizeCanvas(windowWidth, windowHeight);
+ * }
+ *
+ * function setup() {
+ * noCanvas();
+ * }
+ *
+ *
+ * let pg;
+ * function setup() {
+ * createCanvas(100, 100);
+ * pg = createGraphics(100, 100);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * pg.background(100);
+ * pg.noStroke();
+ * pg.ellipse(pg.width / 2, pg.height / 2, 50, 50);
+ * image(pg, 50, 50);
+ * image(pg, 0, 0, 50, 50);
+ * }
+ *
+ * BLEND
- linear interpolation of colours: C =
+ * A*factor + B. This is the default blending mode.ADD
- sum of A and BDARKEST
- only the darkest colour succeeds: C =
+ * min(A*factor, B).LIGHTEST
- only the lightest colour succeeds: C =
+ * max(A*factor, B).DIFFERENCE
- subtract colors from underlying image.EXCLUSION
- similar to DIFFERENCE
, but less
+ * extreme.MULTIPLY
- multiply the colors, result will always be
+ * darker.SCREEN
- opposite multiply, uses inverse values of the
+ * colors.REPLACE
- the pixels entirely replace the others and
+ * don't utilize alpha (transparency) values.REMOVE
- removes pixels from B with the alpha strength of A.OVERLAY
- mix of MULTIPLY
and SCREEN
+ *
. Multiplies dark values, and screens light values. (2D)HARD_LIGHT
- SCREEN
when greater than 50%
+ * gray, MULTIPLY
when lower. (2D)SOFT_LIGHT
- mix of DARKEST
and
+ * LIGHTEST
. Works like OVERLAY
, but not as harsh. (2D)
+ * DODGE
- lightens light tones and increases contrast,
+ * ignores darks. (2D)BURN
- darker areas are applied, increasing contrast,
+ * ignores lights. (2D)SUBTRACT
- remainder of A and B (3D)
+ * blendMode(LIGHTEST);
+ * strokeWeight(30);
+ * stroke(80, 150, 255);
+ * line(25, 25, 75, 75);
+ * stroke(255, 50, 50);
+ * line(75, 25, 25, 75);
+ *
+ *
+ * blendMode(MULTIPLY);
+ * strokeWeight(30);
+ * stroke(80, 150, 255);
+ * line(25, 25, 75, 75);
+ * stroke(255, 50, 50);
+ * line(75, 25, 25, 75);
+ *
+ *
+ * function setup() {
+ * drawingContext.shadowOffsetX = 5;
+ * drawingContext.shadowOffsetY = -5;
+ * drawingContext.shadowBlur = 10;
+ * drawingContext.shadowColor = 'black';
+ * background(200);
+ * ellipse(width / 2, height / 2, 50, 50);
+ * }
+ *
+ *
+ * arc(50, 55, 50, 50, 0, HALF_PI);
+ * noFill();
+ * arc(50, 55, 60, 60, HALF_PI, PI);
+ * arc(50, 55, 70, 70, PI, PI + QUARTER_PI);
+ * arc(50, 55, 80, 80, PI + QUARTER_PI, TWO_PI);
+ *
+ *
+ * arc(50, 50, 80, 80, 0, PI + QUARTER_PI);
+ *
+ *
+ * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, OPEN);
+ *
+ *
+ * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, CHORD);
+ *
+ *
+ * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, PIE);
+ *
+ *
+ * ellipse(56, 46, 55, 55);
+ *
+ *
+ * // Draw a circle at location (30, 30) with a diameter of 20.
+ * circle(30, 30, 20);
+ *
+ *
+ * line(30, 20, 85, 75);
+ *
+ *
+ * line(30, 20, 85, 20);
+ * stroke(126);
+ * line(85, 20, 85, 75);
+ * stroke(255);
+ * line(85, 75, 30, 75);
+ *
+ *
+ * point(30, 20);
+ * point(85, 20);
+ * point(85, 75);
+ * point(30, 75);
+ *
+ *
+ * point(30, 20);
+ * point(85, 20);
+ * stroke('purple'); // Change the color
+ * strokeWeight(10); // Make the points 10 pixels in size
+ * point(85, 75);
+ * point(30, 75);
+ *
+ *
+ * let a = createVector(10, 10);
+ * point(a);
+ * let b = createVector(10, 20);
+ * point(b);
+ * point(createVector(20, 10));
+ * point(createVector(20, 20));
+ *
+ *
+ * quad(38, 31, 86, 20, 69, 63, 30, 76);
+ *
+ *
+ * // Draw a rectangle at location (30, 20) with a width and height of 55.
+ * rect(30, 20, 55, 55);
+ *
+ *
+ * // Draw a rectangle with rounded corners, each having a radius of 20.
+ * rect(30, 20, 55, 55, 20);
+ *
+ *
+ * // Draw a rectangle with rounded corners having the following radii:
+ * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.
+ * rect(30, 20, 55, 55, 20, 15, 10, 5);
+ *
+ *
+ * // Draw a square at location (30, 20) with a side size of 55.
+ * square(30, 20, 55);
+ *
+ *
+ * // Draw a square with rounded corners, each having a radius of 20.
+ * square(30, 20, 55, 20);
+ *
+ *
+ * // Draw a square with rounded corners having the following radii:
+ * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.
+ * square(30, 20, 55, 20, 15, 10, 5);
+ *
+ *
+ * triangle(30, 75, 58, 20, 86, 75);
+ *
+ *
+ * // Example showing RADIUS and CENTER ellipsemode with 2 overlaying ellipses
+ * ellipseMode(RADIUS);
+ * fill(255);
+ * ellipse(50, 50, 30, 30); // Outer white ellipse
+ * ellipseMode(CENTER);
+ * fill(100);
+ * ellipse(50, 50, 30, 30); // Inner gray ellipse
+ *
+ *
+ * // Example showing CORNER and CORNERS ellipseMode with 2 overlaying ellipses
+ * ellipseMode(CORNER);
+ * fill(255);
+ * ellipse(25, 25, 50, 50); // Outer white ellipse
+ * ellipseMode(CORNERS);
+ * fill(100);
+ * ellipse(25, 25, 50, 50); // Inner gray ellipse
+ *
+ *
+ * background(0);
+ * noStroke();
+ * smooth();
+ * ellipse(30, 48, 36, 36);
+ * noSmooth();
+ * ellipse(70, 48, 36, 36);
+ *
+ *
+ * rectMode(CORNER);
+ * fill(255);
+ * rect(25, 25, 50, 50); // Draw white rectangle using CORNER mode
+ *
+ * rectMode(CORNERS);
+ * fill(100);
+ * rect(25, 25, 50, 50); // Draw gray rectangle using CORNERS mode
+ *
+ *
+ * rectMode(RADIUS);
+ * fill(255);
+ * rect(50, 50, 30, 30); // Draw white rectangle using RADIUS mode
+ *
+ * rectMode(CENTER);
+ * fill(100);
+ * rect(50, 50, 30, 30); // Draw gray rectangle using CENTER mode
+ *
+ *
+ * background(0);
+ * noStroke();
+ * smooth();
+ * ellipse(30, 48, 36, 36);
+ * noSmooth();
+ * ellipse(70, 48, 36, 36);
+ *
+ *
+ * // Example of different strokeCaps
+ * strokeWeight(12.0);
+ * strokeCap(ROUND);
+ * line(20, 30, 80, 30);
+ * strokeCap(SQUARE);
+ * line(20, 50, 80, 50);
+ * strokeCap(PROJECT);
+ * line(20, 70, 80, 70);
+ *
+ *
+ * // Example of MITER type of joints
+ * noFill();
+ * strokeWeight(10.0);
+ * strokeJoin(MITER);
+ * beginShape();
+ * vertex(35, 20);
+ * vertex(65, 50);
+ * vertex(35, 80);
+ * endShape();
+ *
+ *
+ * // Example of BEVEL type of joints
+ * noFill();
+ * strokeWeight(10.0);
+ * strokeJoin(BEVEL);
+ * beginShape();
+ * vertex(35, 20);
+ * vertex(65, 50);
+ * vertex(35, 80);
+ * endShape();
+ *
+ *
+ * // Example of ROUND type of joints
+ * noFill();
+ * strokeWeight(10.0);
+ * strokeJoin(ROUND);
+ * beginShape();
+ * vertex(35, 20);
+ * vertex(65, 50);
+ * vertex(35, 80);
+ * endShape();
+ *
+ *
+ * // Example of different stroke weights
+ * strokeWeight(1); // Default
+ * line(20, 20, 80, 20);
+ * strokeWeight(4); // Thicker
+ * line(20, 40, 80, 40);
+ * strokeWeight(10); // Beastly
+ * line(20, 70, 80, 70);
+ *
+ *
+ * noFill();
+ * stroke(255, 102, 0);
+ * line(85, 20, 10, 10);
+ * line(90, 90, 15, 80);
+ * stroke(0, 0, 0);
+ * bezier(85, 20, 10, 10, 90, 90, 15, 80);
+ *
+ *
+ * background(0, 0, 0);
+ * noFill();
+ * stroke(255);
+ * bezier(250, 250, 0, 100, 100, 0, 100, 0, 0, 0, 100, 0);
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * noFill();
+ * bezierDetail(5);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * // prettier-ignore
+ * bezier(-40, -40, 0,
+ * 90, -40, 0,
+ * -90, 40, 0,
+ * 40, 40, 0);
+ * }
+ *
+ *
+ * noFill();
+ * let x1 = 85,
+ x2 = 10,
+ x3 = 90,
+ x4 = 15;
+ * let y1 = 20,
+ y2 = 10,
+ y3 = 90,
+ y4 = 80;
+ * bezier(x1, y1, x2, y2, x3, y3, x4, y4);
+ * fill(255);
+ * let steps = 10;
+ * for (let i = 0; i <= steps; i++) {
+ * let t = i / steps;
+ * let x = bezierPoint(x1, x2, x3, x4, t);
+ * let y = bezierPoint(y1, y2, y3, y4, t);
+ * circle(x, y, 5);
+ * }
+ *
+ *
+ * noFill();
+ * bezier(85, 20, 10, 10, 90, 90, 15, 80);
+ * let steps = 6;
+ * fill(255);
+ * for (let i = 0; i <= steps; i++) {
+ * let t = i / steps;
+ * // Get the location of the point
+ * let x = bezierPoint(85, 10, 90, 15, t);
+ * let y = bezierPoint(20, 10, 90, 80, t);
+ * // Get the tangent points
+ * let tx = bezierTangent(85, 10, 90, 15, t);
+ * let ty = bezierTangent(20, 10, 90, 80, t);
+ * // Calculate an angle from the tangent points
+ * let a = atan2(ty, tx);
+ * a += PI;
+ * stroke(255, 102, 0);
+ * line(x, y, cos(a) * 30 + x, sin(a) * 30 + y);
+ * // The following line of code makes a line
+ * // inverse of the above line
+ * //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y);
+ * stroke(0);
+ * ellipse(x, y, 5, 5);
+ * }
+ *
+ *
+ * noFill();
+ * bezier(85, 20, 10, 10, 90, 90, 15, 80);
+ * stroke(255, 102, 0);
+ * let steps = 16;
+ * for (let i = 0; i <= steps; i++) {
+ * let t = i / steps;
+ * let x = bezierPoint(85, 10, 90, 15, t);
+ * let y = bezierPoint(20, 10, 90, 80, t);
+ * let tx = bezierTangent(85, 10, 90, 15, t);
+ * let ty = bezierTangent(20, 10, 90, 80, t);
+ * let a = atan2(ty, tx);
+ * a -= HALF_PI;
+ * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y);
+ * }
+ *
+ *
+ * noFill();
+ * stroke(255, 102, 0);
+ * curve(5, 26, 5, 26, 73, 24, 73, 61);
+ * stroke(0);
+ * curve(5, 26, 73, 24, 73, 61, 15, 65);
+ * stroke(255, 102, 0);
+ * curve(73, 24, 73, 61, 15, 65, 15, 65);
+ *
+ *
+ * // Define the curve points as JavaScript objects
+ * let p1 = { x: 5, y: 26 };
+ * let p2 = { x: 73, y: 24 };
+ * let p3 = { x: 73, y: 61 };
+ * let p4 = { x: 15, y: 65 };
+ * noFill();
+ * stroke(255, 102, 0);
+ * curve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
+ * stroke(0);
+ * curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
+ * stroke(255, 102, 0);
+ * curve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y);
+ *
+ *
+ * noFill();
+ * stroke(255, 102, 0);
+ * curve(5, 26, 0, 5, 26, 0, 73, 24, 0, 73, 61, 0);
+ * stroke(0);
+ * curve(5, 26, 0, 73, 24, 0, 73, 61, 0, 15, 65, 0);
+ * stroke(255, 102, 0);
+ * curve(73, 24, 0, 73, 61, 0, 15, 65, 0, 15, 65, 0);
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * curveDetail(5);
+ * }
+ * function draw() {
+ * background(200);
+ *
+ * curve(250, 600, 0, -30, 40, 0, 30, 30, 0, -250, 600, 0);
+ * }
+ *
+ *
+ * // Move the mouse left and right to see the curve change
+ * function setup() {
+ * createCanvas(100, 100);
+ * noFill();
+ * }
+ *
+ * function draw() {
+ * background(204);
+ * let t = map(mouseX, 0, width, -5, 5);
+ * curveTightness(t);
+ * beginShape();
+ * curveVertex(10, 26);
+ * curveVertex(10, 26);
+ * curveVertex(83, 24);
+ * curveVertex(83, 61);
+ * curveVertex(25, 65);
+ * curveVertex(25, 65);
+ * endShape();
+ * }
+ *
+ *
+ * noFill();
+ * curve(5, 26, 5, 26, 73, 24, 73, 61);
+ * curve(5, 26, 73, 24, 73, 61, 15, 65);
+ * fill(255);
+ * ellipseMode(CENTER);
+ * let steps = 6;
+ * for (let i = 0; i <= steps; i++) {
+ * let t = i / steps;
+ * let x = curvePoint(5, 5, 73, 73, t);
+ * let y = curvePoint(26, 26, 24, 61, t);
+ * ellipse(x, y, 5, 5);
+ * x = curvePoint(5, 73, 73, 15, t);
+ * y = curvePoint(26, 24, 61, 65, t);
+ * ellipse(x, y, 5, 5);
+ * }
+ *
+ *
+ * noFill();
+ * curve(5, 26, 73, 24, 73, 61, 15, 65);
+ * let steps = 6;
+ * for (let i = 0; i <= steps; i++) {
+ * let t = i / steps;
+ * let x = curvePoint(5, 73, 73, 15, t);
+ * let y = curvePoint(26, 24, 61, 65, t);
+ * //ellipse(x, y, 5, 5);
+ * let tx = curveTangent(5, 73, 73, 15, t);
+ * let ty = curveTangent(26, 24, 61, 65, t);
+ * let a = atan2(ty, tx);
+ * a -= PI / 2.0;
+ * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y);
+ * }
+ *
+ *
+ * translate(50, 50);
+ * stroke(255, 0, 0);
+ * beginShape();
+ * // Exterior part of shape, clockwise winding
+ * vertex(-40, -40);
+ * vertex(40, -40);
+ * vertex(40, 40);
+ * vertex(-40, 40);
+ * // Interior part of shape, counter-clockwise winding
+ * beginContour();
+ * vertex(-20, -20);
+ * vertex(-20, 20);
+ * vertex(20, 20);
+ * vertex(20, -20);
+ * endContour();
+ * endShape(CLOSE);
+ *
+ *
+ * beginShape();
+ * vertex(30, 20);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * vertex(30, 75);
+ * endShape(CLOSE);
+ *
+ *
+ * beginShape(POINTS);
+ * vertex(30, 20);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * vertex(30, 75);
+ * endShape();
+ *
+ *
+ * beginShape(LINES);
+ * vertex(30, 20);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * vertex(30, 75);
+ * endShape();
+ *
+ *
+ * noFill();
+ * beginShape();
+ * vertex(30, 20);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * vertex(30, 75);
+ * endShape();
+ *
+ *
+ * noFill();
+ * beginShape();
+ * vertex(30, 20);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * vertex(30, 75);
+ * endShape(CLOSE);
+ *
+ *
+ * beginShape(TRIANGLES);
+ * vertex(30, 75);
+ * vertex(40, 20);
+ * vertex(50, 75);
+ * vertex(60, 20);
+ * vertex(70, 75);
+ * vertex(80, 20);
+ * endShape();
+ *
+ *
+ * beginShape(TRIANGLE_STRIP);
+ * vertex(30, 75);
+ * vertex(40, 20);
+ * vertex(50, 75);
+ * vertex(60, 20);
+ * vertex(70, 75);
+ * vertex(80, 20);
+ * vertex(90, 75);
+ * endShape();
+ *
+ *
+ * beginShape(TRIANGLE_FAN);
+ * vertex(57.5, 50);
+ * vertex(57.5, 15);
+ * vertex(92, 50);
+ * vertex(57.5, 85);
+ * vertex(22, 50);
+ * vertex(57.5, 15);
+ * endShape();
+ *
+ *
+ * beginShape(QUADS);
+ * vertex(30, 20);
+ * vertex(30, 75);
+ * vertex(50, 75);
+ * vertex(50, 20);
+ * vertex(65, 20);
+ * vertex(65, 75);
+ * vertex(85, 75);
+ * vertex(85, 20);
+ * endShape();
+ *
+ *
+ * beginShape(QUAD_STRIP);
+ * vertex(30, 20);
+ * vertex(30, 75);
+ * vertex(50, 20);
+ * vertex(50, 75);
+ * vertex(65, 20);
+ * vertex(65, 75);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * endShape();
+ *
+ *
+ * beginShape();
+ * vertex(20, 20);
+ * vertex(40, 20);
+ * vertex(40, 40);
+ * vertex(60, 40);
+ * vertex(60, 60);
+ * vertex(20, 60);
+ * endShape(CLOSE);
+ *
+ *
+ * noFill();
+ * beginShape();
+ * vertex(30, 20);
+ * bezierVertex(80, 0, 80, 75, 30, 75);
+ * endShape();
+ *
+ *
+ * beginShape();
+ * vertex(30, 20);
+ * bezierVertex(80, 0, 80, 75, 30, 75);
+ * bezierVertex(50, 80, 60, 25, 30, 20);
+ * endShape();
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * setAttributes('antialias', true);
+ * }
+ * function draw() {
+ * orbitControl();
+ * background(50);
+ * strokeWeight(4);
+ * stroke(255);
+ * point(-25, 30);
+ * point(25, 30);
+ * point(25, -30);
+ * point(-25, -30);
+ *
+ * strokeWeight(1);
+ * noFill();
+ *
+ * beginShape();
+ * vertex(-25, 30);
+ * bezierVertex(25, 30, 25, -30, -25, -30);
+ * endShape();
+ *
+ * beginShape();
+ * vertex(-25, 30, 20);
+ * bezierVertex(25, 30, 20, 25, -30, 20, -25, -30, 20);
+ * endShape();
+ * }
+ *
+ *
+ * strokeWeight(5);
+ * point(84, 91);
+ * point(68, 19);
+ * point(21, 17);
+ * point(32, 91);
+ * strokeWeight(1);
+ *
+ * noFill();
+ * beginShape();
+ * curveVertex(84, 91);
+ * curveVertex(84, 91);
+ * curveVertex(68, 19);
+ * curveVertex(21, 17);
+ * curveVertex(32, 91);
+ * curveVertex(32, 91);
+ * endShape();
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * setAttributes('antialias', true);
+ * }
+ * function draw() {
+ * orbitControl();
+ * background(50);
+ * strokeWeight(4);
+ * stroke(255);
+ *
+ * point(-25, 25);
+ * point(-25, 25);
+ * point(-25, -25);
+ * point(25, -25);
+ * point(25, 25);
+ * point(25, 25);
+ *
+ * strokeWeight(1);
+ * noFill();
+ *
+ * beginShape();
+ * curveVertex(-25, 25);
+ * curveVertex(-25, 25);
+ * curveVertex(-25, -25);
+ * curveVertex(25, -25);
+ * curveVertex(25, 25);
+ * curveVertex(25, 25);
+ * endShape();
+ *
+ * beginShape();
+ * curveVertex(-25, 25, 20);
+ * curveVertex(-25, 25, 20);
+ * curveVertex(-25, -25, 20);
+ * curveVertex(25, -25, 20);
+ * curveVertex(25, 25, 20);
+ * curveVertex(25, 25, 20);
+ * endShape();
+ * }
+ *
+ *
+ * translate(50, 50);
+ * stroke(255, 0, 0);
+ * beginShape();
+ * // Exterior part of shape, clockwise winding
+ * vertex(-40, -40);
+ * vertex(40, -40);
+ * vertex(40, 40);
+ * vertex(-40, 40);
+ * // Interior part of shape, counter-clockwise winding
+ * beginContour();
+ * vertex(-20, -20);
+ * vertex(-20, 20);
+ * vertex(20, 20);
+ * vertex(20, -20);
+ * endContour();
+ * endShape(CLOSE);
+ *
+ *
+ * noFill();
+ *
+ * beginShape();
+ * vertex(20, 20);
+ * vertex(45, 20);
+ * vertex(45, 80);
+ * endShape(CLOSE);
+ *
+ * beginShape();
+ * vertex(50, 20);
+ * vertex(75, 20);
+ * vertex(75, 80);
+ * endShape();
+ *
+ *
+ * strokeWeight(5);
+ * point(20, 20);
+ * point(80, 20);
+ * point(50, 50);
+ *
+ * noFill();
+ * strokeWeight(1);
+ * beginShape();
+ * vertex(20, 20);
+ * quadraticVertex(80, 20, 50, 50);
+ * endShape();
+ *
+ *
+ * strokeWeight(5);
+ * point(20, 20);
+ * point(80, 20);
+ * point(50, 50);
+ *
+ * point(20, 80);
+ * point(80, 80);
+ * point(80, 60);
+ *
+ * noFill();
+ * strokeWeight(1);
+ * beginShape();
+ * vertex(20, 20);
+ * quadraticVertex(80, 20, 50, 50);
+ * quadraticVertex(20, 80, 80, 80);
+ * vertex(80, 60);
+ * endShape();
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * setAttributes('antialias', true);
+ * }
+ * function draw() {
+ * orbitControl();
+ * background(50);
+ * strokeWeight(4);
+ * stroke(255);
+ *
+ * point(-35, -35);
+ * point(35, -35);
+ * point(0, 0);
+ * point(-35, 35);
+ * point(35, 35);
+ * point(35, 10);
+ *
+ * strokeWeight(1);
+ * noFill();
+ *
+ * beginShape();
+ * vertex(-35, -35);
+ * quadraticVertex(35, -35, 0, 0);
+ * quadraticVertex(-35, 35, 35, 35);
+ * vertex(35, 10);
+ * endShape();
+ *
+ * beginShape();
+ * vertex(-35, -35, 20);
+ * quadraticVertex(35, -35, 20, 0, 0, 20);
+ * quadraticVertex(-35, 35, 20, 35, 35, 20);
+ * vertex(35, 10, 20);
+ * endShape();
+ * }
+ *
+ *
+ * strokeWeight(3);
+ * beginShape(POINTS);
+ * vertex(30, 20);
+ * vertex(85, 20);
+ * vertex(85, 75);
+ * vertex(30, 75);
+ * endShape();
+ *
+ *
+ * createCanvas(100, 100, WEBGL);
+ * background(240, 240, 240);
+ * fill(237, 34, 93);
+ * noStroke();
+ * beginShape();
+ * vertex(0, 35);
+ * vertex(35, 0);
+ * vertex(0, -35);
+ * vertex(-35, 0);
+ * endShape();
+ *
+ *
+ * createCanvas(100, 100, WEBGL);
+ * background(240, 240, 240);
+ * fill(237, 34, 93);
+ * noStroke();
+ * beginShape();
+ * vertex(-10, 10);
+ * vertex(0, 35);
+ * vertex(10, 10);
+ * vertex(35, 0);
+ * vertex(10, -8);
+ * vertex(0, -35);
+ * vertex(-10, -8);
+ * vertex(-35, 0);
+ * endShape();
+ *
+ *
+ * strokeWeight(3);
+ * stroke(237, 34, 93);
+ * beginShape(LINES);
+ * vertex(10, 35);
+ * vertex(90, 35);
+ * vertex(10, 65);
+ * vertex(90, 65);
+ * vertex(35, 10);
+ * vertex(35, 90);
+ * vertex(65, 10);
+ * vertex(65, 90);
+ * endShape();
+ *
+ *
+ * // Click to change the number of sides.
+ * // In WebGL mode, custom shapes will only
+ * // display hollow fill sections when
+ * // all calls to vertex() use the same z-value.
+ *
+ * let sides = 3;
+ * let angle, px, py;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * setAttributes('antialias', true);
+ * fill(237, 34, 93);
+ * strokeWeight(3);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateX(frameCount * 0.01);
+ * rotateZ(frameCount * 0.01);
+ * ngon(sides, 0, 0, 80);
+ * }
+ *
+ * function mouseClicked() {
+ * if (sides > 6) {
+ * sides = 3;
+ * } else {
+ * sides++;
+ * }
+ * }
+ *
+ * function ngon(n, x, y, d) {
+ * beginShape(TESS);
+ * for (let i = 0; i < n + 1; i++) {
+ * angle = TWO_PI / n * i;
+ * px = x + sin(angle) * d / 2;
+ * py = y - cos(angle) * d / 2;
+ * vertex(px, py, 0);
+ * }
+ * for (let i = 0; i < n + 1; i++) {
+ * angle = TWO_PI / n * i;
+ * px = x + sin(angle) * d / 4;
+ * py = y - cos(angle) * d / 4;
+ * vertex(px, py, 0);
+ * }
+ * endShape();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * noLoop();
+ * }
+
+ * function draw() {
+ * line(10, 10, 90, 90);
+ * }
+ *
+ *
+ * let x = 0;
+ * function setup() {
+ * createCanvas(100, 100);
+ * }
+ *
+ * function draw() {
+ * background(204);
+ * x = x + 0.1;
+ * if (x > width) {
+ * x = 0;
+ * }
+ * line(x, 0, x, height);
+ * }
+ *
+ * function mousePressed() {
+ * noLoop();
+ * }
+ *
+ * function mouseReleased() {
+ * loop();
+ * }
+ *
+ *
+ * let x = 0;
+ * function setup() {
+ * createCanvas(100, 100);
+ * noLoop();
+ * }
+ *
+ * function draw() {
+ * background(204);
+ * x = x + 0.1;
+ * if (x > width) {
+ * x = 0;
+ * }
+ * line(x, 0, x, height);
+ * }
+ *
+ * function mousePressed() {
+ * loop();
+ * }
+ *
+ * function mouseReleased() {
+ * noLoop();
+ * }
+ *
+ *
+ * let checkbox, button, colBG, colFill;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * button = createButton('Colorize if loop()');
+ * button.position(0, 120);
+ * button.mousePressed(changeBG);
+ *
+ * checkbox = createCheckbox('loop()', true);
+ * checkbox.changed(checkLoop);
+ *
+ * colBG = color(0);
+ * colFill = color(255);
+ * }
+ *
+ * function changeBG() {
+ * if (isLooping()) {
+ * colBG = color(random(255), random(255), random(255));
+ * colFill = color(random(255), random(255), random(255));
+ * }
+ * }
+ *
+ * function checkLoop() {
+ * if (this.checked()) {
+ * loop();
+ * } else {
+ * noLoop();
+ * }
+ * }
+ *
+ * function draw() {
+ * background(colBG);
+ * fill(colFill);
+ * ellipse(frameCount % width, height / 2, 50);
+ * }
+ *
+ *
+ * ellipse(0, 50, 33, 33); // Left circle
+ *
+ * push(); // Start a new drawing state
+ * strokeWeight(10);
+ * fill(204, 153, 0);
+ * translate(50, 0);
+ * ellipse(0, 50, 33, 33); // Middle circle
+ * pop(); // Restore original state
+ *
+ * ellipse(100, 50, 33, 33); // Right circle
+ *
+ *
+ * ellipse(0, 50, 33, 33); // Left circle
+ *
+ * push(); // Start a new drawing state
+ * strokeWeight(10);
+ * fill(204, 153, 0);
+ * ellipse(33, 50, 33, 33); // Left-middle circle
+ *
+ * push(); // Start another new drawing state
+ * stroke(0, 102, 153);
+ * ellipse(66, 50, 33, 33); // Right-middle circle
+ * pop(); // Restore previous state
+ *
+ * pop(); // Restore original state
+ *
+ * ellipse(100, 50, 33, 33); // Right circle
+ *
+ *
+ * ellipse(0, 50, 33, 33); // Left circle
+ *
+ * push(); // Start a new drawing state
+ * translate(50, 0);
+ * strokeWeight(10);
+ * fill(204, 153, 0);
+ * ellipse(0, 50, 33, 33); // Middle circle
+ * pop(); // Restore original state
+ *
+ * ellipse(100, 50, 33, 33); // Right circle
+ *
+ *
+ * ellipse(0, 50, 33, 33); // Left circle
+ *
+ * push(); // Start a new drawing state
+ * strokeWeight(10);
+ * fill(204, 153, 0);
+ * ellipse(33, 50, 33, 33); // Left-middle circle
+ *
+ * push(); // Start another new drawing state
+ * stroke(0, 102, 153);
+ * ellipse(66, 50, 33, 33); // Right-middle circle
+ * pop(); // Restore previous state
+ *
+ * pop(); // Restore original state
+ *
+ * ellipse(100, 50, 33, 33); // Right circle
+ *
+ *
+ * let x = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * noLoop();
+ * }
+ *
+ * function draw() {
+ * background(204);
+ * line(x, 0, x, height);
+ * }
+ *
+ * function mousePressed() {
+ * x += 1;
+ * redraw();
+ * }
+ *
+ *
+ * let x = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * noLoop();
+ * }
+ *
+ * function draw() {
+ * background(204);
+ * x += 1;
+ * line(x, 0, x, height);
+ * }
+ *
+ * function mousePressed() {
+ * redraw(5);
+ * }
+ *
+ *
+ * const s = p => {
+ * let x = 100;
+ * let y = 100;
+ *
+ * p.setup = function() {
+ * p.createCanvas(700, 410);
+ * };
+ *
+ * p.draw = function() {
+ * p.background(0);
+ * p.fill(255);
+ * p.rect(x, y, 50, 50);
+ * };
+ * };
+ *
+ * new p5(s); // invoke p5
+ *
+ * function setup() {
+ * frameRate(10);
+ * rectMode(CENTER);
+ * }
+ *
+ * function draw() {
+ * let step = frameCount % 20;
+ * background(200);
+ * // Equivalent to translate(x, y);
+ * applyMatrix(1, 0, 0, 1, 40 + step, 50);
+ * rect(0, 0, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * frameRate(10);
+ * rectMode(CENTER);
+ * }
+ *
+ * function draw() {
+ * let step = frameCount % 20;
+ * background(200);
+ * translate(50, 50);
+ * // Equivalent to scale(x, y);
+ * applyMatrix(1 / step, 0, 0, 1 / step, 0, 0);
+ * rect(0, 0, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * frameRate(10);
+ * rectMode(CENTER);
+ * }
+ *
+ * function draw() {
+ * let step = frameCount % 20;
+ * let angle = map(step, 0, 20, 0, TWO_PI);
+ * let cos_a = cos(angle);
+ * let sin_a = sin(angle);
+ * background(200);
+ * translate(50, 50);
+ * // Equivalent to rotate(angle);
+ * applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0);
+ * rect(0, 0, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * frameRate(10);
+ * rectMode(CENTER);
+ * }
+ *
+ * function draw() {
+ * let step = frameCount % 20;
+ * let angle = map(step, 0, 20, -PI / 4, PI / 4);
+ * background(200);
+ * translate(50, 50);
+ * // equivalent to shearX(angle);
+ * let shear_factor = 1 / tan(PI / 2 - angle);
+ * applyMatrix(1, 0, shear_factor, 1, 0, 0);
+ * rect(0, 0, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * noFill();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateY(PI / 6);
+ * stroke(153);
+ * box(35);
+ * let rad = millis() / 1000;
+ * // Set rotation angles
+ * let ct = cos(rad);
+ * let st = sin(rad);
+ * // Matrix for rotation around the Y axis
+ * // prettier-ignore
+ * applyMatrix( ct, 0.0, st, 0.0,
+ * 0.0, 1.0, 0.0, 0.0,
+ * -st, 0.0, ct, 0.0,
+ * 0.0, 0.0, 0.0, 1.0);
+ * stroke(255);
+ * box(50);
+ * }
+ *
+ *
+ * function draw() {
+ * background(200);
+ * let testMatrix = [1, 0, 0, 1, 0, 0];
+ * applyMatrix(testMatrix);
+ * rect(0, 0, 50, 50);
+ * }
+ *
+ *
+ * translate(50, 50);
+ * applyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0);
+ * rect(0, 0, 20, 20);
+ * // Note that the translate is also reset.
+ * resetMatrix();
+ * rect(0, 0, 20, 20);
+ *
+ *
+ * translate(width / 2, height / 2);
+ * rotate(PI / 3.0);
+ * rect(-26, -26, 52, 52);
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(255);
+ * rotateX(millis() / 1000);
+ * box();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(255);
+ * rotateY(millis() / 1000);
+ * box();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(255);
+ * rotateZ(millis() / 1000);
+ * box();
+ * }
+ *
+ *
+ * rect(30, 20, 50, 50);
+ * scale(0.5);
+ * rect(30, 20, 50, 50);
+ *
+ *
+ * rect(30, 20, 50, 50);
+ * scale(0.5, 1.3);
+ * rect(30, 20, 50, 50);
+ *
+ *
+ * translate(width / 4, height / 4);
+ * shearX(PI / 4.0);
+ * rect(0, 0, 30, 30);
+ *
+ *
+ * translate(width / 4, height / 4);
+ * shearY(PI / 4.0);
+ * rect(0, 0, 30, 30);
+ *
+ *
+ * translate(30, 20);
+ * rect(0, 0, 55, 55);
+ *
+ *
+ * rect(0, 0, 55, 55); // Draw rect at original 0,0
+ * translate(30, 20);
+ * rect(0, 0, 55, 55); // Draw rect at new 0,0
+ * translate(14, 14);
+ * rect(0, 0, 55, 55); // Draw rect at new 0,0
+ *
+ *
+ * function draw() {
+ * background(200);
+ * rectMode(CENTER);
+ * translate(width / 2, height / 2);
+ * translate(p5.Vector.fromAngle(millis() / 1000, 40));
+ * rect(0, 0, 20, 20);
+ * }
+ *
+ *
+ * // Type to change the letter in the
+ * // center of the canvas.
+ * // If you reload the page, it will
+ * // still display the last key you entered
+ *
+ * let myText;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * myText = getItem('myText');
+ * if (myText === null) {
+ * myText = '';
+ * }
+ * }
+ *
+ * function draw() {
+ * textSize(40);
+ * background(255);
+ * text(myText, width / 2, height / 2);
+ * }
+ *
+ * function keyPressed() {
+ * myText = key;
+ * storeItem('myText', myText);
+ * }
+ *
+ * // Click the mouse to change
+ * // the color of the background
+ * // Once you have changed the color
+ * // it will stay changed even when you
+ * // reload the page.
+ *
+ * let myColor;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * myColor = getItem('myColor');
+ * }
+ *
+ * function draw() {
+ * if (myColor !== null) {
+ * background(myColor);
+ * }
+ * }
+ *
+ * function mousePressed() {
+ * myColor = color(random(255), random(255), random(255));
+ * storeItem('myColor', myColor);
+ * }
+ *
+ * function setup() {
+ * let myNum = 10;
+ * let myBool = false;
+ * storeItem('myNum', myNum);
+ * storeItem('myBool', myBool);
+ * print(getItem('myNum')); // logs 10 to the console
+ * print(getItem('myBool')); // logs false to the console
+ * clearStorage();
+ * print(getItem('myNum')); // logs null to the console
+ * print(getItem('myBool')); // logs null to the console
+ * }
+ *
+ * function setup() {
+ * let myVar = 10;
+ * storeItem('myVar', myVar);
+ * print(getItem('myVar')); // logs 10 to the console
+ * removeItem('myVar');
+ * print(getItem('myVar')); // logs null to the console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * print(myDictionary.hasKey('p5')); // logs true to console
+ *
+ * let anotherDictionary = createStringDict({ happy: 'coding' });
+ * print(anotherDictionary.hasKey('happy')); // logs true to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(100, 42);
+ * print(myDictionary.hasKey(100)); // logs true to console
+ *
+ * let anotherDictionary = createNumberDict({ 200: 84 });
+ * print(anotherDictionary.hasKey(200)); // logs true to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(1, 10);
+ * myDictionary.create(2, 20);
+ * myDictionary.create(3, 30);
+ * print(myDictionary.size()); // logs 3 to the console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * print(myDictionary.hasKey('p5')); // logs true to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * let myValue = myDictionary.get('p5');
+ * print(myValue === 'js'); // logs true to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.set('p5', 'JS');
+ * myDictionary.print(); // logs "key: p5 - value: JS" to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.create('happy', 'coding');
+ * myDictionary.print();
+ * // above logs "key: p5 - value: js, key: happy - value: coding" to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * print(myDictionary.hasKey('p5')); // prints 'true'
+ * myDictionary.clear();
+ * print(myDictionary.hasKey('p5')); // prints 'false'
+ * }
+ *
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.create('happy', 'coding');
+ * myDictionary.print();
+ * // above logs "key: p5 - value: js, key: happy - value: coding" to console
+ * myDictionary.remove('p5');
+ * myDictionary.print();
+ * // above logs "key: happy value: coding" to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.create('happy', 'coding');
+ * myDictionary.print();
+ * // above logs "key: p5 - value: js, key: happy - value: coding" to console
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * createStringDict({
+ * john: 1940,
+ * paul: 1942,
+ * george: 1943,
+ * ringo: 1940
+ * }).saveTable('beatles');
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * createStringDict({
+ * john: 1940,
+ * paul: 1942,
+ * george: 1943,
+ * ringo: 1940
+ * }).saveJSON('beatles');
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 5);
+ * myDictionary.add(2, 2);
+ * print(myDictionary.get(2)); // logs 7 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 5);
+ * myDictionary.sub(2, 2);
+ * print(myDictionary.get(2)); // logs 3 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 4);
+ * myDictionary.mult(2, 2);
+ * print(myDictionary.get(2)); // logs 8 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 8);
+ * myDictionary.div(2, 2);
+ * print(myDictionary.get(2)); // logs 4 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
+ * let lowestValue = myDictionary.minValue(); // value is -10
+ * print(lowestValue);
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
+ * let highestValue = myDictionary.maxValue(); // value is 3
+ * print(highestValue);
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
+ * let lowestKey = myDictionary.minKey(); // value is 1.2
+ * print(lowestKey);
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
+ * let highestKey = myDictionary.maxKey(); // value is 4
+ * print(highestKey);
+ * }
+ *
+ * function setup() {
+ * createCanvas(50, 50);
+ * background(30);
+ * // move canvas down and right
+ * select('canvas').position(10, 30);
+ * }
+ *
+ * // select using ID
+ * let a = select('#container');
+ * let b = select('#beep', '#container');
+ * let c;
+ * if (a) {
+ * // select using class
+ * c = select('.boop', a);
+ * }
+ * // select using CSS selector string
+ * let d = select('#container #bleep');
+ * let e = select('#container p');
+ * [a, b, c, d, e]; // unused
+ *
+ * function setup() {
+ * createButton('btn');
+ * createButton('2nd btn');
+ * createButton('3rd btn');
+ * let buttons = selectAll('button');
+ *
+ * for (let i = 0; i < 3; i++) {
+ * buttons[i].size(100);
+ * buttons[i].position(0, i * 30);
+ * }
+ * }
+ *
+ * // these are all valid calls to selectAll()
+ * let a = selectAll('.beep');
+ * a = selectAll('div');
+ * a = selectAll('button', '#container');
+ *
+ * let b = createDiv();
+ * b.id('container');
+ * let c = select('#container');
+ * a = selectAll('p', c);
+ * a = selectAll('#container p');
+ *
+ * let d = document.getElementById('container');
+ * a = selectAll('.boop', d);
+ * a = selectAll('#container .boop');
+ * console.log(a);
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background('grey');
+ * let div = createDiv('this is some text');
+ * let p = createP('this is a paragraph');
+ * div.style('font-size', '16px');
+ * p.style('font-size', '16px');
+ * }
+ * function mousePressed() {
+ * removeElements(); // this will remove the div and p, not canvas
+ * }
+ *
+ * let sel;
+ *
+ * function setup() {
+ * textAlign(CENTER);
+ * background(200);
+ * sel = createSelect();
+ * sel.position(10, 10);
+ * sel.option('pear');
+ * sel.option('kiwi');
+ * sel.option('grape');
+ * sel.changed(mySelectEvent);
+ * }
+ *
+ * function mySelectEvent() {
+ * let item = sel.value();
+ * background(200);
+ * text("it's a " + item + '!', 50, 50);
+ * }
+ *
+ * let checkbox;
+ * let cnv;
+ *
+ * function setup() {
+ * checkbox = createCheckbox(' fill');
+ * checkbox.changed(changeFill);
+ * cnv = createCanvas(100, 100);
+ * cnv.position(0, 30);
+ * noFill();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * ellipse(50, 50, 50, 50);
+ * }
+ *
+ * function changeFill() {
+ * if (checkbox.checked()) {
+ * fill(0);
+ * } else {
+ * noFill();
+ * }
+ * }
+ *
+ * // Open your console to see the output
+ * function setup() {
+ * createCanvas(100, 100);
+ * background('grey');
+ * let inp = createInput('');
+ * inp.position(0, 0);
+ * inp.size(100);
+ * inp.input(myInputEvent);
+ * }
+ *
+ * function myInputEvent() {
+ * console.log('you are typing: ', this.value());
+ * }
+ *
+ * let div = createDiv('this is some text');
+ * div.style('font-size', '16px');
+ * div.position(10, 0);
+ *
+ * let p = createP('this is some text');
+ * p.style('font-size', '16px');
+ * p.position(10, 0);
+ *
+ * let span = createSpan('this is some text');
+ * span.position(0, 0);
+ *
+ * let img = createImg(
+ * 'https://p5js.org/assets/img/asterisk-01.png',
+ * 'the p5 magenta asterisk'
+ * );
+ * img.position(0, -10);
+ *
+ * let a = createA('http://p5js.org/', 'this is a link');
+ * a.position(0, 0);
+ *
+ * let slider;
+ * function setup() {
+ * slider = createSlider(0, 255, 100);
+ * slider.position(10, 10);
+ * slider.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * let val = slider.value();
+ * background(val);
+ * }
+ *
+ * let slider;
+ * function setup() {
+ * colorMode(HSB);
+ * slider = createSlider(0, 360, 60, 40);
+ * slider.position(10, 10);
+ * slider.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * let val = slider.value();
+ * background(val, 100, 100, 1);
+ * }
+ *
+ * let button;
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(0);
+ * button = createButton('click me');
+ * button.position(0, 0);
+ * button.mousePressed(changeBG);
+ * }
+ *
+ * function changeBG() {
+ * let val = random(255);
+ * background(val);
+ * }
+ *
+ * let checkbox;
+ *
+ * function setup() {
+ * checkbox = createCheckbox('label', false);
+ * checkbox.changed(myCheckedEvent);
+ * }
+ *
+ * function myCheckedEvent() {
+ * if (this.checked()) {
+ * console.log('Checking!');
+ * } else {
+ * console.log('Unchecking!');
+ * }
+ * }
+ *
+ * let sel;
+ *
+ * function setup() {
+ * textAlign(CENTER);
+ * background(200);
+ * sel = createSelect();
+ * sel.position(10, 10);
+ * sel.option('pear');
+ * sel.option('kiwi');
+ * sel.option('grape');
+ * sel.selected('kiwi');
+ * sel.changed(mySelectEvent);
+ * }
+ *
+ * function mySelectEvent() {
+ * let item = sel.value();
+ * background(200);
+ * text('It is a ' + item + '!', 50, 50);
+ * }
+ *
+ * let sel;
+ *
+ * function setup() {
+ * textAlign(CENTER);
+ * background(200);
+ * sel = createSelect();
+ * sel.position(10, 10);
+ * sel.option('oil');
+ * sel.option('milk');
+ * sel.option('bread');
+ * sel.disable('milk');
+ * }
+ *
+ * let radio;
+ *
+ * function setup() {
+ * radio = createRadio();
+ * radio.option('black');
+ * radio.option('white');
+ * radio.option('gray');
+ * radio.style('width', '60px');
+ * textAlign(CENTER);
+ * fill(255, 0, 0);
+ * }
+ *
+ * function draw() {
+ * let val = radio.value();
+ * background(val);
+ * text(val, width / 2, height / 2);
+ * }
+ *
+ * let radio;
+ *
+ * function setup() {
+ * radio = createRadio();
+ * radio.option(1, 'apple');
+ * radio.option(2, 'bread');
+ * radio.option(3, 'juice');
+ * radio.style('width', '30px');
+ * textAlign(CENTER);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * let val = radio.value();
+ * if (val) {
+ * text('item cost is $' + val, width / 2, height / 2);
+ * }
+ * }
+ *
+ * let colorPicker;
+ * function setup() {
+ * createCanvas(100, 100);
+ * colorPicker = createColorPicker('#ed225d');
+ * colorPicker.position(0, height + 5);
+ * }
+ *
+ * function draw() {
+ * background(colorPicker.color());
+ * }
+ *
+ * let inp1, inp2;
+ * function setup() {
+ * createCanvas(100, 100);
+ * background('grey');
+ * inp1 = createColorPicker('#ff0000');
+ * inp1.position(0, height + 5);
+ * inp1.input(setShade1);
+ * inp2 = createColorPicker(color('yellow'));
+ * inp2.position(0, height + 30);
+ * inp2.input(setShade2);
+ * setMidShade();
+ * }
+ *
+ * function setMidShade() {
+ * // Finding a shade between the two
+ * let commonShade = lerpColor(inp1.color(), inp2.color(), 0.5);
+ * fill(commonShade);
+ * rect(20, 20, 60, 60);
+ * }
+ *
+ * function setShade1() {
+ * setMidShade();
+ * console.log('You are choosing shade 1 to be : ', this.value());
+ * }
+ * function setShade2() {
+ * setMidShade();
+ * console.log('You are choosing shade 2 to be : ', this.value());
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background('grey');
+ * let inp = createInput('');
+ * inp.position(0, 0);
+ * inp.size(100);
+ * inp.input(myInputEvent);
+ * }
+ *
+ * function myInputEvent() {
+ * console.log('you are typing: ', this.value());
+ * }
+ *
+ * let input;
+ * let img;
+ *
+ * function setup() {
+ * input = createFileInput(handleFile);
+ * input.position(0, 0);
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * if (img) {
+ * image(img, 0, 0, width, height);
+ * }
+ * }
+ *
+ * function handleFile(file) {
+ * print(file);
+ * if (file.type === 'image') {
+ * img = createImg(file.data, '');
+ * img.hide();
+ * } else {
+ * img = null;
+ * }
+ * }
+ *
+ * let vid;
+ * function setup() {
+ * noCanvas();
+ *
+ * vid = createVideo(
+ * ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'],
+ * vidLoad
+ * );
+ *
+ * vid.size(100, 100);
+ * }
+ *
+ * // This function is called when the video loads
+ * function vidLoad() {
+ * vid.loop();
+ * vid.volume(0);
+ * }
+ *
+ * let ele;
+ * function setup() {
+ * ele = createAudio('assets/beat.mp3');
+ *
+ * // here we set the element to autoplay
+ * // The element will play as soon
+ * // as it is able to do so.
+ * ele.autoplay(true);
+ * }
+ *
+ * let capture;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * capture = createCapture(VIDEO);
+ * capture.hide();
+ * }
+ *
+ * function draw() {
+ * image(capture, 0, 0, width, width * capture.height / capture.width);
+ * filter(INVERT);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(480, 120);
+ * let constraints = {
+ * video: {
+ * mandatory: {
+ * minWidth: 1280,
+ * minHeight: 720
+ * },
+ * optional: [{ maxFrameRate: 10 }]
+ * },
+ * audio: true
+ * };
+ * createCapture(constraints, function(stream) {
+ * console.log(stream);
+ * });
+ * }
+ *
+ *
+ * let capture;
+ *
+ * function setup() {
+ * createCanvas(640, 480);
+ * capture = createCapture(VIDEO);
+ * }
+ * function draw() {
+ * background(0);
+ * if (capture.loadedmetadata) {
+ * let c = capture.get(0, 0, 100, 100);
+ * image(c, 0, 0);
+ * }
+ * }
+ *
+ *
+ * let h5 = createElement('h5', 'im an h5 p5.element!');
+ * h5.style('color', '#00a1d3');
+ * h5.position(0, 0);
+ *
+ * let div = createDiv('div');
+ * div.addClass('myClass');
+ *
+ * // In this example, a class is set when the div is created
+ * // and removed when mouse is pressed. This could link up
+ * // with a CSS style rule to toggle style properties.
+ *
+ * let div;
+ *
+ * function setup() {
+ * div = createDiv('div');
+ * div.addClass('myClass');
+ * }
+ *
+ * function mousePressed() {
+ * div.removeClass('myClass');
+ * }
+ *
+ * let div;
+ *
+ * function setup() {
+ * div = createDiv('div');
+ * div.addClass('show');
+ * }
+ *
+ * function mousePressed() {
+ * if (div.hasClass('show')) {
+ * div.addClass('show');
+ * } else {
+ * div.removeClass('show');
+ * }
+ * }
+ *
+ * let div;
+ *
+ * function setup() {
+ * div = createDiv('div');
+ * div.addClass('show');
+ * }
+ *
+ * function mousePressed() {
+ * div.toggleClass('show');
+ * }
+ *
+ * let div0 = createDiv('this is the parent');
+ * let div1 = createDiv('this is the child');
+ * div0.child(div1); // use p5.Element
+ *
+ * let div0 = createDiv('this is the parent');
+ * let div1 = createDiv('this is the child');
+ * div1.id('apples');
+ * div0.child('apples'); // use id
+ *
+ * // this example assumes there is a div already on the page
+ * // with id "myChildDiv"
+ * let div0 = createDiv('this is the parent');
+ * let elt = document.getElementById('myChildDiv');
+ * div0.child(elt); // use element from page
+ *
+ * function setup() {
+ * let div = createDiv('').size(10, 10);
+ * div.style('background-color', 'orange');
+ * div.center();
+ * }
+ *
+ * let div = createDiv('').size(100, 100);
+ * div.html('hi');
+ *
+ * let div = createDiv('Hello ').size(100, 100);
+ * div.html('World', true);
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ * // positions canvas 50px to the right and 100px
+ * // below upper left corner of the window
+ * cnv.position(50, 100);
+ * }
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ * // positions canvas 50px to the right and 100px
+ * // below upper left corner of the window
+ * cnv.position(0, 0, 'fixed');
+ * }
+ *
+ * let myDiv = createDiv('I like pandas.');
+ * myDiv.style('font-size', '18px');
+ * myDiv.style('color', '#ff0000');
+ * myDiv.position(0, 0);
+ *
+ * let col = color(25, 23, 200, 50);
+ * let button = createButton('button');
+ * button.style('background-color', col);
+ * button.position(0, 0);
+ *
+ * let myDiv, fontSize;
+ * function setup() {
+ * background(200);
+ * myDiv = createDiv('I like gray.');
+ * myDiv.position(0, 0);
+ * myDiv.style('z-index', 10);
+ * }
+ *
+ * function draw() {
+ * fontSize = min(mouseX, 90);
+ * myDiv.style('font-size', fontSize + 'px');
+ * }
+ *
+ * let myDiv = createDiv('I like pandas.');
+ * myDiv.attribute('align', 'center');
+ *
+ * let button;
+ * let checkbox;
+ *
+ * function setup() {
+ * checkbox = createCheckbox('enable', true);
+ * checkbox.changed(enableButton);
+ * button = createButton('button');
+ * button.position(10, 10);
+ * }
+ *
+ * function enableButton() {
+ * if (this.checked()) {
+ * // Re-enable the button
+ * button.removeAttribute('disabled');
+ * } else {
+ * // Disable the button
+ * button.attribute('disabled', '');
+ * }
+ * }
+ *
+ * // gets the value
+ * let inp;
+ * function setup() {
+ * inp = createInput('');
+ * }
+ *
+ * function mousePressed() {
+ * print(inp.value());
+ * }
+ *
+ * // sets the value
+ * let inp;
+ * function setup() {
+ * inp = createInput('myValue');
+ * }
+ *
+ * function mousePressed() {
+ * inp.value('myValue');
+ * }
+ *
+ * let div = createDiv('div');
+ * div.style('display', 'none');
+ * div.show(); // turns display to block
+ *
+ * let div = createDiv('this is a div');
+ * div.hide();
+ *
+ * let div = createDiv('this is a div');
+ * div.size(100, 100);
+ * let img = createImg(
+ * 'assets/rockies.jpg',
+ * 'A tall mountain with a small forest and field in front of it on a sunny day',
+ * '',
+ * () => {
+ * img.size(10, AUTO);
+ * }
+ * );
+ *
+ * let myDiv = createDiv('this is some text');
+ * myDiv.remove();
+ *
+ * function setup() {
+ * let c = createCanvas(100, 100);
+ * background(200);
+ * textAlign(CENTER);
+ * text('drop file', width / 2, height / 2);
+ * c.drop(gotFile);
+ * }
+ *
+ * function gotFile(file) {
+ * background(200);
+ * text('received file:', width / 2, height / 2);
+ * text(file.name, width / 2, height / 2 + 50);
+ * }
+ *
+ * let img;
+ *
+ * function setup() {
+ * let c = createCanvas(100, 100);
+ * background(200);
+ * textAlign(CENTER);
+ * text('drop image', width / 2, height / 2);
+ * c.drop(gotFile);
+ * }
+ *
+ * function draw() {
+ * if (img) {
+ * image(img, 0, 0, width, height);
+ * }
+ * }
+ *
+ * function gotFile(file) {
+ * img = createImg(file.data, '').hide();
+ * }
+ *
+ * let ele;
+ *
+ * function setup() {
+ * background(250);
+ *
+ * //p5.MediaElement objects are usually created
+ * //by calling the createAudio(), createVideo(),
+ * //and createCapture() functions.
+ *
+ * //In this example we create
+ * //a new p5.MediaElement via createAudio().
+ * ele = createAudio('assets/beat.mp3');
+ *
+ * //We'll set up our example so that
+ * //when you click on the text,
+ * //an alert box displays the MediaElement's
+ * //src field.
+ * textAlign(CENTER);
+ * text('Click Me!', width / 2, height / 2);
+ * }
+ *
+ * function mouseClicked() {
+ * //here we test if the mouse is over the
+ * //canvas element when it's clicked
+ * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
+ * //Show our p5.MediaElement's src field
+ * alert(ele.src);
+ * }
+ * }
+ *
+ * let ele;
+ *
+ * function setup() {
+ * //p5.MediaElement objects are usually created
+ * //by calling the createAudio(), createVideo(),
+ * //and createCapture() functions.
+ *
+ * //In this example we create
+ * //a new p5.MediaElement via createAudio().
+ * ele = createAudio('assets/beat.mp3');
+ *
+ * background(250);
+ * textAlign(CENTER);
+ * text('Click to Play!', width / 2, height / 2);
+ * }
+ *
+ * function mouseClicked() {
+ * //here we test if the mouse is over the
+ * //canvas element when it's clicked
+ * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
+ * //Here we call the play() function on
+ * //the p5.MediaElement we created above.
+ * //This will start the audio sample.
+ * ele.play();
+ *
+ * background(200);
+ * text('You clicked Play!', width / 2, height / 2);
+ * }
+ * }
+ *
+ * //This example both starts
+ * //and stops a sound sample
+ * //when the user clicks the canvas
+ *
+ * //We will store the p5.MediaElement
+ * //object in here
+ * let ele;
+ *
+ * //while our audio is playing,
+ * //this will be set to true
+ * let sampleIsPlaying = false;
+ *
+ * function setup() {
+ * //Here we create a p5.MediaElement object
+ * //using the createAudio() function.
+ * ele = createAudio('assets/beat.mp3');
+ * background(200);
+ * textAlign(CENTER);
+ * text('Click to play!', width / 2, height / 2);
+ * }
+ *
+ * function mouseClicked() {
+ * //here we test if the mouse is over the
+ * //canvas element when it's clicked
+ * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
+ * background(200);
+ *
+ * if (sampleIsPlaying) {
+ * //if the sample is currently playing
+ * //calling the stop() function on
+ * //our p5.MediaElement will stop
+ * //it and reset its current
+ * //time to 0 (i.e. it will start
+ * //at the beginning the next time
+ * //you play it)
+ * ele.stop();
+ *
+ * sampleIsPlaying = false;
+ * text('Click to play!', width / 2, height / 2);
+ * } else {
+ * //loop our sound element until we
+ * //call ele.stop() on it.
+ * ele.loop();
+ *
+ * sampleIsPlaying = true;
+ * text('Click to stop!', width / 2, height / 2);
+ * }
+ * }
+ * }
+ *
+ * //This example both starts
+ * //and pauses a sound sample
+ * //when the user clicks the canvas
+ *
+ * //We will store the p5.MediaElement
+ * //object in here
+ * let ele;
+ *
+ * //while our audio is playing,
+ * //this will be set to true
+ * let sampleIsPlaying = false;
+ *
+ * function setup() {
+ * //Here we create a p5.MediaElement object
+ * //using the createAudio() function.
+ * ele = createAudio('assets/lucky_dragons.mp3');
+ * background(200);
+ * textAlign(CENTER);
+ * text('Click to play!', width / 2, height / 2);
+ * }
+ *
+ * function mouseClicked() {
+ * //here we test if the mouse is over the
+ * //canvas element when it's clicked
+ * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
+ * background(200);
+ *
+ * if (sampleIsPlaying) {
+ * //Calling pause() on our
+ * //p5.MediaElement will stop it
+ * //playing, but when we call the
+ * //loop() or play() functions
+ * //the sample will start from
+ * //where we paused it.
+ * ele.pause();
+ *
+ * sampleIsPlaying = false;
+ * text('Click to resume!', width / 2, height / 2);
+ * } else {
+ * //loop our sound element until we
+ * //call ele.pause() on it.
+ * ele.loop();
+ *
+ * sampleIsPlaying = true;
+ * text('Click to pause!', width / 2, height / 2);
+ * }
+ * }
+ * }
+ *
+ * //Clicking the canvas will loop
+ * //the audio sample until the user
+ * //clicks again to stop it
+ *
+ * //We will store the p5.MediaElement
+ * //object in here
+ * let ele;
+ *
+ * //while our audio is playing,
+ * //this will be set to true
+ * let sampleIsLooping = false;
+ *
+ * function setup() {
+ * //Here we create a p5.MediaElement object
+ * //using the createAudio() function.
+ * ele = createAudio('assets/lucky_dragons.mp3');
+ * background(200);
+ * textAlign(CENTER);
+ * text('Click to loop!', width / 2, height / 2);
+ * }
+ *
+ * function mouseClicked() {
+ * //here we test if the mouse is over the
+ * //canvas element when it's clicked
+ * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
+ * background(200);
+ *
+ * if (!sampleIsLooping) {
+ * //loop our sound element until we
+ * //call ele.stop() on it.
+ * ele.loop();
+ *
+ * sampleIsLooping = true;
+ * text('Click to stop!', width / 2, height / 2);
+ * } else {
+ * ele.stop();
+ *
+ * sampleIsLooping = false;
+ * text('Click to loop!', width / 2, height / 2);
+ * }
+ * }
+ * }
+ *
+ * //This example both starts
+ * //and stops loop of sound sample
+ * //when the user clicks the canvas
+ *
+ * //We will store the p5.MediaElement
+ * //object in here
+ * let ele;
+ * //while our audio is playing,
+ * //this will be set to true
+ * let sampleIsPlaying = false;
+ *
+ * function setup() {
+ * //Here we create a p5.MediaElement object
+ * //using the createAudio() function.
+ * ele = createAudio('assets/beat.mp3');
+ * background(200);
+ * textAlign(CENTER);
+ * text('Click to play!', width / 2, height / 2);
+ * }
+ *
+ * function mouseClicked() {
+ * //here we test if the mouse is over the
+ * //canvas element when it's clicked
+ * if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {
+ * background(200);
+ *
+ * if (sampleIsPlaying) {
+ * ele.noLoop();
+ * sampleIsPlaying = false;
+ * text('No more Loops!', width / 2, height / 2);
+ * } else {
+ * ele.loop();
+ * sampleIsPlaying = true;
+ * text('Click to stop looping!', width / 2, height / 2);
+ * }
+ * }
+ * }
+ *
+ * let videoElement;
+ * function setup() {
+ * noCanvas();
+ * videoElement = createVideo(['assets/small.mp4'], onVideoLoad);
+ * }
+ * function onVideoLoad() {
+ * // The media will play as soon as it is loaded.
+ * videoElement.autoplay();
+ * videoElement.volume(0);
+ * videoElement.size(100, 100);
+ * }
+ *
+ * let videoElement;
+ * function setup() {
+ * noCanvas();
+ * videoElement = createVideo(['assets/small.mp4'], onVideoLoad);
+ * }
+ * function onVideoLoad() {
+ * // The media will not play untill some explicitly triggered.
+ * videoElement.autoplay(false);
+ * videoElement.volume(0);
+ * videoElement.size(100, 100);
+ * }
+ *
+ * function mouseClicked() {
+ * videoElement.play();
+ * }
+ *
+ * let ele;
+ * function setup() {
+ * // p5.MediaElement objects are usually created
+ * // by calling the createAudio(), createVideo(),
+ * // and createCapture() functions.
+ * // In this example we create
+ * // a new p5.MediaElement via createAudio().
+ * ele = createAudio('assets/lucky_dragons.mp3');
+ * background(250);
+ * textAlign(CENTER);
+ * text('Click to Play!', width / 2, height / 2);
+ * }
+ * function mouseClicked() {
+ * // Here we call the volume() function
+ * // on the sound element to set its volume
+ * // Volume must be between 0.0 and 1.0
+ * ele.volume(0.2);
+ * ele.play();
+ * background(200);
+ * text('You clicked Play!', width / 2, height / 2);
+ * }
+ *
+ * let audio;
+ * let counter = 0;
+ *
+ * function loaded() {
+ * audio.play();
+ * }
+ *
+ * function setup() {
+ * audio = createAudio('assets/lucky_dragons.mp3', loaded);
+ * textAlign(CENTER);
+ * }
+ *
+ * function draw() {
+ * if (counter === 0) {
+ * background(0, 255, 0);
+ * text('volume(0.9)', width / 2, height / 2);
+ * } else if (counter === 1) {
+ * background(255, 255, 0);
+ * text('volume(0.5)', width / 2, height / 2);
+ * } else if (counter === 2) {
+ * background(255, 0, 0);
+ * text('volume(0.1)', width / 2, height / 2);
+ * }
+ * }
+ *
+ * function mousePressed() {
+ * counter++;
+ * if (counter === 0) {
+ * audio.volume(0.9);
+ * } else if (counter === 1) {
+ * audio.volume(0.5);
+ * } else if (counter === 2) {
+ * audio.volume(0.1);
+ * } else {
+ * counter = 0;
+ * audio.volume(0.9);
+ * }
+ * }
+ *
+ *
+ * //Clicking the canvas will loop
+ * //the audio sample until the user
+ * //clicks again to stop it
+ *
+ * //We will store the p5.MediaElement
+ * //object in here
+ * let ele;
+ * let button;
+ *
+ * function setup() {
+ * createCanvas(710, 400);
+ * //Here we create a p5.MediaElement object
+ * //using the createAudio() function.
+ * ele = createAudio('assets/beat.mp3');
+ * ele.loop();
+ * background(200);
+ *
+ * button = createButton('2x speed');
+ * button.position(100, 68);
+ * button.mousePressed(twice_speed);
+ *
+ * button = createButton('half speed');
+ * button.position(200, 68);
+ * button.mousePressed(half_speed);
+ *
+ * button = createButton('reverse play');
+ * button.position(300, 68);
+ * button.mousePressed(reverse_speed);
+ *
+ * button = createButton('STOP');
+ * button.position(400, 68);
+ * button.mousePressed(stop_song);
+ *
+ * button = createButton('PLAY!');
+ * button.position(500, 68);
+ * button.mousePressed(play_speed);
+ * }
+ *
+ * function twice_speed() {
+ * ele.speed(2);
+ * }
+ *
+ * function half_speed() {
+ * ele.speed(0.5);
+ * }
+ *
+ * function reverse_speed() {
+ * ele.speed(-1);
+ * }
+ *
+ * function stop_song() {
+ * ele.stop();
+ * }
+ *
+ * function play_speed() {
+ * ele.play();
+ * }
+ *
+ * let ele;
+ * let beginning = true;
+ * function setup() {
+ * //p5.MediaElement objects are usually created
+ * //by calling the createAudio(), createVideo(),
+ * //and createCapture() functions.
+ *
+ * //In this example we create
+ * //a new p5.MediaElement via createAudio().
+ * ele = createAudio('assets/lucky_dragons.mp3');
+ * background(250);
+ * textAlign(CENTER);
+ * text('start at beginning', width / 2, height / 2);
+ * }
+ *
+ * // this function fires with click anywhere
+ * function mousePressed() {
+ * if (beginning === true) {
+ * // here we start the sound at the beginning
+ * // time(0) is not necessary here
+ * // as this produces the same result as
+ * // play()
+ * ele.play().time(0);
+ * background(200);
+ * text('jump 2 sec in', width / 2, height / 2);
+ * beginning = false;
+ * } else {
+ * // here we jump 2 seconds into the sound
+ * ele.play().time(2);
+ * background(250);
+ * text('start at beginning', width / 2, height / 2);
+ * beginning = true;
+ * }
+ * }
+ *
+ * let ele;
+ * function setup() {
+ * //p5.MediaElement objects are usually created
+ * //by calling the createAudio(), createVideo(),
+ * //and createCapture() functions.
+ * //In this example we create
+ * //a new p5.MediaElement via createAudio().
+ * ele = createAudio('assets/doorbell.mp3');
+ * background(250);
+ * textAlign(CENTER);
+ * text('Click to know the duration!', 10, 25, 70, 80);
+ * }
+ * function mouseClicked() {
+ * ele.play();
+ * background(200);
+ * //ele.duration dislpays the duration
+ * text(ele.duration() + ' seconds', width / 2, height / 2);
+ * }
+ *
+ * function setup() {
+ * let audioEl = createAudio('assets/beat.mp3');
+ * audioEl.showControls();
+ * audioEl.onended(sayDone);
+ * }
+ *
+ * function sayDone(elt) {
+ * alert('done playing ' + elt.src);
+ * }
+ *
+ * let ele;
+ * function setup() {
+ * //p5.MediaElement objects are usually created
+ * //by calling the createAudio(), createVideo(),
+ * //and createCapture() functions.
+ * //In this example we create
+ * //a new p5.MediaElement via createAudio()
+ * ele = createAudio('assets/lucky_dragons.mp3');
+ * background(200);
+ * textAlign(CENTER);
+ * text('Click to Show Controls!', 10, 25, 70, 80);
+ * }
+ * function mousePressed() {
+ * ele.showControls();
+ * background(200);
+ * text('Controls Shown', width / 2, height / 2);
+ * }
+ *
+ * let ele;
+ * function setup() {
+ * //p5.MediaElement objects are usually created
+ * //by calling the createAudio(), createVideo(),
+ * //and createCapture() functions.
+ * //In this example we create
+ * //a new p5.MediaElement via createAudio()
+ * ele = createAudio('assets/lucky_dragons.mp3');
+ * ele.showControls();
+ * background(200);
+ * textAlign(CENTER);
+ * text('Click to hide Controls!', 10, 25, 70, 80);
+ * }
+ * function mousePressed() {
+ * ele.hideControls();
+ * background(200);
+ * text('Controls hidden', width / 2, height / 2);
+ * }
+ *
+ * //
+ * //
+ * function setup() {
+ * createCanvas(200, 200);
+ *
+ * let audioEl = createAudio('assets/beat.mp3');
+ * audioEl.showControls();
+ *
+ * // schedule three calls to changeBackground
+ * audioEl.addCue(0.5, changeBackground, color(255, 0, 0));
+ * audioEl.addCue(1.0, changeBackground, color(0, 255, 0));
+ * audioEl.addCue(2.5, changeBackground, color(0, 0, 255));
+ * audioEl.addCue(3.0, changeBackground, color(0, 255, 255));
+ * audioEl.addCue(4.2, changeBackground, color(255, 255, 0));
+ * audioEl.addCue(5.0, changeBackground, color(255, 255, 0));
+ * }
+ *
+ * function changeBackground(val) {
+ * background(val);
+ * }
+ *
+ * let audioEl, id1, id2;
+ * function setup() {
+ * background(255, 255, 255);
+ * audioEl = createAudio('assets/beat.mp3');
+ * audioEl.showControls();
+ * // schedule five calls to changeBackground
+ * id1 = audioEl.addCue(0.5, changeBackground, color(255, 0, 0));
+ * audioEl.addCue(1.0, changeBackground, color(0, 255, 0));
+ * audioEl.addCue(2.5, changeBackground, color(0, 0, 255));
+ * audioEl.addCue(3.0, changeBackground, color(0, 255, 255));
+ * id2 = audioEl.addCue(4.2, changeBackground, color(255, 255, 0));
+ * text('Click to remove first and last Cue!', 10, 25, 70, 80);
+ * }
+ * function mousePressed() {
+ * audioEl.removeCue(id1);
+ * audioEl.removeCue(id2);
+ * }
+ * function changeBackground(val) {
+ * background(val);
+ * }
+ *
+ * let audioEl;
+ * function setup() {
+ * background(255, 255, 255);
+ * audioEl = createAudio('assets/beat.mp3');
+ * //Show the default MediaElement controls, as determined by the web browser
+ * audioEl.showControls();
+ * // schedule calls to changeBackground
+ * background(200);
+ * text('Click to change Cue!', 10, 25, 70, 80);
+ * audioEl.addCue(0.5, changeBackground, color(255, 0, 0));
+ * audioEl.addCue(1.0, changeBackground, color(0, 255, 0));
+ * audioEl.addCue(2.5, changeBackground, color(0, 0, 255));
+ * audioEl.addCue(3.0, changeBackground, color(0, 255, 255));
+ * audioEl.addCue(4.2, changeBackground, color(255, 255, 0));
+ * }
+ * function mousePressed() {
+ * // here we clear the scheduled callbacks
+ * audioEl.clearCues();
+ * // then we add some more callbacks
+ * audioEl.addCue(1, changeBackground, color(2, 2, 2));
+ * audioEl.addCue(3, changeBackground, color(255, 255, 0));
+ * }
+ * function changeBackground(val) {
+ * background(val);
+ * }
+ *
+ * // Move a touchscreen device to register
+ * // acceleration changes.
+ * function draw() {
+ * background(220, 50);
+ * fill('magenta');
+ * ellipse(width / 2, height / 2, accelerationX);
+ * }
+ *
+ *
+ * // Move a touchscreen device to register
+ * // acceleration changes.
+ * function draw() {
+ * background(220, 50);
+ * fill('magenta');
+ * ellipse(width / 2, height / 2, accelerationY);
+ * }
+ *
+ *
+ * // Move a touchscreen device to register
+ * // acceleration changes.
+ * function draw() {
+ * background(220, 50);
+ * fill('magenta');
+ * ellipse(width / 2, height / 2, accelerationZ);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * //rotateZ(radians(rotationZ));
+ * rotateX(radians(rotationX));
+ * //rotateY(radians(rotationY));
+ * box(200, 200, 200);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * //rotateZ(radians(rotationZ));
+ * //rotateX(radians(rotationX));
+ * rotateY(radians(rotationY));
+ * box(200, 200, 200);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateZ(radians(rotationZ));
+ * //rotateX(radians(rotationX));
+ * //rotateY(radians(rotationY));
+ * box(200, 200, 200);
+ * }
+ *
+ *
+ * // A simple if statement looking at whether
+ * // rotationX - pRotationX < 0 is true or not will be
+ * // sufficient for determining the rotate direction
+ * // in most cases.
+ *
+ * // Some extra logic is needed to account for cases where
+ * // the angles wrap around.
+ * let rotateDirection = 'clockwise';
+ *
+ * // Simple range conversion to make things simpler.
+ * // This is not absolutely necessary but the logic
+ * // will be different in that case.
+ *
+ * let rX = rotationX + 180;
+ * let pRX = pRotationX + 180;
+ *
+ * if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) {
+ * rotateDirection = 'clockwise';
+ * } else if (rX - pRX < 0 || rX - pRX > 270) {
+ * rotateDirection = 'counter-clockwise';
+ * }
+ *
+ * print(rotateDirection);
+ *
+ *
+ * // A simple if statement looking at whether
+ * // rotationY - pRotationY < 0 is true or not will be
+ * // sufficient for determining the rotate direction
+ * // in most cases.
+ *
+ * // Some extra logic is needed to account for cases where
+ * // the angles wrap around.
+ * let rotateDirection = 'clockwise';
+ *
+ * // Simple range conversion to make things simpler.
+ * // This is not absolutely necessary but the logic
+ * // will be different in that case.
+ *
+ * let rY = rotationY + 180;
+ * let pRY = pRotationY + 180;
+ *
+ * if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) {
+ * rotateDirection = 'clockwise';
+ * } else if (rY - pRY < 0 || rY - pRY > 270) {
+ * rotateDirection = 'counter-clockwise';
+ * }
+ * print(rotateDirection);
+ *
+ *
+ * // A simple if statement looking at whether
+ * // rotationZ - pRotationZ < 0 is true or not will be
+ * // sufficient for determining the rotate direction
+ * // in most cases.
+ *
+ * // Some extra logic is needed to account for cases where
+ * // the angles wrap around.
+ * let rotateDirection = 'clockwise';
+ *
+ * if (
+ * (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) ||
+ * rotationZ - pRotationZ < -270
+ * ) {
+ * rotateDirection = 'clockwise';
+ * } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) {
+ * rotateDirection = 'counter-clockwise';
+ * }
+ * print(rotateDirection);
+ *
+ *
+ * // Run this example on a mobile device
+ * // Rotate the device by 90 degrees in the
+ * // X-axis to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceTurned() {
+ * if (turnAxis === 'X') {
+ * if (value === 0) {
+ * value = 255;
+ * } else if (value === 255) {
+ * value = 0;
+ * }
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // You will need to move the device incrementally further
+ * // the closer the square's color gets to white in order to change the value.
+ *
+ * let value = 0;
+ * let threshold = 0.5;
+ * function setup() {
+ * setMoveThreshold(threshold);
+ * }
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceMoved() {
+ * value = value + 5;
+ * threshold = threshold + 0.1;
+ * if (value > 255) {
+ * value = 0;
+ * threshold = 30;
+ * }
+ * setMoveThreshold(threshold);
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // You will need to shake the device more firmly
+ * // the closer the box's fill gets to white in order to change the value.
+ *
+ * let value = 0;
+ * let threshold = 30;
+ * function setup() {
+ * setShakeThreshold(threshold);
+ * }
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceMoved() {
+ * value = value + 5;
+ * threshold = threshold + 5;
+ * if (value > 255) {
+ * value = 0;
+ * threshold = 30;
+ * }
+ * setShakeThreshold(threshold);
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Move the device around
+ * // to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceMoved() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Rotate the device by 90 degrees
+ * // to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceTurned() {
+ * if (value === 0) {
+ * value = 255;
+ * } else if (value === 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Rotate the device by 90 degrees in the
+ * // X-axis to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceTurned() {
+ * if (turnAxis === 'X') {
+ * if (value === 0) {
+ * value = 255;
+ * } else if (value === 255) {
+ * value = 0;
+ * }
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Shake the device to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function deviceShaken() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function draw() {
+ * if (keyIsPressed === true) {
+ * fill(0);
+ * } else {
+ * fill(255);
+ * }
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ *
+ * // Click any key to display it!
+ * // (Not Guaranteed to be Case Sensitive)
+ * function setup() {
+ * fill(245, 123, 158);
+ * textSize(50);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * text(key, 33, 65); // Display last key pressed.
+ * }
+ *
+ * let fillVal = 126;
+ * function draw() {
+ * fill(fillVal);
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ * function keyPressed() {
+ * if (keyCode === UP_ARROW) {
+ * fillVal = 255;
+ * } else if (keyCode === DOWN_ARROW) {
+ * fillVal = 0;
+ * }
+ * }
+ *
+ * function draw() {}
+ * function keyPressed() {
+ * background('yellow');
+ * text(`${key} ${keyCode}`, 10, 40);
+ * print(key, ' ', keyCode);
+ * }
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function keyPressed() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function keyPressed() {
+ * if (keyCode === LEFT_ARROW) {
+ * value = 255;
+ * } else if (keyCode === RIGHT_ARROW) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function keyPressed() {
+ * // Do something
+ * return false; // prevent any default behaviour
+ * }
+ *
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function keyReleased() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * return false; // prevent any default behavior
+ * }
+ *
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function keyTyped() {
+ * if (key === 'a') {
+ * value = 255;
+ * } else if (key === 'b') {
+ * value = 0;
+ * }
+ * // uncomment to prevent any default behavior
+ * // return false;
+ * }
+ *
+ *
+ * let x = 100;
+ * let y = 100;
+ *
+ * function setup() {
+ * createCanvas(512, 512);
+ * fill(255, 0, 0);
+ * }
+ *
+ * function draw() {
+ * if (keyIsDown(LEFT_ARROW)) {
+ * x -= 5;
+ * }
+ *
+ * if (keyIsDown(RIGHT_ARROW)) {
+ * x += 5;
+ * }
+ *
+ * if (keyIsDown(UP_ARROW)) {
+ * y -= 5;
+ * }
+ *
+ * if (keyIsDown(DOWN_ARROW)) {
+ * y += 5;
+ * }
+ *
+ * clear();
+ * ellipse(x, y, 50, 50);
+ * }
+ *
+ * let diameter = 50;
+ *
+ * function setup() {
+ * createCanvas(512, 512);
+ * }
+ *
+ * function draw() {
+ * // 107 and 187 are keyCodes for "+"
+ * if (keyIsDown(107) || keyIsDown(187)) {
+ * diameter += 1;
+ * }
+ *
+ * // 109 and 189 are keyCodes for "-"
+ * if (keyIsDown(109) || keyIsDown(189)) {
+ * diameter -= 1;
+ * }
+ *
+ * clear();
+ * fill(255, 0, 0);
+ * ellipse(50, 50, diameter, diameter);
+ * }
+ *
+ * let x = 50;
+ * function setup() {
+ * rectMode(CENTER);
+ * }
+ *
+ * function draw() {
+ * if (x > 48) {
+ * x -= 2;
+ * } else if (x < 48) {
+ * x += 2;
+ * }
+ * x += floor(movedX / 5);
+ * background(237, 34, 93);
+ * fill(0);
+ * rect(x, 50, 50, 50);
+ * }
+ *
+ *
+ * let y = 50;
+ * function setup() {
+ * rectMode(CENTER);
+ * }
+ *
+ * function draw() {
+ * if (y > 48) {
+ * y -= 2;
+ * } else if (y < 48) {
+ * y += 2;
+ * }
+ * y += floor(movedY / 5);
+ * background(237, 34, 93);
+ * fill(0);
+ * rect(y, 50, 50, 50);
+ * }
+ *
+ *
+ * // Move the mouse across the canvas
+ * function draw() {
+ * background(244, 248, 252);
+ * line(mouseX, 0, mouseX, 100);
+ * }
+ *
+ *
+ * // Move the mouse across the canvas
+ * function draw() {
+ * background(244, 248, 252);
+ * line(0, mouseY, 100, mouseY);
+ * }
+ *
+ *
+ * // Move the mouse across the canvas to leave a trail
+ * function setup() {
+ * //slow down the frameRate to make it more visible
+ * frameRate(10);
+ * }
+ *
+ * function draw() {
+ * background(244, 248, 252);
+ * line(mouseX, mouseY, pmouseX, pmouseY);
+ * print(pmouseX + ' -> ' + mouseX);
+ * }
+ *
+ *
+ * function draw() {
+ * background(237, 34, 93);
+ * fill(0);
+ * //draw a square only if the mouse is not moving
+ * if (mouseY === pmouseY && mouseX === pmouseX) {
+ * rect(20, 20, 60, 60);
+ * }
+ *
+ * print(pmouseY + ' -> ' + mouseY);
+ * }
+ *
+ *
+ * let myCanvas;
+ *
+ * function setup() {
+ * //use a variable to store a pointer to the canvas
+ * myCanvas = createCanvas(100, 100);
+ * let body = document.getElementsByTagName('body')[0];
+ * myCanvas.parent(body);
+ * }
+ *
+ * function draw() {
+ * background(237, 34, 93);
+ * fill(0);
+ *
+ * //move the canvas to the horizontal mouse position
+ * //relative to the window
+ * myCanvas.position(winMouseX + 1, windowHeight / 2);
+ *
+ * //the y of the square is relative to the canvas
+ * rect(20, mouseY, 60, 60);
+ * }
+ *
+ *
+ * let myCanvas;
+ *
+ * function setup() {
+ * //use a variable to store a pointer to the canvas
+ * myCanvas = createCanvas(100, 100);
+ * let body = document.getElementsByTagName('body')[0];
+ * myCanvas.parent(body);
+ * }
+ *
+ * function draw() {
+ * background(237, 34, 93);
+ * fill(0);
+ *
+ * //move the canvas to the vertical mouse position
+ * //relative to the window
+ * myCanvas.position(windowWidth / 2, winMouseY + 1);
+ *
+ * //the x of the square is relative to the canvas
+ * rect(mouseX, 20, 60, 60);
+ * }
+ *
+ *
+ * let myCanvas;
+ *
+ * function setup() {
+ * //use a variable to store a pointer to the canvas
+ * myCanvas = createCanvas(100, 100);
+ * noStroke();
+ * fill(237, 34, 93);
+ * }
+ *
+ * function draw() {
+ * clear();
+ * //the difference between previous and
+ * //current x position is the horizontal mouse speed
+ * let speed = abs(winMouseX - pwinMouseX);
+ * //change the size of the circle
+ * //according to the horizontal speed
+ * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5);
+ * //move the canvas to the mouse position
+ * myCanvas.position(winMouseX + 1, winMouseY + 1);
+ * }
+ *
+ *
+ * let myCanvas;
+ *
+ * function setup() {
+ * //use a variable to store a pointer to the canvas
+ * myCanvas = createCanvas(100, 100);
+ * noStroke();
+ * fill(237, 34, 93);
+ * }
+ *
+ * function draw() {
+ * clear();
+ * //the difference between previous and
+ * //current y position is the vertical mouse speed
+ * let speed = abs(winMouseY - pwinMouseY);
+ * //change the size of the circle
+ * //according to the vertical speed
+ * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5);
+ * //move the canvas to the mouse position
+ * myCanvas.position(winMouseX + 1, winMouseY + 1);
+ * }
+ *
+ *
+ * function draw() {
+ * background(237, 34, 93);
+ * fill(0);
+ *
+ * if (mouseIsPressed) {
+ * if (mouseButton === LEFT) {
+ * ellipse(50, 50, 50, 50);
+ * }
+ * if (mouseButton === RIGHT) {
+ * rect(25, 25, 50, 50);
+ * }
+ * if (mouseButton === CENTER) {
+ * triangle(23, 75, 50, 20, 78, 75);
+ * }
+ * }
+ *
+ * print(mouseButton);
+ * }
+ *
+ *
+ * function draw() {
+ * background(237, 34, 93);
+ * fill(0);
+ *
+ * if (mouseIsPressed) {
+ * ellipse(50, 50, 50, 50);
+ * } else {
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ * print(mouseIsPressed);
+ * }
+ *
+ *
+ * // Move the mouse across the page
+ * // to change its value
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function mouseMoved() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function mouseMoved() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a MouseEvent object
+ * // as a callback argument
+ * function mouseMoved(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Drag the mouse across the page
+ * // to change its value
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function mouseDragged() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function mouseDragged() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a MouseEvent object
+ * // as a callback argument
+ * function mouseDragged(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Click within the image to change
+ * // the value of the rectangle
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function mousePressed() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function mousePressed() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a MouseEvent object
+ * // as a callback argument
+ * function mousePressed(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Click within the image to change
+ * // the value of the rectangle
+ * // after the mouse has been clicked
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function mouseReleased() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function mouseReleased() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a MouseEvent object
+ * // as a callback argument
+ * function mouseReleased(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Click within the image to change
+ * // the value of the rectangle
+ * // after the mouse has been clicked
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ * function mouseClicked() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function mouseClicked() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a MouseEvent object
+ * // as a callback argument
+ * function mouseClicked(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Click within the image to change
+ * // the value of the rectangle
+ * // after the mouse has been double clicked
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ * function doubleClicked() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function doubleClicked() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a MouseEvent object
+ * // as a callback argument
+ * function doubleClicked(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * let pos = 25;
+ *
+ * function draw() {
+ * background(237, 34, 93);
+ * fill(0);
+ * rect(25, pos, 50, 50);
+ * }
+ *
+ * function mouseWheel(event) {
+ * print(event.delta);
+ * //move the square according to the vertical scroll amount
+ * pos += event.delta;
+ * //uncomment to block page scrolling
+ * //return false;
+ * }
+ *
+ *
+ * let cam;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * requestPointerLock();
+ * cam = createCamera();
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * cam.pan(-movedX * 0.001);
+ * cam.tilt(movedY * 0.001);
+ * sphere(25);
+ * }
+ *
+ *
+ * //click the canvas to lock the pointer
+ * //click again to exit (otherwise escape)
+ * let locked = false;
+ * function draw() {
+ * background(237, 34, 93);
+ * }
+ * function mouseClicked() {
+ * if (!locked) {
+ * locked = true;
+ * requestPointerLock();
+ * } else {
+ * exitPointerLock();
+ * locked = false;
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch
+ * // the canvas using one or more fingers
+ * // at the same time
+ * function draw() {
+ * clear();
+ * let display = touches.length + ' touches';
+ * text(display, 5, 10);
+ * }
+ *
+ *
+ * // Touch within the image to change
+ * // the value of the rectangle
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function touchStarted() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function touchStarted() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a TouchEvent object
+ * // as a callback argument
+ * function touchStarted(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Move your finger across the page
+ * // to change its value
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function touchMoved() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function touchMoved() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a TouchEvent object
+ * // as a callback argument
+ * function touchMoved(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * // Release touch within the image to
+ * // change the value of the rectangle
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * }
+ * function touchEnded() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * function touchEnded() {
+ * ellipse(mouseX, mouseY, 5, 5);
+ * // prevent default
+ * return false;
+ * }
+ *
+ *
+ * // returns a TouchEvent object
+ * // as a callback argument
+ * function touchEnded(event) {
+ * console.log(event);
+ * }
+ *
+ *
+ * let img = createImage(66, 66);
+ * img.loadPixels();
+ * for (let i = 0; i < img.width; i++) {
+ * for (let j = 0; j < img.height; j++) {
+ * img.set(i, j, color(0, 90, 102));
+ * }
+ * }
+ * img.updatePixels();
+ * image(img, 17, 17);
+ *
+ *
+ * let img = createImage(66, 66);
+ * img.loadPixels();
+ * for (let i = 0; i < img.width; i++) {
+ * for (let j = 0; j < img.height; j++) {
+ * img.set(i, j, color(0, 90, 102, (i % img.width) * 2));
+ * }
+ * }
+ * img.updatePixels();
+ * image(img, 17, 17);
+ * image(img, 34, 34);
+ *
+ *
+ * let pink = color(255, 102, 204);
+ * let img = createImage(66, 66);
+ * img.loadPixels();
+ * let d = pixelDensity();
+ * let halfImage = 4 * (img.width * d) * (img.height / 2 * d);
+ * for (let i = 0; i < halfImage; i += 4) {
+ * img.pixels[i] = red(pink);
+ * img.pixels[i + 1] = green(pink);
+ * img.pixels[i + 2] = blue(pink);
+ * img.pixels[i + 3] = alpha(pink);
+ * }
+ * img.updatePixels();
+ * image(img, 17, 17);
+ *
+ *
+ * function setup() {
+ * let c = createCanvas(100, 100);
+ * background(255, 0, 0);
+ * saveCanvas(c, 'myCanvas', 'jpg');
+ * }
+ *
+ * // note that this example has the same result as above
+ * // if no canvas is specified, defaults to main canvas
+ * function setup() {
+ * let c = createCanvas(100, 100);
+ * background(255, 0, 0);
+ * saveCanvas('myCanvas', 'jpg');
+ *
+ * // all of the following are valid
+ * saveCanvas(c, 'myCanvas', 'jpg');
+ * saveCanvas(c, 'myCanvas.jpg');
+ * saveCanvas(c, 'myCanvas');
+ * saveCanvas(c);
+ * saveCanvas('myCanvas', 'png');
+ * saveCanvas('myCanvas');
+ * saveCanvas();
+ * }
+ *
+ * function draw() {
+ * background(mouseX);
+ * }
+ *
+ * function mousePressed() {
+ * saveFrames('out', 'png', 1, 25, data => {
+ * print(data);
+ * });
+ * }
+
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * }
+ *
+ *
+ * function setup() {
+ * // here we use a callback to display the image after loading
+ * loadImage('assets/laDefense.jpg', img => {
+ * image(img, 0, 0);
+ * });
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ * function setup() {
+ * // Top-left corner of the img is at (0, 0)
+ * // Width and height are the img's original width and height
+ * image(img, 0, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ * function setup() {
+ * background(50);
+ * // Top-left corner of the img is at (10, 10)
+ * // Width and height are 50 x 50
+ * image(img, 10, 10, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * // Here, we use a callback to display the image after loading
+ * loadImage('assets/laDefense.jpg', img => {
+ * image(img, 0, 0);
+ * });
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/gradient.png');
+ * }
+ * function setup() {
+ * // 1. Background image
+ * // Top-left corner of the img is at (0, 0)
+ * // Width and height are the img's original width and height, 100 x 100
+ * image(img, 0, 0);
+ * // 2. Top right image
+ * // Top-left corner of destination rectangle is at (50, 0)
+ * // Destination rectangle width and height are 40 x 20
+ * // The next parameters are relative to the source image:
+ * // - Starting at position (50, 50) on the source image, capture a 50 x 50
+ * // subsection
+ * // - Draw this subsection to fill the dimensions of the destination rectangle
+ * image(img, 50, 0, 40, 20, 50, 50, 50, 50);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * tint(0, 153, 204); // Tint blue
+ * image(img, 50, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * tint(0, 153, 204, 126); // Tint blue and set transparency
+ * image(img, 50, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * tint(255, 126); // Apply transparency without changing color
+ * image(img, 50, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * tint(0, 153, 204); // Tint blue
+ * image(img, 0, 0);
+ * noTint(); // Disable tint
+ * image(img, 50, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * imageMode(CORNER);
+ * image(img, 10, 10, 50, 50);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * imageMode(CORNERS);
+ * image(img, 10, 10, 90, 40);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * imageMode(CENTER);
+ * image(img, 50, 50, 80, 80);
+ * }
+ *
+ *
+ * function setup() {
+ * let img = createImage(100, 100); // same as new p5.Image(100, 100);
+ * img.loadPixels();
+ * createCanvas(100, 100);
+ * background(0);
+ *
+ * // helper for writing color to array
+ * function writeColor(image, x, y, red, green, blue, alpha) {
+ * let index = (x + y * width) * 4;
+ * image.pixels[index] = red;
+ * image.pixels[index + 1] = green;
+ * image.pixels[index + 2] = blue;
+ * image.pixels[index + 3] = alpha;
+ * }
+ *
+ * let x, y;
+ * // fill with random colors
+ * for (y = 0; y < img.height; y++) {
+ * for (x = 0; x < img.width; x++) {
+ * let red = random(255);
+ * let green = random(255);
+ * let blue = random(255);
+ * let alpha = 255;
+ * writeColor(img, x, y, red, green, blue, alpha);
+ * }
+ * }
+ *
+ * // draw a red line
+ * y = 0;
+ * for (x = 0; x < img.width; x++) {
+ * writeColor(img, x, y, 255, 0, 0, 255);
+ * }
+ *
+ * // draw a green line
+ * y = img.height - 1;
+ * for (x = 0; x < img.width; x++) {
+ * writeColor(img, x, y, 0, 255, 0, 255);
+ * }
+ *
+ * img.updatePixels();
+ * image(img, 0, 0);
+ * }
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * image(img, 0, 0);
+ * for (let i = 0; i < img.width; i++) {
+ * let c = img.get(i, img.height / 2);
+ * stroke(c);
+ * line(i, height / 2, i, height);
+ * }
+ * }
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * image(img, 0, 0);
+ * for (let i = 0; i < img.height; i++) {
+ * let c = img.get(img.width / 2, i);
+ * stroke(c);
+ * line(0, i, width / 2, i);
+ * }
+ * }
+ *
+ * let img = createImage(66, 66);
+ * img.loadPixels();
+ * for (let i = 0; i < img.width; i++) {
+ * for (let j = 0; j < img.height; j++) {
+ * img.set(i, j, color(0, 90, 102));
+ * }
+ * }
+ * img.updatePixels();
+ * image(img, 17, 17);
+ *
+ *
+ * let pink = color(255, 102, 204);
+ * let img = createImage(66, 66);
+ * img.loadPixels();
+ * for (let i = 0; i < 4 * (width * height / 2); i += 4) {
+ * img.pixels[i] = red(pink);
+ * img.pixels[i + 1] = green(pink);
+ * img.pixels[i + 2] = blue(pink);
+ * img.pixels[i + 3] = alpha(pink);
+ * }
+ * img.updatePixels();
+ * image(img, 17, 17);
+ *
+ *
+ * let myImage;
+ * let halfImage;
+ *
+ * function preload() {
+ * myImage = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * myImage.loadPixels();
+ * halfImage = 4 * myImage.width * myImage.height / 2;
+ * for (let i = 0; i < halfImage; i++) {
+ * myImage.pixels[i + halfImage] = myImage.pixels[i];
+ * }
+ * myImage.updatePixels();
+ * }
+ *
+ * function draw() {
+ * image(myImage, 0, 0, width, height);
+ * }
+ *
+ * let myImage;
+ * let halfImage;
+ *
+ * function preload() {
+ * myImage = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * myImage.loadPixels();
+ * halfImage = 4 * myImage.width * myImage.height / 2;
+ * for (let i = 0; i < halfImage; i++) {
+ * myImage.pixels[i + halfImage] = myImage.pixels[i];
+ * }
+ * myImage.updatePixels();
+ * }
+ *
+ * function draw() {
+ * image(myImage, 0, 0, width, height);
+ * }
+ *
+ * let myImage;
+ * let c;
+ *
+ * function preload() {
+ * myImage = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * background(myImage);
+ * noStroke();
+ * c = myImage.get(60, 90);
+ * fill(c);
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ * //get() returns color here
+ *
+ * let img = createImage(66, 66);
+ * img.loadPixels();
+ * for (let i = 0; i < img.width; i++) {
+ * for (let j = 0; j < img.height; j++) {
+ * img.set(i, j, color(0, 90, 102, (i % img.width) * 2));
+ * }
+ * }
+ * img.updatePixels();
+ * image(img, 17, 17);
+ * image(img, 34, 34);
+ *
+ *
+ * let img;
+ *
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+
+ * function draw() {
+ * image(img, 0, 0);
+ * }
+ *
+ * function mousePressed() {
+ * img.resize(50, 100);
+ * }
+ *
+ * let photo;
+ * let bricks;
+ * let x;
+ * let y;
+ *
+ * function preload() {
+ * photo = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * x = bricks.width / 2;
+ * y = bricks.height / 2;
+ * photo.copy(bricks, 0, 0, x, y, 0, 0, x, y);
+ * image(photo, 0, 0);
+ * }
+ *
+ * let photo, maskImage;
+ * function preload() {
+ * photo = loadImage('assets/rockies.jpg');
+ * maskImage = loadImage('assets/mask2.png');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * photo.mask(maskImage);
+ * image(photo, 0, 0);
+ * }
+ *
+ * let photo1;
+ * let photo2;
+ *
+ * function preload() {
+ * photo1 = loadImage('assets/rockies.jpg');
+ * photo2 = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * photo2.filter(GRAY);
+ * image(photo1, 0, 0);
+ * image(photo2, width / 2, 0);
+ * }
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
+ * image(mountains, 0, 0);
+ * image(bricks, 0, 0);
+ * }
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
+ * image(mountains, 0, 0);
+ * image(bricks, 0, 0);
+ * }
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
+ * image(mountains, 0, 0);
+ * image(bricks, 0, 0);
+ * }
+ *
+ * let photo;
+ *
+ * function preload() {
+ * photo = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function draw() {
+ * image(photo, 0, 0);
+ * }
+ *
+ * function keyTyped() {
+ * if (key === 's') {
+ * photo.save('photo', 'png');
+ * }
+ * }
+ *
+ * let gif;
+ *
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-wink-loop-once.gif');
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * // The GIF file that we loaded only loops once
+ * // so it freezes on the last frame after playing through
+ * image(gif, 0, 0);
+ * }
+ *
+ * function mousePressed() {
+ * // Click to reset the GIF and begin playback from start
+ * gif.reset();
+ * }
+ *
+ * let gif;
+ *
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function draw() {
+ * let frame = gif.getCurrentFrame();
+ * image(gif, 0, 0);
+ * text(frame, 10, 90);
+ * }
+ *
+ * let gif;
+ *
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * // Move your mouse up and down over canvas to see the GIF
+ * // frames animate
+ * function draw() {
+ * gif.pause();
+ * image(gif, 0, 0);
+ * // Get the highest frame number which is the number of frames - 1
+ * let maxFrame = gif.numFrames() - 1;
+ * // Set the current frame that is mapped to be relative to mouse position
+ * let frameNumber = floor(map(mouseY, 0, height, 0, maxFrame, true));
+ * gif.setFrame(frameNumber);
+ * }
+ *
+ * let gif;
+ *
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * // Move your mouse up and down over canvas to see the GIF
+ * // frames animate
+ * function draw() {
+ * gif.pause();
+ * image(gif, 0, 0);
+ * // Get the highest frame number which is the number of frames - 1
+ * let maxFrame = gif.numFrames() - 1;
+ * // Set the current frame that is mapped to be relative to mouse position
+ * let frameNumber = floor(map(mouseY, 0, height, 0, maxFrame, true));
+ * gif.setFrame(frameNumber);
+ * }
+ *
+ * let gif;
+ *
+ * function preload() {
+ * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * image(gif, 0, 0);
+ * }
+ *
+ * function mousePressed() {
+ * gif.pause();
+ * }
+ *
+ * function mouseReleased() {
+ * gif.play();
+ * }
+ *
+ * let gif;
+ *
+ * function preload() {
+ * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * image(gif, 0, 0);
+ * }
+ *
+ * function mousePressed() {
+ * gif.pause();
+ * }
+ *
+ * function mouseReleased() {
+ * gif.play();
+ * }
+ *
+ * let gifFast, gifSlow;
+ *
+ * function preload() {
+ * gifFast = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * gifSlow = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * gifFast.resize(width / 2, height / 2);
+ * gifSlow.resize(width / 2, height / 2);
+ *
+ * //Change the delay here
+ * gifFast.delay(10);
+ * gifSlow.delay(100);
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * image(gifFast, 0, 0);
+ * image(gifSlow, width / 2, 0);
+ * }
+ *
+ * let pink = color(255, 102, 204);
+ * loadPixels();
+ * let d = pixelDensity();
+ * let halfImage = 4 * (width * d) * (height / 2 * d);
+ * for (let i = 0; i < halfImage; i += 4) {
+ * pixels[i] = red(pink);
+ * pixels[i + 1] = green(pink);
+ * pixels[i + 2] = blue(pink);
+ * pixels[i + 3] = alpha(pink);
+ * }
+ * updatePixels();
+ *
+ *
+ * let img0;
+ * let img1;
+ *
+ * function preload() {
+ * img0 = loadImage('assets/rockies.jpg');
+ * img1 = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * background(img0);
+ * image(img1, 0, 0);
+ * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
+ * }
+ *
+ * let img0;
+ * let img1;
+ *
+ * function preload() {
+ * img0 = loadImage('assets/rockies.jpg');
+ * img1 = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * background(img0);
+ * image(img1, 0, 0);
+ * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
+ * }
+ *
+ * let img0;
+ * let img1;
+ *
+ * function preload() {
+ * img0 = loadImage('assets/rockies.jpg');
+ * img1 = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * background(img0);
+ * image(img1, 0, 0);
+ * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
+ * }
+ *
+ * let img;
+ *
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * background(img);
+ * copy(img, 7, 22, 10, 10, 35, 25, 50, 50);
+ * stroke(255);
+ * noFill();
+ * // Rectangle shows area being copied
+ * rect(7, 22, 10, 10);
+ * }
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(THRESHOLD);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(GRAY);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(OPAQUE);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(INVERT);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(POSTERIZE, 3);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(DILATE);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(BLUR, 3);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * filter(ERODE);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * let c = get();
+ * image(c, width / 2, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ * function setup() {
+ * image(img, 0, 0);
+ * let c = get(50, 90);
+ * fill(c);
+ * noStroke();
+ * rect(25, 25, 50, 50);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * image(img, 0, 0, width, height);
+ * let d = pixelDensity();
+ * let halfImage = 4 * (width * d) * (height * d / 2);
+ * loadPixels();
+ * for (let i = 0; i < halfImage; i++) {
+ * pixels[i + halfImage] = pixels[i];
+ * }
+ * updatePixels();
+ * }
+ *
+ *
+ * let black = color(0);
+ * set(30, 20, black);
+ * set(85, 20, black);
+ * set(85, 75, black);
+ * set(30, 75, black);
+ * updatePixels();
+ *
+ *
+ * for (let i = 30; i < width - 15; i++) {
+ * for (let j = 20; j < height - 25; j++) {
+ * let c = color(204 - j, 153 - i, 0);
+ * set(i, j, c);
+ * }
+ * }
+ * updatePixels();
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * set(0, 0, img);
+ * updatePixels();
+ * line(0, 0, width, height);
+ * line(0, height, width, 0);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * image(img, 0, 0, width, height);
+ * let d = pixelDensity();
+ * let halfImage = 4 * (width * d) * (height * d / 2);
+ * loadPixels();
+ * for (let i = 0; i < halfImage; i++) {
+ * pixels[i + halfImage] = pixels[i];
+ * }
+ * updatePixels();
+ * }
+ *
+ *
+ * // Examples use USGS Earthquake API:
+ * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
+ * let earthquakes;
+ * function preload() {
+ * // Get the most recent earthquake in the database
+ * let url =
+ 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' +
+ * 'summary/all_day.geojson';
+ * earthquakes = loadJSON(url);
+ * }
+ *
+ * function setup() {
+ * noLoop();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * // Get the magnitude and name of the earthquake out of the loaded JSON
+ * let earthquakeMag = earthquakes.features[0].properties.mag;
+ * let earthquakeName = earthquakes.features[0].properties.place;
+ * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
+ * textAlign(CENTER);
+ * text(earthquakeName, 0, height - 30, width, 30);
+ * }
+ *
+ * function setup() {
+ * noLoop();
+ * let url =
+ 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' +
+ * 'summary/all_day.geojson';
+ * loadJSON(url, drawEarthquake);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * }
+ *
+ * function drawEarthquake(earthquakes) {
+ * // Get the magnitude and name of the earthquake out of the loaded JSON
+ * let earthquakeMag = earthquakes.features[0].properties.mag;
+ * let earthquakeName = earthquakes.features[0].properties.place;
+ * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
+ * textAlign(CENTER);
+ * text(earthquakeName, 0, height - 30, width, 30);
+ * }
+ *
+ * let result;
+ * function preload() {
+ * result = loadStrings('assets/test.txt');
+ * }
+
+ * function setup() {
+ * background(200);
+ * text(random(result), 10, 10, 80, 80);
+ * }
+ *
+ * function setup() {
+ * loadStrings('assets/test.txt', pickString);
+ * }
+ *
+ * function pickString(result) {
+ * background(200);
+ * text(random(result), 10, 10, 80, 80);
+ * }
+ *
+ * // Given the following CSV file called "mammals.csv"
+ * // located in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * //the file can be remote
+ * //table = loadTable("http://p5js.org/reference/assets/mammals.csv",
+ * // "csv", "header");
+ * }
+ *
+ * function setup() {
+ * //count the columns
+ * print(table.getRowCount() + ' total rows in table');
+ * print(table.getColumnCount() + ' total columns in table');
+ *
+ * print(table.getColumn('name'));
+ * //["Goat", "Leopard", "Zebra"]
+ *
+ * //cycle through the table
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++) {
+ * print(table.getString(r, c));
+ * }
+ * }
+ *
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let children = xml.getChildren('animal');
+ *
+ * for (let i = 0; i < children.length; i++) {
+ * let id = children[i].getNum('id');
+ * let coloring = children[i].getString('species');
+ * let name = children[i].getContent();
+ * print(id + ', ' + coloring + ', ' + name);
+ * }
+ * }
+ *
+ * // Sketch prints:
+ * // 0, Capra hircus, Goat
+ * // 1, Panthera pardus, Leopard
+ * // 2, Equus zebra, Zebra
+ *
+ * let data;
+ *
+ * function preload() {
+ * data = loadBytes('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * for (let i = 0; i < 5; i++) {
+ * console.log(data.bytes[i].toString(16));
+ * }
+ * }
+ *
httpDo(path, 'GET')
. The 'binary' datatype will return
+ * a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer
+ * which can be used to initialize typed arrays (such as Uint8Array).
+ *
+ * @method httpGet
+ * @param {String} path name of the file or url to load
+ * @param {String} [datatype] "json", "jsonp", "binary", "arrayBuffer",
+ * "xml", or "text"
+ * @param {Object|Boolean} [data] param data passed sent with request
+ * @param {function} [callback] function to be executed after
+ * httpGet() completes, data is passed in
+ * as first argument
+ * @param {function} [errorCallback] function to be executed if
+ * there is an error, response is passed
+ * in as first argument
+ * @return {Promise} A promise that resolves with the data when the operation
+ * completes successfully or rejects with the error after
+ * one occurs.
+ * @example
+ *
+ * // Examples use USGS Earthquake API:
+ * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
+ * let earthquakes;
+ * function preload() {
+ * // Get the most recent earthquake in the database
+ * let url =
+ 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
+ * 'format=geojson&limit=1&orderby=time';
+ * httpGet(url, 'jsonp', false, function(response) {
+ * // when the HTTP request completes, populate the variable that holds the
+ * // earthquake data used in the visualization.
+ * earthquakes = response;
+ * });
+ * }
+ *
+ * function draw() {
+ * if (!earthquakes) {
+ * // Wait until the earthquake data has loaded before drawing.
+ * return;
+ * }
+ * background(200);
+ * // Get the magnitude and name of the earthquake out of the loaded JSON
+ * let earthquakeMag = earthquakes.features[0].properties.mag;
+ * let earthquakeName = earthquakes.features[0].properties.place;
+ * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
+ * textAlign(CENTER);
+ * text(earthquakeName, 0, height - 30, width, 30);
+ * noLoop();
+ * }
+ *
httpDo(path, 'POST')
.
+ *
+ * @method httpPost
+ * @param {String} path name of the file or url to load
+ * @param {String} [datatype] "json", "jsonp", "xml", or "text".
+ * If omitted, httpPost() will guess.
+ * @param {Object|Boolean} [data] param data passed sent with request
+ * @param {function} [callback] function to be executed after
+ * httpPost() completes, data is passed in
+ * as first argument
+ * @param {function} [errorCallback] function to be executed if
+ * there is an error, response is passed
+ * in as first argument
+ * @return {Promise} A promise that resolves with the data when the operation
+ * completes successfully or rejects with the error after
+ * one occurs.
+ *
+ * @example
+ *
+ * // Examples use jsonplaceholder.typicode.com for a Mock Data API
+ *
+ * let url = 'https://jsonplaceholder.typicode.com/posts';
+ * let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very cool.' };
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * }
+ *
+ * function mousePressed() {
+ * httpPost(url, 'json', postData, function(result) {
+ * strokeWeight(2);
+ * text(result.body, mouseX, mouseY);
+ * });
+ * }
+ *
+ *
+ * let url = 'ttps://invalidURL'; // A bad URL that will cause errors
+ * let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' };
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * }
+ *
+ * function mousePressed() {
+ * httpPost(
+ * url,
+ * 'json',
+ * postData,
+ * function(result) {
+ * // ... won't be called
+ * },
+ * function(error) {
+ * strokeWeight(2);
+ * text(error.toString(), mouseX, mouseY);
+ * }
+ * );
+ * }
+ *
+ * // Examples use USGS Earthquake API:
+ * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
+ *
+ * // displays an animation of all USGS earthquakes
+ * let earthquakes;
+ * let eqFeatureIndex = 0;
+ *
+ * function preload() {
+ * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
+ * httpDo(
+ * url,
+ * {
+ * method: 'GET',
+ * // Other Request options, like special headers for apis
+ * headers: { authorization: 'Bearer secretKey' }
+ * },
+ * function(res) {
+ * earthquakes = res;
+ * }
+ * );
+ * }
+ *
+ * function draw() {
+ * // wait until the data is loaded
+ * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
+ * return;
+ * }
+ * clear();
+ *
+ * let feature = earthquakes.features[eqFeatureIndex];
+ * let mag = feature.properties.mag;
+ * let rad = mag / 11 * ((width + height) / 2);
+ * fill(255, 0, 0, 100);
+ * ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad);
+ *
+ * if (eqFeatureIndex >= earthquakes.features.length) {
+ * eqFeatureIndex = 0;
+ * } else {
+ * eqFeatureIndex += 1;
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * const writer = createWriter('squares.txt');
+ * for (let i = 0; i < 10; i++) {
+ * writer.print(i * i);
+ * }
+ * writer.close();
+ * writer.clear();
+ * }
+ * }
+ *
+ *
+ * // creates a file called 'newFile.txt'
+ * let writer = createWriter('newFile.txt');
+ * // write 'Hello world!'' to the file
+ * writer.write(['Hello world!']);
+ * // close the PrintWriter and save the file
+ * writer.close();
+ *
+ *
+ * // creates a file called 'newFile2.txt'
+ * let writer = createWriter('newFile2.txt');
+ * // write 'apples,bananas,123' to the file
+ * writer.write(['apples', 'bananas', 123]);
+ * // close the PrintWriter and save the file
+ * writer.close();
+ *
+ *
+ * // creates a file called 'newFile3.txt'
+ * let writer = createWriter('newFile3.txt');
+ * // write 'My name is: Teddy' to the file
+ * writer.write('My name is:');
+ * writer.write(' Teddy');
+ * // close the PrintWriter and save the file
+ * writer.close();
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * button = createButton('SAVE FILE');
+ * button.position(21, 40);
+ * button.mousePressed(createFile);
+ * }
+ *
+ * function createFile() {
+ * // creates a file called 'newFile.txt'
+ * let writer = createWriter('newFile.txt');
+ * // write 'Hello world!'' to the file
+ * writer.write(['Hello world!']);
+ * // close the PrintWriter and save the file
+ * writer.close();
+ * }
+ *
+ *
+ * // creates a file called 'newFile.txt'
+ * let writer = createWriter('newFile.txt');
+ * // creates a file containing
+ * // My name is:
+ * // Teddy
+ * writer.print('My name is:');
+ * writer.print('Teddy');
+ * // close the PrintWriter and save the file
+ * writer.close();
+ *
+ *
+ * let writer;
+ *
+ * function setup() {
+ * createCanvas(400, 400);
+ * // create a PrintWriter
+ * writer = createWriter('newFile.txt');
+ * }
+ *
+ * function draw() {
+ * writer.print([mouseX, mouseY]);
+ * }
+ *
+ * function mouseClicked() {
+ * writer.close();
+ * }
+ *
+ *
+ * // create writer object
+ * let writer = createWriter('newFile.txt');
+ * writer.write(['clear me']);
+ * // clear writer object here
+ * writer.clear();
+ * // close writer
+ * writer.close();
+ *
+ * function setup() {
+ * button = createButton('CLEAR ME');
+ * button.position(21, 40);
+ * button.mousePressed(createFile);
+ * }
+ *
+ * function createFile() {
+ * let writer = createWriter('newFile.txt');
+ * writer.write(['clear me']);
+ * writer.clear();
+ * writer.close();
+ * }
+ *
+ *
+ * // create a file called 'newFile.txt'
+ * let writer = createWriter('newFile.txt');
+ * // close the PrintWriter and save the file
+ * writer.close();
+ *
+ *
+ * // create a file called 'newFile2.txt'
+ * let writer = createWriter('newFile2.txt');
+ * // write some data to the file
+ * writer.write([100, 101, 102]);
+ * // close the PrintWriter and save the file
+ * writer.close();
+ *
+ * true
indicates that the
+ * output will be optimized for filesize,
+ * rather than readability.
+ *
+ * @example
+ *
+ * // Saves the canvas as an image
+ * cnv = createCanvas(300, 300);
+ * save(cnv, 'myCanvas.jpg');
+ *
+ * // Saves the canvas as an image by default
+ * save('myCanvas.jpg');
+ *
+ * // Saves p5.Image as an image
+ * img = createImage(10, 10);
+ * save(img, 'myImage.png');
+ *
+ * // Saves p5.Renderer object as an image
+ * obj = createGraphics(100, 100);
+ * save(obj, 'myObject.png');
+ *
+ * let myTable = new p5.Table();
+ * // Saves table as html file
+ * save(myTable, 'myTable.html');
+ *
+ * // Comma Separated Values
+ * save(myTable, 'myTable.csv');
+ *
+ * // Tab Separated Values
+ * save(myTable, 'myTable.tsv');
+ *
+ * let myJSON = { a: 1, b: true };
+ *
+ * // Saves pretty JSON
+ * save(myJSON, 'my.json');
+ *
+ * // Optimizes JSON filesize
+ * save(myJSON, 'my.json', true);
+ *
+ * // Saves array of strings to text file with line breaks after each item
+ * let arrayOfStrings = ['a', 'b'];
+ * save(arrayOfStrings, 'my.txt');
+ *
+ * let json = {}; // new JSON Object
+ *
+ * json.id = 0;
+ * json.species = 'Panthera leo';
+ * json.name = 'Lion';
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * saveJSON(json, 'lion.json');
+ * }
+ * }
+ *
+ * // saves the following to a file called "lion.json":
+ * // {
+ * // "id": 0,
+ * // "species": "Panthera leo",
+ * // "name": "Lion"
+ * // }
+ *
+ * let words = 'apple bear cat dog';
+ *
+ * // .split() outputs an Array
+ * let list = split(words, ' ');
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * saveStrings(list, 'nouns.txt');
+ * }
+ * }
+ *
+ * // Saves the following to a file called 'nouns.txt':
+ * //
+ * // apple
+ * // bear
+ * // cat
+ * // dog
+ *
+ * let table;
+ *
+ * function setup() {
+ * table = new p5.Table();
+ *
+ * table.addColumn('id');
+ * table.addColumn('species');
+ * table.addColumn('name');
+ *
+ * let newRow = table.addRow();
+ * newRow.setNum('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Panthera leo');
+ * newRow.setString('name', 'Lion');
+ *
+ * // To save, un-comment next line then click 'run'
+ * // saveTable(table, 'new.csv');
+ * }
+ *
+ * // Saves the following to a file called 'new.csv':
+ * // id,species,name
+ * // 0,Panthera leo,Lion
+ *
'.concat(e)); + pWriter.print(' | '); + } + pWriter.print('
'.concat(htmlEntry)); + pWriter.print(' | '); + } + pWriter.print('
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //print the column names
+ * for (let c = 0; c < table.getColumnCount(); c++) {
+ * print('column ' + c + ' is named ' + table.columns[c]);
+ * }
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //add a row
+ * let newRow = table.addRow();
+ * newRow.setString('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Canis Lupus');
+ * newRow.setString('name', 'Wolf');
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //remove the first row
+ * table.removeRow(0);
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let row = table.getRow(1);
+ * //print it column by column
+ * //note: a row is an object, not an array
+ * for (let c = 0; c < table.getColumnCount(); c++) {
+ * print(row.getString(c));
+ * }
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ *
+ * //warning: rows is an array of objects
+ * for (let r = 0; r < rows.length; r++) {
+ * rows[r].set('name', 'Unicorn');
+ * }
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //find the animal named zebra
+ * let row = table.findRow('Zebra', 'name');
+ * //find the corresponding species
+ * print(row.getString('species'));
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //add another goat
+ * let newRow = table.addRow();
+ * newRow.setString('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Scape Goat');
+ * newRow.setString('name', 'Goat');
+ *
+ * //find the rows containing animals named Goat
+ * let rows = table.findRows('Goat', 'name');
+ * print(rows.length + ' Goats found');
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //Search using specified regex on a given column, return TableRow object
+ * let mammal = table.matchRow(new RegExp('ant'), 1);
+ * print(mammal.getString(1));
+ * //Output "Panthera pardus"
+ * }
+ *
+ *
+ * let table;
+ *
+ * function setup() {
+ * table = new p5.Table();
+ *
+ * table.addColumn('name');
+ * table.addColumn('type');
+ *
+ * let newRow = table.addRow();
+ * newRow.setString('name', 'Lion');
+ * newRow.setString('type', 'Mammal');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', 'Snake');
+ * newRow.setString('type', 'Reptile');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', 'Mosquito');
+ * newRow.setString('type', 'Insect');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', 'Lizard');
+ * newRow.setString('type', 'Reptile');
+ *
+ * let rows = table.matchRows('R.*', 'type');
+ * for (let i = 0; i < rows.length; i++) {
+ * print(rows[i].getString('name') + ': ' + rows[i].getString('type'));
+ * }
+ * }
+ * // Sketch prints:
+ * // Snake: Reptile
+ * // Lizard: Reptile
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //getColumn returns an array that can be printed directly
+ * print(table.getColumn('species'));
+ * //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"]
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.clearRows();
+ * print(table.getRowCount() + ' total rows in table');
+ * print(table.getColumnCount() + ' total columns in table');
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.addColumn('carnivore');
+ * table.set(0, 'carnivore', 'no');
+ * table.set(1, 'carnivore', 'yes');
+ * table.set(2, 'carnivore', 'no');
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ * }
+ *
+ *
+ * // given the cvs file "blobs.csv" in /assets directory
+ * // ID, Name, Flavor, Shape, Color
+ * // Blob1, Blobby, Sweet, Blob, Pink
+ * // Blob2, Saddy, Savory, Blob, Blue
+ *
+ * let table;
+ *
+ * function preload() {
+ * table = loadTable('assets/blobs.csv');
+ * }
+ *
+ * function setup() {
+ * createCanvas(200, 100);
+ * textAlign(CENTER);
+ * background(255);
+ * }
+ *
+ * function draw() {
+ * let numOfColumn = table.getColumnCount();
+ * text('There are ' + numOfColumn + ' columns in the table.', 100, 50);
+ * }
+ *
+ *
+ * // given the cvs file "blobs.csv" in /assets directory
+ * //
+ * // ID, Name, Flavor, Shape, Color
+ * // Blob1, Blobby, Sweet, Blob, Pink
+ * // Blob2, Saddy, Savory, Blob, Blue
+ *
+ * let table;
+ *
+ * function preload() {
+ * table = loadTable('assets/blobs.csv');
+ * }
+ *
+ * function setup() {
+ * createCanvas(200, 100);
+ * textAlign(CENTER);
+ * background(255);
+ * }
+ *
+ * function draw() {
+ * text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * let table = new p5.Table();
+ *
+ * table.addColumn('name');
+ * table.addColumn('type');
+ *
+ * let newRow = table.addRow();
+ * newRow.setString('name', ' $Lion ,');
+ * newRow.setString('type', ',,,Mammal');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', '$Snake ');
+ * newRow.setString('type', ',,,Reptile');
+ *
+ * table.removeTokens(',$ ');
+ * print(table.getArray());
+ * }
+ *
+ * // prints:
+ * // 0 "Lion" "Mamal"
+ * // 1 "Snake" "Reptile"
+ *
+ * function setup() {
+ * let table = new p5.Table();
+ *
+ * table.addColumn('name');
+ * table.addColumn('type');
+ *
+ * let newRow = table.addRow();
+ * newRow.setString('name', ' Lion ,');
+ * newRow.setString('type', ' Mammal ');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', ' Snake ');
+ * newRow.setString('type', ' Reptile ');
+ *
+ * table.trim();
+ * print(table.getArray());
+ * }
+ *
+ * // prints:
+ * // 0 "Lion" "Mamal"
+ * // 1 "Snake" "Reptile"
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.removeColumn('id');
+ * print(table.getColumnCount());
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.set(0, 'species', 'Canis Lupus');
+ * table.set(0, 'name', 'Wolf');
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.setNum(1, 'id', 1);
+ *
+ * print(table.getColumn(0));
+ * //["0", 1, "2"]
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //add a row
+ * let newRow = table.addRow();
+ * newRow.setString('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Canis Lupus');
+ * newRow.setString('name', 'Wolf');
+ *
+ * print(table.getArray());
+ * }
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * print(table.get(0, 1));
+ * //Capra hircus
+ * print(table.get(0, 'species'));
+ * //Capra hircus
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * print(table.getNum(1, 0) + 100);
+ * //id 1 + 100 = 101
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * // table is comma separated value "CSV"
+ * // and has specifiying header for column labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * print(table.getString(0, 0)); // 0
+ * print(table.getString(0, 1)); // Capra hircus
+ * print(table.getString(0, 2)); // Goat
+ * print(table.getString(1, 0)); // 1
+ * print(table.getString(1, 1)); // Panthera pardus
+ * print(table.getString(1, 2)); // Leopard
+ * print(table.getString(2, 0)); // 2
+ * print(table.getString(2, 1)); // Equus zebra
+ * print(table.getString(2, 2)); // Zebra
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let tableObject = table.getObject();
+ *
+ * print(tableObject);
+ * //outputs an object
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leoperd
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * // table is comma separated value "CSV"
+ * // and has specifiying header for column labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let tableArray = table.getArray();
+ * for (let i = 0; i < tableArray.length; i++) {
+ * print(tableArray[i]);
+ * }
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * rows[r].set('name', 'Unicorn');
+ * }
+ *
+ * //print the results
+ * print(table.getArray());
+ * }
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * rows[r].setNum('id', r + 10);
+ * }
+ *
+ * print(table.getArray());
+ * }
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * let name = rows[r].getString('name');
+ * rows[r].setString('name', 'A ' + name + ' named George');
+ * }
+ *
+ * print(table.getArray());
+ * }
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let names = [];
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * names.push(rows[r].get('name'));
+ * }
+ *
+ * print(names);
+ * }
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * let minId = Infinity;
+ * let maxId = -Infinity;
+ * for (let r = 0; r < rows.length; r++) {
+ * let id = rows[r].getNum('id');
+ * minId = min(minId, id);
+ * maxId = min(maxId, id);
+ * }
+ * print('minimum id = ' + minId + ', maximum id = ' + maxId);
+ * }
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * let longest = '';
+ * for (let r = 0; r < rows.length; r++) {
+ * let species = rows[r].getString('species');
+ * if (longest.length < species.length) {
+ * longest = species;
+ * }
+ * }
+ *
+ * print('longest: ' + longest);
+ * }
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let children = xml.getChildren('animal');
+ *
+ * for (let i = 0; i < children.length; i++) {
+ * let id = children[i].getNum('id');
+ * let coloring = children[i].getString('species');
+ * let name = children[i].getContent();
+ * print(id + ', ' + coloring + ', ' + name);
+ * }
+ * }
+ *
+ * // Sketch prints:
+ * // 0, Capra hircus, Goat
+ * // 1, Panthera pardus, Leopard
+ * // 2, Equus zebra, Zebra
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let children = xml.getChildren('animal');
+ * let parent = children[1].getParent();
+ * print(parent.getName());
+ * }
+ *
+ * // Sketch prints:
+ * // mammals
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * print(xml.getName());
+ * }
+ *
+ * // Sketch prints:
+ * // mammals
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * print(xml.getName());
+ * xml.setName('fish');
+ * print(xml.getName());
+ * }
+ *
+ * // Sketch prints:
+ * // mammals
+ * // fish
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * print(xml.hasChildren());
+ * }
+ *
+ * // Sketch prints:
+ * // true
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * print(xml.listChildren());
+ * }
+ *
+ * // Sketch prints:
+ * // ["animal", "animal", "animal"]
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let animals = xml.getChildren('animal');
+ *
+ * for (let i = 0; i < animals.length; i++) {
+ * print(animals[i].getContent());
+ * }
+ * }
+ *
+ * // Sketch prints:
+ * // "Goat"
+ * // "Leopard"
+ * // "Zebra"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getContent());
+ * }
+ *
+ * // Sketch prints:
+ * // "Goat"
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let secondChild = xml.getChild(1);
+ * print(secondChild.getContent());
+ * }
+ *
+ * // Sketch prints:
+ * // "Leopard"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let child = new p5.XML();
+ * child.setName('animal');
+ * child.setAttribute('id', '3');
+ * child.setAttribute('species', 'Ornithorhynchus anatinus');
+ * child.setContent('Platypus');
+ * xml.addChild(child);
+ *
+ * let animals = xml.getChildren('animal');
+ * print(animals[animals.length - 1].getContent());
+ * }
+ *
+ * // Sketch prints:
+ * // "Goat"
+ * // "Leopard"
+ * // "Zebra"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * xml.removeChild('animal');
+ * let children = xml.getChildren();
+ * for (let i = 0; i < children.length; i++) {
+ * print(children[i].getContent());
+ * }
+ * }
+ *
+ * // Sketch prints:
+ * // "Leopard"
+ * // "Zebra"
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * xml.removeChild(1);
+ * let children = xml.getChildren();
+ * for (let i = 0; i < children.length; i++) {
+ * print(children[i].getContent());
+ * }
+ * }
+ *
+ * // Sketch prints:
+ * // "Goat"
+ * // "Zebra"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getAttributeCount());
+ * }
+ *
+ * // Sketch prints:
+ * // 2
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.listAttributes());
+ * }
+ *
+ * // Sketch prints:
+ * // ["id", "species"]
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.hasAttribute('species'));
+ * print(firstChild.hasAttribute('color'));
+ * }
+ *
+ * // Sketch prints:
+ * // true
+ * // false
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getNum('id'));
+ * }
+ *
+ * // Sketch prints:
+ * // 0
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getString('species'));
+ * }
+ *
+ * // Sketch prints:
+ * // "Capra hircus"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getString('species'));
+ * firstChild.setAttribute('species', 'Jamides zebra');
+ * print(firstChild.getString('species'));
+ * }
+ *
+ * // Sketch prints:
+ * // "Capra hircus"
+ * // "Jamides zebra"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getContent());
+ * }
+ *
+ * // Sketch prints:
+ * // "Goat"
+ *
+ * // The following short XML file called "mammals.xml" is parsed
+ * // in the code below.
+ * //
+ * //
+ * // <mammals>
+ * // <animal id="0" species="Capra hircus">Goat</animal>
+ * // <animal id="1" species="Panthera pardus">Leopard</animal>
+ * // <animal id="2" species="Equus zebra">Zebra</animal>
+ * // </mammals>
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * let firstChild = xml.getChild('animal');
+ * print(firstChild.getContent());
+ * firstChild.setContent('Mountain Goat');
+ * print(firstChild.getContent());
+ * }
+ *
+ * // Sketch prints:
+ * // "Goat"
+ * // "Mountain Goat"
+ *
+ * let xml;
+ *
+ * function preload() {
+ * xml = loadXML('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * print(xml.serialize());
+ * }
+ *
+ * // Sketch prints:
+ * //
+ * // Goat
+ * // Leopard
+ * // Zebra
+ * //
+ *
+ * function setup() {
+ * let x = -3;
+ * let y = abs(x);
+ *
+ * print(x); // -3
+ * print(y); // 3
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * // map, mouseX between 0 and 5.
+ * let ax = map(mouseX, 0, 100, 0, 5);
+ * let ay = 66;
+ *
+ * //Get the ceiling of the mapped number.
+ * let bx = ceil(map(mouseX, 0, 100, 0, 5));
+ * let by = 33;
+ *
+ * // Multiply the mapped numbers by 20 to more easily
+ * // see the changes.
+ * stroke(0);
+ * fill(0);
+ * line(0, ay, ax * 20, ay);
+ * line(0, by, bx * 20, by);
+ *
+ * // Reformat the float returned by map and draw it.
+ * noStroke();
+ * text(nfc(ax, 2), ax, ay - 5);
+ * text(nfc(bx, 1), bx, by - 5);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * let leftWall = 25;
+ * let rightWall = 75;
+ *
+ * // xm is just the mouseX, while
+ * // xc is the mouseX, but constrained
+ * // between the leftWall and rightWall!
+ * let xm = mouseX;
+ * let xc = constrain(mouseX, leftWall, rightWall);
+ *
+ * // Draw the walls.
+ * stroke(150);
+ * line(leftWall, 0, leftWall, height);
+ * line(rightWall, 0, rightWall, height);
+ *
+ * // Draw xm and xc as circles.
+ * noStroke();
+ * fill(150);
+ * ellipse(xm, 33, 9, 9); // Not Constrained
+ * fill(0);
+ * ellipse(xc, 66, 9, 9); // Constrained
+ * }
+ *
+ * // Move your mouse inside the canvas to see the
+ * // change in distance between two points!
+ * function draw() {
+ * background(200);
+ * fill(0);
+ *
+ * let x1 = 10;
+ * let y1 = 90;
+ * let x2 = mouseX;
+ * let y2 = mouseY;
+ *
+ * line(x1, y1, x2, y2);
+ * ellipse(x1, y1, 7, 7);
+ * ellipse(x2, y2, 7, 7);
+ *
+ * // d is the length of the line
+ * // the distance from point 1 to point 2.
+ * let d = dist(x1, y1, x2, y2);
+ *
+ * // Let's write d along the line we are drawing!
+ * push();
+ * translate((x1 + x2) / 2, (y1 + y2) / 2);
+ * rotate(atan2(y2 - y1, x2 - x1));
+ * text(nfc(d, 1), 0, -5);
+ * pop();
+ * // Fancy!
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Compute the exp() function with a value between 0 and 2
+ * let xValue = map(mouseX, 0, width, 0, 2);
+ * let yValue = exp(xValue);
+ *
+ * let y = map(yValue, 0, 8, height, 0);
+ *
+ * let legend = 'exp (' + nfc(xValue, 3) + ')\n= ' + nf(yValue, 1, 4);
+ * stroke(150);
+ * line(mouseX, y, mouseX, height);
+ * fill(0);
+ * text(legend, 5, 15);
+ * noStroke();
+ * ellipse(mouseX, y, 7, 7);
+ *
+ * // Draw the exp(x) curve,
+ * // over the domain of x from 0 to 2
+ * noFill();
+ * stroke(0);
+ * beginShape();
+ * for (let x = 0; x < width; x++) {
+ * xValue = map(x, 0, width, 0, 2);
+ * yValue = exp(xValue);
+ * y = map(yValue, 0, 8, height, 0);
+ * vertex(x, y);
+ * }
+ *
+ * endShape();
+ * line(0, 0, 0, height);
+ * line(0, height - 1, width, height - 1);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * //map, mouseX between 0 and 5.
+ * let ax = map(mouseX, 0, 100, 0, 5);
+ * let ay = 66;
+ *
+ * //Get the floor of the mapped number.
+ * let bx = floor(map(mouseX, 0, 100, 0, 5));
+ * let by = 33;
+ *
+ * // Multiply the mapped numbers by 20 to more easily
+ * // see the changes.
+ * stroke(0);
+ * fill(0);
+ * line(0, ay, ax * 20, ay);
+ * line(0, by, bx * 20, by);
+ *
+ * // Reformat the float returned by map and draw it.
+ * noStroke();
+ * text(nfc(ax, 2), ax, ay - 5);
+ * text(nfc(bx, 1), bx, by - 5);
+ * }
+ *
+ * function setup() {
+ * background(200);
+ * let a = 20;
+ * let b = 80;
+ * let c = lerp(a, b, 0.2);
+ * let d = lerp(a, b, 0.5);
+ * let e = lerp(a, b, 0.8);
+ *
+ * let y = 50;
+ *
+ * strokeWeight(5);
+ * stroke(0); // Draw the original points in black
+ * point(a, y);
+ * point(b, y);
+ *
+ * stroke(100); // Draw the lerp points in gray
+ * point(c, y);
+ * point(d, y);
+ * point(e, y);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * let maxX = 2.8;
+ * let maxY = 1.5;
+ *
+ * // Compute the natural log of a value between 0 and maxX
+ * let xValue = map(mouseX, 0, width, 0, maxX);
+ * let yValue, y;
+ * if (xValue > 0) {
+ // Cannot take the log of a negative number.
+ * yValue = log(xValue);
+ * y = map(yValue, -maxY, maxY, height, 0);
+ *
+ * // Display the calculation occurring.
+ * let legend = 'log(' + nf(xValue, 1, 2) + ')\n= ' + nf(yValue, 1, 3);
+ * stroke(150);
+ * line(mouseX, y, mouseX, height);
+ * fill(0);
+ * text(legend, 5, 15);
+ * noStroke();
+ * ellipse(mouseX, y, 7, 7);
+ * }
+ *
+ * // Draw the log(x) curve,
+ * // over the domain of x from 0 to maxX
+ * noFill();
+ * stroke(0);
+ * beginShape();
+ * for (let x = 0; x < width; x++) {
+ * xValue = map(x, 0, width, 0, maxX);
+ * yValue = log(xValue);
+ * y = map(yValue, -maxY, maxY, height, 0);
+ * vertex(x, y);
+ * }
+ * endShape();
+ * line(0, 0, 0, height);
+ * line(0, height / 2, width, height / 2);
+ * }
+ *
+ * function setup() {
+ * let x1 = 20;
+ * let x2 = 80;
+ * let y1 = 30;
+ * let y2 = 70;
+ *
+ * line(0, 0, x1, y1);
+ * print(mag(x1, y1)); // Prints "36.05551275463989"
+ * line(0, 0, x2, y1);
+ * print(mag(x2, y1)); // Prints "85.44003745317531"
+ * line(0, 0, x1, y2);
+ * print(mag(x1, y2)); // Prints "72.80109889280519"
+ * line(0, 0, x2, y2);
+ * print(mag(x2, y2)); // Prints "106.3014581273465"
+ * }
+ *
+ * let value = 25;
+ * let m = map(value, 0, 100, 0, width);
+ * ellipse(m, 50, 10, 10);
+
+ * function setup() {
+ * noStroke();
+ * }
+ *
+ * function draw() {
+ * background(204);
+ * let x1 = map(mouseX, 0, width, 25, 75);
+ * ellipse(x1, 25, 25, 25);
+ * //This ellipse is constrained to the 0-100 range
+ * //after setting withinBounds to true
+ * let x2 = map(mouseX, 0, width, 0, 100, true);
+ * ellipse(x2, 75, 25, 25);
+ * }
+
+ * function setup() {
+ * // Change the elements in the array and run the sketch
+ * // to show how max() works!
+ * let numArray = [2, 1, 5, 4, 8, 9];
+ * fill(0);
+ * noStroke();
+ * text('Array Elements', 0, 10);
+ * // Draw all numbers in the array
+ * let spacing = 15;
+ * let elemsY = 25;
+ * for (let i = 0; i < numArray.length; i++) {
+ * text(numArray[i], i * spacing, elemsY);
+ * }
+ * let maxX = 33;
+ * let maxY = 80;
+ * // Draw the Maximum value in the array.
+ * textSize(32);
+ * text(max(numArray), maxX, maxY);
+ * }
+ *
+ * function setup() {
+ * // Change the elements in the array and run the sketch
+ * // to show how min() works!
+ * let numArray = [2, 1, 5, 4, 8, 9];
+ * fill(0);
+ * noStroke();
+ * text('Array Elements', 0, 10);
+ * // Draw all numbers in the array
+ * let spacing = 15;
+ * let elemsY = 25;
+ * for (let i = 0; i < numArray.length; i++) {
+ * text(numArray[i], i * spacing, elemsY);
+ * }
+ * let maxX = 33;
+ * let maxY = 80;
+ * // Draw the Minimum value in the array.
+ * textSize(32);
+ * text(min(numArray), maxX, maxY);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * let currentNum = mouseX;
+ * let lowerBound = 0;
+ * let upperBound = width; //100;
+ * let normalized = norm(currentNum, lowerBound, upperBound);
+ * let lineY = 70;
+ * stroke(3);
+ * line(0, lineY, width, lineY);
+ * //Draw an ellipse mapped to the non-normalized value.
+ * noStroke();
+ * fill(50);
+ * let s = 7; // ellipse size
+ * ellipse(currentNum, lineY, s, s);
+ *
+ * // Draw the guide
+ * let guideY = lineY + 15;
+ * text('0', 0, guideY);
+ * textAlign(RIGHT);
+ * text('100', width, guideY);
+ *
+ * // Draw the normalized value
+ * textAlign(LEFT);
+ * fill(0);
+ * textSize(32);
+ * let normalY = 40;
+ * let normalX = 20;
+ * text(normalized, normalX, normalY);
+ * }
+ *
+ * function setup() {
+ * //Exponentially increase the size of an ellipse.
+ * let eSize = 3; // Original Size
+ * let eLoc = 10; // Original Location
+ *
+ * ellipse(eLoc, eLoc, eSize, eSize);
+ *
+ * ellipse(eLoc * 2, eLoc * 2, pow(eSize, 2), pow(eSize, 2));
+ *
+ * ellipse(eLoc * 4, eLoc * 4, pow(eSize, 3), pow(eSize, 3));
+ *
+ * ellipse(eLoc * 8, eLoc * 8, pow(eSize, 4), pow(eSize, 4));
+ * }
+ *
+ * let x = round(3.7);
+ * text(x, width / 2, height / 2);
+ *
+ * let x = round(12.782383, 2);
+ * text(x, width / 2, height / 2);
+ *
+ * function draw() {
+ * background(200);
+ * //map, mouseX between 0 and 5.
+ * let ax = map(mouseX, 0, 100, 0, 5);
+ * let ay = 66;
+ *
+ * // Round the mapped number.
+ * let bx = round(map(mouseX, 0, 100, 0, 5));
+ * let by = 33;
+ *
+ * // Multiply the mapped numbers by 20 to more easily
+ * // see the changes.
+ * stroke(0);
+ * fill(0);
+ * line(0, ay, ax * 20, ay);
+ * line(0, by, bx * 20, by);
+ *
+ * // Reformat the float returned by map and draw it.
+ * noStroke();
+ * text(nfc(ax, 2), ax, ay - 5);
+ * text(nfc(bx, 1), bx, by - 5);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * let eSize = 7;
+ * let x1 = map(mouseX, 0, width, 0, 10);
+ * let y1 = 80;
+ * let x2 = sq(x1);
+ * let y2 = 20;
+ *
+ * // Draw the non-squared.
+ * line(0, y1, width, y1);
+ * ellipse(x1, y1, eSize, eSize);
+ *
+ * // Draw the squared.
+ * line(0, y2, width, y2);
+ * ellipse(x2, y2, eSize, eSize);
+ *
+ * // Draw dividing line.
+ * stroke(100);
+ * line(0, height / 2, width, height / 2);
+ *
+ * // Draw text.
+ * let spacing = 15;
+ * noStroke();
+ * fill(0);
+ * text('x = ' + x1, 0, y1 + spacing);
+ * text('sq(x) = ' + x2, 0, y2 + spacing);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * let eSize = 7;
+ * let x1 = mouseX;
+ * let y1 = 80;
+ * let x2 = sqrt(x1);
+ * let y2 = 20;
+ *
+ * // Draw the non-squared.
+ * line(0, y1, width, y1);
+ * ellipse(x1, y1, eSize, eSize);
+ *
+ * // Draw the squared.
+ * line(0, y2, width, y2);
+ * ellipse(x2, y2, eSize, eSize);
+ *
+ * // Draw dividing line.
+ * stroke(100);
+ * line(0, height / 2, width, height / 2);
+ *
+ * // Draw text.
+ * noStroke();
+ * fill(0);
+ * let spacing = 15;
+ * text('x = ' + x1, 0, y1 + spacing);
+ * text('sqrt(x) = ' + x2, 0, y2 + spacing);
+ * }
+ *
+ * function setup() {
+ * createCanvas(windowWidth, windowHeight);
+ * fill(0);
+ * text(7345.73472742, 0, 50);
+ * text(fract(7345.73472742), 0, 100);
+ * text(1.4215e-15, 150, 50);
+ * text(fract(1.4215e-15), 150, 100);
+ * }
+ *
+ *
+ * let v1;
+ * function setup() {
+ * createCanvas(100, 100);
+ * stroke(255, 0, 255);
+ * v1 = createVector(width / 2, height / 2);
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * line(v1.x, v1.y, mouseX, mouseY);
+ * }
+ *
+ * let xoff = 0.0;
+ *
+ * function draw() {
+ * background(204);
+ * xoff = xoff + 0.01;
+ * let n = noise(xoff) * width;
+ * line(n, 0, n, height);
+ * }
+ *
+ * let noiseScale=0.02;
+ *
+ * function draw() {
+ * background(0);
+ * for (let x=0; x < width; x++) {
+ * let noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale);
+ * stroke(noiseVal*255);
+ * line(x, mouseY+noiseVal*80, x, height);
+ * }
+ * }
+ *
+ *
+ * let noiseVal;
+ * let noiseScale = 0.02;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * for (let y = 0; y < height; y++) {
+ * for (let x = 0; x < width / 2; x++) {
+ * noiseDetail(2, 0.2);
+ * noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale);
+ * stroke(noiseVal * 255);
+ * point(x, y);
+ * noiseDetail(8, 0.65);
+ * noiseVal = noise(
+ * (mouseX + x + width / 2) * noiseScale,
+ * (mouseY + y) * noiseScale
+ * );
+ * stroke(noiseVal * 255);
+ * point(x + width / 2, y);
+ * }
+ * }
+ * }
+ *
+ * let xoff = 0.0;
+ *
+ * function setup() {
+ * noiseSeed(99);
+ * stroke(0, 10);
+ * }
+ *
+ * function draw() {
+ * xoff = xoff + .01;
+ * let n = noise(xoff) * width;
+ * line(n, 0, n, height);
+ * }
+ *
+ *
+ * let v1 = createVector(40, 50);
+ * let v2 = createVector(40, 50);
+ *
+ * ellipse(v1.x, v1.y, 50, 50);
+ * ellipse(v2.x, v2.y, 50, 50);
+ * v1.add(v2);
+ * ellipse(v1.x, v1.y, 50, 50);
+ *
+ *
+ * function setup() {
+ * let v = createVector(20, 30);
+ * print(String(v)); // prints "p5.Vector Object : [20, 30, 0]"
+ * }
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v1, 'black');
+ *
+ * noStroke();
+ * text(v1.toString(), 10, 25, 90, 75);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * function setup() {
+ * let v = createVector(1, 2, 3);
+ * v.set(4, 5, 6); // Sets vector to [4, 5, 6]
+ *
+ * let v1 = createVector(0, 0, 0);
+ * let arr = [1, 2, 3];
+ * v1.set(arr); // Sets vector to [1, 2, 3]
+ * }
+ *
+ *
+ * let v0, v1;
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * v0 = createVector(0, 0);
+ * v1 = createVector(50, 50);
+ * }
+ *
+ * function draw() {
+ * background(240);
+ *
+ * drawArrow(v0, v1, 'black');
+ * v1.set(v1.x + random(-1, 1), v1.y + random(-1, 1));
+ *
+ * noStroke();
+ * text('x: ' + round(v1.x) + ' y: ' + round(v1.y), 20, 90);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v1 = createVector(1, 2, 3);
+ * let v2 = v1.copy();
+ * print(v1.x === v2.x && v1.y === v2.y && v1.z === v2.z);
+ * // Prints "true"
+ *
+ *
+ * let v = createVector(1, 2, 3);
+ * v.add(4, 5, 6);
+ * // v's components are set to [5, 7, 9]
+ *
+ *
+ * let v = createVector(1, 2, 3);
+ * // Provide arguments as an array
+ * let arr = [4, 5, 6];
+ * v.add(arr);
+ * // v's components are set to [5, 7, 9]
+ *
+ *
+ * // Static method
+ * let v1 = createVector(1, 2, 3);
+ * let v2 = createVector(2, 3, 4);
+ *
+ * let v3 = p5.Vector.add(v1, v2);
+ * // v3 has components [3, 5, 7]
+ * print(v3);
+ *
+ *
+ * // red vector + blue vector = purple vector
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let v2 = createVector(-30, 20);
+ * drawArrow(v1, v2, 'blue');
+ *
+ * let v3 = p5.Vector.add(v1, v2);
+ * drawArrow(v0, v3, 'purple');
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(3, 4, 5);
+ * v.rem(2, 3, 4);
+ * // v's components are set to [1, 1, 1]
+ *
+ *
+ * // Static method
+ * let v1 = createVector(3, 4, 5);
+ * let v2 = createVector(2, 3, 4);
+ *
+ * let v3 = p5.Vector.rem(v1, v2);
+ * // v3 has components [1, 1, 1]
+ * print(v3);
+ *
+ *
+ * let v = createVector(4, 5, 6);
+ * v.sub(1, 1, 1);
+ * // v's components are set to [3, 4, 5]
+ *
+ *
+ * let v = createVector(4, 5, 6);
+ * // Provide arguments as an array
+ * let arr = [1, 1, 1];
+ * v.sub(arr);
+ * // v's components are set to [3, 4, 5]
+ *
+ *
+ * // Static method
+ * let v1 = createVector(2, 3, 4);
+ * let v2 = createVector(1, 2, 3);
+ *
+ * let v3 = p5.Vector.sub(v1, v2);
+ * // v3 has components [1, 1, 1]
+ * print(v3);
+ *
+ *
+ * // red vector - blue vector = purple vector
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(70, 50);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let v2 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v2, 'blue');
+ *
+ * let v3 = p5.Vector.sub(v1, v2);
+ * drawArrow(v2, v3, 'purple');
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(1, 2, 3);
+ * v.mult(2);
+ * // v's components are set to [2, 4, 6]
+ *
+ *
+ * let v0 = createVector(1, 2, 3);
+ * let v1 = createVector(2, 3, 4);
+ * v0.mult(v1); // v0's components are set to [2, 6, 12]
+ *
+ *
+ * let v0 = createVector(1, 2, 3);
+ * // Provide arguments as an array
+ * let arr = [2, 3, 4];
+ * v0.mult(arr); // v0's components are set to [2, 6, 12]
+ *
+ *
+ * let v0 = createVector(1, 2, 3);
+ * let v1 = createVector(2, 3, 4);
+ * const result = p5.Vector.mult(v0, v1);
+ * print(result); // result's components are set to [2, 6, 12]
+ *
+ *
+ * // Static method
+ * let v1 = createVector(1, 2, 3);
+ * let v2 = p5.Vector.mult(v1, 2);
+ * // v2 has components [2, 4, 6]
+ * print(v2);
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(50, 50);
+ * let v1 = createVector(25, -25);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let num = map(mouseX, 0, width, -2, 2, true);
+ * let v2 = p5.Vector.mult(v1, num);
+ * drawArrow(v0, v2, 'blue');
+ *
+ * noStroke();
+ * text('multiplied by ' + num.toFixed(2), 5, 90);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(6, 4, 2);
+ * v.div(2); //v's components are set to [3, 2, 1]
+ *
+ *
+ * let v0 = createVector(9, 4, 2);
+ * let v1 = createVector(3, 2, 4);
+ * v0.div(v1); // v0's components are set to [3, 2, 0.5]
+ *
+ *
+ * let v0 = createVector(9, 4, 2);
+ * // Provide arguments as an array
+ * let arr = [3, 2, 4];
+ * v0.div(arr); // v0's components are set to [3, 2, 0.5]
+ *
+ *
+ * let v0 = createVector(9, 4, 2);
+ * let v1 = createVector(3, 2, 4);
+ * let result = p5.Vector.div(v0, v1);
+ * print(result); // result's components are set to [3, 2, 0.5]
+ *
+ *
+ * // Static method
+ * let v1 = createVector(6, 4, 2);
+ * let v2 = p5.Vector.div(v1, 2);
+ * // v2 has components [3, 2, 1]
+ * print(v2);
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 100);
+ * let v1 = createVector(50, -50);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let num = map(mouseX, 0, width, 10, 0.5, true);
+ * let v2 = p5.Vector.div(v1, num);
+ * drawArrow(v0, v2, 'blue');
+ *
+ * noStroke();
+ * text('divided by ' + num.toFixed(2), 10, 90);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v1, 'black');
+ *
+ * noStroke();
+ * text('vector length: ' + v1.mag().toFixed(2), 10, 70, 90, 30);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(20.0, 30.0, 40.0);
+ * let m = v.mag();
+ * print(m); // Prints "53.85164807134504"
+ *
+ *
+ * // Static method
+ * let v1 = createVector(6, 4, 2);
+ * print(v1.magSq()); // Prints "56"
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v1, 'black');
+ *
+ * noStroke();
+ * text('vector length squared: ' + v1.magSq().toFixed(2), 10, 45, 90, 55);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v1 = createVector(1, 2, 3);
+ * let v2 = createVector(2, 3, 4);
+ *
+ * print(v1.dot(v2)); // Prints "20"
+ *
+ *
+ * //Static method
+ * let v1 = createVector(1, 2, 3);
+ * let v2 = createVector(3, 2, 1);
+ * print(p5.Vector.dot(v1, v2)); // Prints "10"
+ *
+ *
+ * let v1 = createVector(1, 2, 3);
+ * let v2 = createVector(1, 2, 3);
+ *
+ * let v = v1.cross(v2); // v's components are [0, 0, 0]
+ * print(v);
+ *
+ *
+ * // Static method
+ * let v1 = createVector(1, 0, 0);
+ * let v2 = createVector(0, 1, 0);
+ *
+ * let crossProduct = p5.Vector.cross(v1, v2);
+ * // crossProduct has components [0, 0, 1]
+ * print(crossProduct);
+ *
+ *
+ * let v1 = createVector(1, 0, 0);
+ * let v2 = createVector(0, 1, 0);
+ *
+ * let distance = v1.dist(v2); // distance is 1.4142...
+ * print(distance);
+ *
+ *
+ * // Static method
+ * let v1 = createVector(1, 0, 0);
+ * let v2 = createVector(0, 1, 0);
+ *
+ * let distance = p5.Vector.dist(v1, v2);
+ * // distance is 1.4142...
+ * print(distance);
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ *
+ * let v1 = createVector(70, 50);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let v2 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v2, 'blue');
+ *
+ * noStroke();
+ * text('distance between vectors: ' + v2.dist(v1).toFixed(2), 5, 50, 95, 50);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(10, 20, 2);
+ * // v has components [10.0, 20.0, 2.0]
+ * v.normalize();
+ * // v's components are set to
+ * // [0.4454354, 0.8908708, 0.089087084]
+ *
+ *
+ * // Static method
+ * let v_initial = createVector(10, 20, 2);
+ * // v_initial has components [10.0, 20.0, 2.0]
+ * let v_normalized = p5.Vector.normalize(v_initial);
+ * print(v_normalized);
+ * // returns a new vector with components set to
+ * // [0.4454354, 0.8908708, 0.089087084]
+ * // v_initial remains unchanged
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(50, 50);
+ * let v1 = createVector(mouseX - 50, mouseY - 50);
+ *
+ * drawArrow(v0, v1, 'red');
+ * v1.normalize();
+ * drawArrow(v0, v1.mult(35), 'blue');
+ *
+ * noFill();
+ * ellipse(50, 50, 35 * 2);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(10, 20, 2);
+ * // v has components [10.0, 20.0, 2.0]
+ * v.limit(5);
+ * // v's components are set to
+ * // [2.2271771, 4.4543543, 0.4454354]
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(50, 50);
+ * let v1 = createVector(mouseX - 50, mouseY - 50);
+ *
+ * drawArrow(v0, v1, 'red');
+ * drawArrow(v0, v1.limit(35), 'blue');
+ *
+ * noFill();
+ * ellipse(50, 50, 35 * 2);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(10, 20, 2);
+ * // v has components [10.0, 20.0, 2.0]
+ * v.setMag(10);
+ * // v's components are set to [6.0, 8.0, 0.0]
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(50, 50);
+ *
+ * drawArrow(v0, v1, 'red');
+ *
+ * let length = map(mouseX, 0, width, 0, 141, true);
+ * v1.setMag(length);
+ * drawArrow(v0, v1, 'blue');
+ *
+ * noStroke();
+ * text('magnitude set to: ' + length.toFixed(2), 10, 70, 90, 30);
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * function setup() {
+ * let v1 = createVector(30, 50);
+ * print(v1.heading()); // 1.0303768265243125
+ *
+ * v1 = createVector(40, 50);
+ * print(v1.heading()); // 0.8960553845713439
+ *
+ * v1 = createVector(30, 70);
+ * print(v1.heading()); // 1.1659045405098132
+ * }
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(50, 50);
+ * let v1 = createVector(mouseX - 50, mouseY - 50);
+ *
+ * drawArrow(v0, v1, 'black');
+ *
+ * let myHeading = v1.heading();
+ * noStroke();
+ * text(
+ * 'vector heading: ' +
+ * myHeading.toFixed(2) +
+ * ' radians or ' +
+ * degrees(myHeading).toFixed(2) +
+ * ' degrees',
+ * 10,
+ * 50,
+ * 90,
+ * 50
+ * );
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(10.0, 20.0);
+ * // result of v.heading() is 1.1071487177940904
+ * v.setHeading(Math.PI);
+ * // result of v.heading() is now 3.141592653589793
+ *
+ *
+ * let v = createVector(10.0, 20.0);
+ * // v has components [10.0, 20.0, 0.0]
+ * v.rotate(HALF_PI);
+ * // v's components are set to [-20.0, 9.999999, 0.0]
+ *
+ *
+ * // static function implementation
+ * let v = createVector(10.0, 20.0);
+ * // v has components [10.0, 20.0, 0.0]
+ * let rotated_v = p5.Vector.rotate(v, HALF_PI);
+ * console.log(rotated_v);
+ * // rotated_v's components are set to [-20.0, 9.999999, 0.0]
+ * console.log(v);
+ * // v's components remains the same (i.e, [10.0, 20.0, 0.0])
+ *
+ *
+ * let angle = 0;
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(50, 50);
+ * let v1 = createVector(50, 0);
+ *
+ * drawArrow(v0, v1.rotate(angle), 'black');
+ * angle += 0.01;
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v1 = createVector(1, 0, 0);
+ * let v2 = createVector(0, 1, 0);
+ *
+ * let angle = v1.angleBetween(v2);
+ * // angle is PI/2
+ * print(angle);
+ *
+ *
+ * function draw() {
+ * background(240);
+ * let v0 = createVector(50, 50);
+ *
+ * let v1 = createVector(50, 0);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let v2 = createVector(mouseX - 50, mouseY - 50);
+ * drawArrow(v0, v2, 'blue');
+ *
+ * let angleBetween = v1.angleBetween(v2);
+ * noStroke();
+ * text(
+ * 'angle between: ' +
+ * angleBetween.toFixed(2) +
+ * ' radians or ' +
+ * degrees(angleBetween).toFixed(2) +
+ * ' degrees',
+ * 10,
+ * 50,
+ * 90,
+ * 50
+ * );
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(1, 1, 0);
+ *
+ * v.lerp(3, 3, 0, 0.5); // v now has components [2,2,0]
+ *
+ *
+ * let v1 = createVector(0, 0, 0);
+ * let v2 = createVector(100, 100, 0);
+ *
+ * let v3 = p5.Vector.lerp(v1, v2, 0.5);
+ * // v3 has components [50,50,0]
+ * print(v3);
+ *
+ *
+ * let step = 0.01;
+ * let amount = 0;
+ *
+ * function draw() {
+ * background(240);
+ * let v0 = createVector(0, 0);
+ *
+ * let v1 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let v2 = createVector(90, 90);
+ * drawArrow(v0, v2, 'blue');
+ *
+ * if (amount > 1 || amount < 0) {
+ * step *= -1;
+ * }
+ * amount += step;
+ * let v3 = p5.Vector.lerp(v1, v2, amount);
+ *
+ * drawArrow(v0, v3, 'purple');
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = createVector(4, 6); // incoming vector, this example vector is heading to the right and downward
+ * let n = createVector(0, -1); // surface normal to a plane (this example normal points directly upwards)
+ * v.reflect(n); // v is reflected about the surface normal n. v's components are now set to [4, -6]
+ *
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(0, 0);
+ * let v1 = createVector(mouseX, mouseY);
+ * drawArrow(v0, v1, 'red');
+ *
+ * let n = createVector(0, -30);
+ * drawArrow(v1, n, 'blue');
+ *
+ * let r = v1.copy();
+ * r.reflect(n);
+ * drawArrow(v1, r, 'purple');
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * function setup() {
+ * let v = createVector(20, 30);
+ * print(v.array()); // Prints : Array [20, 30, 0]
+ * }
+ *
+ *
+ * let v = createVector(10.0, 20.0, 30.0);
+ * let f = v.array();
+ * print(f[0]); // Prints "10.0"
+ * print(f[1]); // Prints "20.0"
+ * print(f[2]); // Prints "30.0"
+ *
+ *
+ * let v1 = createVector(5, 10, 20);
+ * let v2 = createVector(5, 10, 20);
+ * let v3 = createVector(13, 10, 19);
+ *
+ * print(v1.equals(v2.x, v2.y, v2.z)); // true
+ * print(v1.equals(v3.x, v3.y, v3.z)); // false
+ *
+ *
+ * let v1 = createVector(10.0, 20.0, 30.0);
+ * let v2 = createVector(10.0, 20.0, 30.0);
+ * let v3 = createVector(0.0, 0.0, 0.0);
+ * print(v1.equals(v2)); // true
+ * print(v1.equals(v3)); // false
+ *
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Create a variable, proportional to the mouseX,
+ * // varying from 0-360, to represent an angle in degrees.
+ * let myDegrees = map(mouseX, 0, width, 0, 360);
+ *
+ * // Display that variable in an onscreen text.
+ * // (Note the nfc() function to truncate additional decimal places,
+ * // and the "\xB0" character for the degree symbol.)
+ * let readout = 'angle = ' + nfc(myDegrees, 1) + '\xB0';
+ * noStroke();
+ * fill(0);
+ * text(readout, 5, 15);
+ *
+ * // Create a p5.Vector using the fromAngle function,
+ * // and extract its x and y components.
+ * let v = p5.Vector.fromAngle(radians(myDegrees), 30);
+ * let vx = v.x;
+ * let vy = v.y;
+ *
+ * push();
+ * translate(width / 2, height / 2);
+ * noFill();
+ * stroke(150);
+ * line(0, 0, 30, 0);
+ * stroke(0);
+ * line(0, 0, vx, vy);
+ * pop();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * fill(255);
+ * noStroke();
+ * }
+ * function draw() {
+ * background(255);
+ *
+ * let t = millis() / 1000;
+ *
+ * // add three point lights
+ * pointLight(color('#f00'), p5.Vector.fromAngles(t * 1.0, t * 1.3, 100));
+ * pointLight(color('#0f0'), p5.Vector.fromAngles(t * 1.1, t * 1.2, 100));
+ * pointLight(color('#00f'), p5.Vector.fromAngles(t * 1.2, t * 1.1, 100));
+ *
+ * sphere(35);
+ * }
+ *
+ *
+ * let v = p5.Vector.random2D();
+ * // May make v's attributes something like:
+ * // [0.61554617, -0.51195765, 0.0] or
+ * // [-0.4695841, -0.14366731, 0.0] or
+ * // [0.6091097, -0.22805278, 0.0]
+ * print(v);
+ *
+ *
+ * function setup() {
+ * frameRate(1);
+ * }
+ *
+ * function draw() {
+ * background(240);
+ *
+ * let v0 = createVector(50, 50);
+ * let v1 = p5.Vector.random2D();
+ * drawArrow(v0, v1.mult(50), 'black');
+ * }
+ *
+ * // draw an arrow for a vector at a given base position
+ * function drawArrow(base, vec, myColor) {
+ * push();
+ * stroke(myColor);
+ * strokeWeight(3);
+ * fill(myColor);
+ * translate(base.x, base.y);
+ * line(0, 0, vec.x, vec.y);
+ * rotate(vec.heading());
+ * let arrowSize = 7;
+ * translate(vec.mag() - arrowSize, 0);
+ * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);
+ * pop();
+ * }
+ *
+ *
+ * let v = p5.Vector.random3D();
+ * // May make v's attributes something like:
+ * // [0.61554617, -0.51195765, 0.599168] or
+ * // [-0.4695841, -0.14366731, -0.8711202] or
+ * // [0.6091097, -0.22805278, -0.7595902]
+ * print(v);
+ *
+ *
+ * randomSeed(99);
+ * for (let i = 0; i < 100; i++) {
+ * let r = random(0, 255);
+ * stroke(r);
+ * line(i, 0, i, 100);
+ * }
+ *
+ *
+ * for (let i = 0; i < 100; i++) {
+ * let r = random(50);
+ * stroke(r * 5);
+ * line(50, i, 50 + r, i);
+ * }
+ *
+ *
+ * for (let i = 0; i < 100; i++) {
+ * let r = random(-50, 50);
+ * line(50, i, 50 + r, i);
+ * }
+ *
+ *
+ * // Get a random element from an array using the random(Array) syntax
+ * let words = ['apple', 'bear', 'cat', 'dog'];
+ * let word = random(words); // select random word
+ * text(word, 10, 50); // draw the word
+ *
+ *
+ * for (let y = 0; y < 100; y++) {
+ * let x = randomGaussian(50, 15);
+ * line(50, y, x, y);
+ * }
+ *
+ *
+ * let distribution = new Array(360);
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * for (let i = 0; i < distribution.length; i++) {
+ * distribution[i] = floor(randomGaussian(0, 15));
+ * }
+ * }
+ *
+ * function draw() {
+ * background(204);
+ *
+ * translate(width / 2, width / 2);
+ *
+ * for (let i = 0; i < distribution.length; i++) {
+ * rotate(TWO_PI / distribution.length);
+ * stroke(0);
+ * let dist = abs(distribution[i]);
+ * line(0, 0, dist, 0);
+ * }
+ * }
+ *
+ *
+ * let a = PI;
+ * let c = cos(a);
+ * let ac = acos(c);
+ * // Prints: "3.1415927 : -1.0 : 3.1415927"
+ * print(a + ' : ' + c + ' : ' + ac);
+ *
+ *
+ * let a = PI + PI / 4.0;
+ * let c = cos(a);
+ * let ac = acos(c);
+ * // Prints: "3.926991 : -0.70710665 : 2.3561943"
+ * print(a + ' : ' + c + ' : ' + ac);
+ *
+ *
+ * let a = PI / 3.0;
+ * let s = sin(a);
+ * let as = asin(s);
+ * // Prints: "1.0471975 : 0.86602540 : 1.0471975"
+ * print(a + ' : ' + s + ' : ' + as);
+ *
+ *
+ * let a = PI + PI / 3.0;
+ * let s = sin(a);
+ * let as = asin(s);
+ * // Prints: "4.1887902 : -0.86602540 : -1.0471975"
+ * print(a + ' : ' + s + ' : ' + as);
+ *
+ *
+ * let a = PI / 3.0;
+ * let t = tan(a);
+ * let at = atan(t);
+ * // Prints: "1.0471975 : 1.7320508 : 1.0471975"
+ * print(a + ' : ' + t + ' : ' + at);
+ *
+ *
+ * let a = PI + PI / 3.0;
+ * let t = tan(a);
+ * let at = atan(t);
+ * // Prints: "4.1887902 : 1.7320508 : 1.0471975"
+ * print(a + ' : ' + t + ' : ' + at);
+ *
+ *
+ * function draw() {
+ * background(204);
+ * translate(width / 2, height / 2);
+ * let a = atan2(mouseY - height / 2, mouseX - width / 2);
+ * rotate(a);
+ * rect(-30, -5, 60, 10);
+ * }
+ *
+ *
+ * let a = 0.0;
+ * let inc = TWO_PI / 25.0;
+ * for (let i = 0; i < 25; i++) {
+ * line(i * 4, 50, i * 4, 50 + cos(a) * 40.0);
+ * a = a + inc;
+ * }
+ *
+ *
+ * let a = 0.0;
+ * let inc = TWO_PI / 25.0;
+ * for (let i = 0; i < 25; i++) {
+ * line(i * 4, 50, i * 4, 50 + sin(a) * 40.0);
+ * a = a + inc;
+ * }
+ *
+ *
+ * let a = 0.0;
+ * let inc = TWO_PI / 50.0;
+ * for (let i = 0; i < 100; i = i + 2) {
+ * line(i, 50, i, 50 + tan(a) * 2.0);
+ * a = a + inc;
+ * }
+ *
+ *
+ * @alt
+ * vertical black lines end down and up from center to form spike pattern
+ */
+ _main.default.prototype.tan = function(angle) {
+ return Math.tan(this._toRadians(angle));
+ };
+
+ /**
+ * Converts a radian measurement to its corresponding value in degrees.
+ * Radians and degrees are two ways of measuring the same thing. There are
+ * 360 degrees in a circle and 2*PI radians in a circle. For example,
+ * 90° = PI/2 = 1.5707964. This function does not take into account the
+ * current angleMode.
+ *
+ * @method degrees
+ * @param {Number} radians the radians value to convert to degrees
+ * @return {Number} the converted angle
+ *
+ * @example
+ *
+ * let rad = PI / 4;
+ * let deg = degrees(rad);
+ * print(rad + ' radians is ' + deg + ' degrees');
+ * // Prints: 0.7853981633974483 radians is 45 degrees
+ *
+ *
+ * let deg = 45.0;
+ * let rad = radians(deg);
+ * print(deg + ' degrees is ' + rad + ' radians');
+ * // Prints: 45 degrees is 0.7853981633974483 radians
+ *
+ *
+ * function draw() {
+ * background(204);
+ * angleMode(DEGREES); // Change the mode to DEGREES
+ * let a = atan2(mouseY - height / 2, mouseX - width / 2);
+ * translate(width / 2, height / 2);
+ * push();
+ * rotate(a);
+ * rect(-20, -5, 40, 10); // Larger rectangle is rotating in degrees
+ * pop();
+ * angleMode(RADIANS); // Change the mode to RADIANS
+ * rotate(a); // variable a stays the same
+ * rect(-40, -5, 20, 10); // Smaller rectangle is rotating in radians
+ * }
+ *
+ *
+ * textSize(16);
+ * textAlign(RIGHT);
+ * text('ABCD', 50, 30);
+ * textAlign(CENTER);
+ * text('EFGH', 50, 50);
+ * textAlign(LEFT);
+ * text('IJKL', 50, 70);
+ *
+ *
+ * textSize(16);
+ * strokeWeight(0.5);
+ *
+ * line(0, 12, width, 12);
+ * textAlign(CENTER, TOP);
+ * text('TOP', 0, 12, width);
+ *
+ * line(0, 37, width, 37);
+ * textAlign(CENTER, CENTER);
+ * text('CENTER', 0, 37, width);
+ *
+ * line(0, 62, width, 62);
+ * textAlign(CENTER, BASELINE);
+ * text('BASELINE', 0, 62, width);
+ *
+ * line(0, 87, width, 87);
+ * textAlign(CENTER, BOTTOM);
+ * text('BOTTOM', 0, 87, width);
+ *
+ *
+ * let lines = 'L1\nL2\nL3'; // "\n" is a "new line" character
+ * textSize(12);
+ *
+ * textLeading(10);
+ * text(lines, 10, 25);
+ *
+ * textLeading(20);
+ * text(lines, 40, 25);
+ *
+ * textLeading(30);
+ * text(lines, 70, 25);
+ *
+ *
+ * textSize(12);
+ * text('Font Size 12', 10, 30);
+ * textSize(14);
+ * text('Font Size 14', 10, 60);
+ * textSize(16);
+ * text('Font Size 16', 10, 90);
+ *
+ *
+ * strokeWeight(0);
+ * textSize(12);
+ * textStyle(NORMAL);
+ * text('Font Style Normal', 10, 15);
+ * textStyle(ITALIC);
+ * text('Font Style Italic', 10, 40);
+ * textStyle(BOLD);
+ * text('Font Style Bold', 10, 65);
+ * textStyle(BOLDITALIC);
+ * text('Font Style Bold Italic', 10, 90);
+ *
+ *
+ * textSize(28);
+ *
+ * let aChar = 'P';
+ * let cWidth = textWidth(aChar);
+ * text(aChar, 0, 40);
+ * line(cWidth, 0, cWidth, 50);
+ *
+ * let aString = 'p5.js';
+ * let sWidth = textWidth(aString);
+ * text(aString, 0, 85);
+ * line(sWidth, 50, sWidth, 100);
+ *
+ *
+ * let base = height * 0.75;
+ * let scalar = 0.8; // Different for each font
+ *
+ * textSize(32); // Set initial text size
+ * let asc = textAscent() * scalar; // Calc ascent
+ * line(0, base - asc, width, base - asc);
+ * text('dp', 0, base); // Draw text on baseline
+ *
+ * textSize(64); // Increase text size
+ * asc = textAscent() * scalar; // Recalc ascent
+ * line(40, base - asc, width, base - asc);
+ * text('dp', 40, base); // Draw text on baseline
+ *
+ *
+ * let base = height * 0.75;
+ * let scalar = 0.8; // Different for each font
+ *
+ * textSize(32); // Set initial text size
+ * let desc = textDescent() * scalar; // Calc ascent
+ * line(0, base + desc, width, base + desc);
+ * text('dp', 0, base); // Draw text on baseline
+ *
+ * textSize(64); // Increase text size
+ * desc = textDescent() * scalar; // Recalc ascent
+ * line(40, base + desc, width, base + desc);
+ * text('dp', 40, base); // Draw text on baseline
+ *
+ *
+ * let myFont;
+ * function preload() {
+ * myFont = loadFont('assets/inconsolata.otf');
+ * }
+ *
+ * function setup() {
+ * fill('#ED225D');
+ * textFont(myFont);
+ * textSize(36);
+ * text('p5*js', 10, 50);
+ * }
+ *
+ * function setup() {
+ * loadFont('assets/inconsolata.otf', drawText);
+ * }
+ *
+ * function drawText(font) {
+ * fill('#ED225D');
+ * textFont(font, 36);
+ * text('p5*js', 10, 50);
+ * }
+ *
+ * function preload() {
+ * loadFont('assets/inconsolata.otf');
+ * }
+ *
+ * function setup() {
+ * let myDiv = createDiv('hello there');
+ * myDiv.style('font-family', 'Inconsolata');
+ * }
+ *
+ * textSize(32);
+ * text('word', 10, 30);
+ * fill(0, 102, 153);
+ * text('word', 10, 60);
+ * fill(0, 102, 153, 51);
+ * text('word', 10, 90);
+ *
+ *
+ * let s = 'The quick brown fox jumped over the lazy dog.';
+ * fill(50);
+ * text(s, 10, 10, 70, 80); // Text wraps within text box
+ *
+ *
+ * let inconsolata;
+ * function preload() {
+ * inconsolata = loadFont('assets/inconsolata.otf');
+ * }
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * textFont(inconsolata);
+ * textSize(width / 3);
+ * textAlign(CENTER, CENTER);
+ * }
+ * function draw() {
+ * background(0);
+ * let time = millis();
+ * rotateX(time / 1000);
+ * rotateZ(time / 1234);
+ * text('p5.js', 0, 0);
+ * }
+ *
+ *
+ * fill(0);
+ * textSize(12);
+ * textFont('Georgia');
+ * text('Georgia', 12, 30);
+ * textFont('Helvetica');
+ * text('Helvetica', 12, 60);
+ *
+ *
+ * let fontRegular, fontItalic, fontBold;
+ * function preload() {
+ * fontRegular = loadFont('assets/Regular.otf');
+ * fontItalic = loadFont('assets/Italic.ttf');
+ * fontBold = loadFont('assets/Bold.ttf');
+ * }
+ * function setup() {
+ * background(210);
+ * fill(0)
+ .strokeWeight(0)
+ .textSize(10);
+ * textFont(fontRegular);
+ * text('Font Style Normal', 10, 30);
+ * textFont(fontItalic);
+ * text('Font Style Italic', 10, 50);
+ * textFont(fontBold);
+ * text('Font Style Bold', 10, 70);
+ * }
+ *
+ *
+ * let font;
+ * let textString = 'Lorem ipsum dolor sit amet.';
+ * function preload() {
+ * font = loadFont('./assets/Regular.otf');
+ * }
+ * function setup() {
+ * background(210);
+ *
+ * let bbox = font.textBounds(textString, 10, 30, 12);
+ * fill(255);
+ * stroke(0);
+ * rect(bbox.x, bbox.y, bbox.w, bbox.h);
+ * fill(0);
+ * noStroke();
+ *
+ * textFont(font);
+ * textSize(12);
+ * text(textString, 10, 30);
+ * }
+ *
+ *
+ * let font;
+ * function preload() {
+ * font = loadFont('assets/inconsolata.otf');
+ * }
+ *
+ * let points;
+ * let bounds;
+ * function setup() {
+ * createCanvas(100, 100);
+ * stroke(0);
+ * fill(255, 104, 204);
+ *
+ * points = font.textToPoints('p5', 0, 0, 10, {
+ * sampleFactor: 5,
+ * simplifyThreshold: 0
+ * });
+ * bounds = font.textBounds(' p5 ', 0, 0, 10);
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * beginShape();
+ * translate(-bounds.x * width / bounds.w, -bounds.y * height / bounds.h);
+ * for (let i = 0; i < points.length; i++) {
+ * let p = points[i];
+ * vertex(
+ * p.x * width / bounds.w +
+ * sin(20 * p.y / bounds.h + millis() / 1000) * width / 30,
+ * p.y * height / bounds.h
+ * );
+ * }
+ * endShape(CLOSE);
+ * }
+ *
+ *
+ * function setup() {
+ * let myArray = ['Mango', 'Apple', 'Papaya'];
+ * print(myArray); // ['Mango', 'Apple', 'Papaya']
+ *
+ * append(myArray, 'Peach');
+ * print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach']
+ * }
+ *
+ * let src = ['A', 'B', 'C'];
+ * let dst = [1, 2, 3];
+ * let srcPosition = 1;
+ * let dstPosition = 0;
+ * let length = 2;
+ *
+ * print(src); // ['A', 'B', 'C']
+ * print(dst); // [ 1 , 2 , 3 ]
+ *
+ * arrayCopy(src, srcPosition, dst, dstPosition, length);
+ * print(dst); // ['B', 'C', 3]
+ *
+ * function setup() {
+ * let arr1 = ['A', 'B', 'C'];
+ * let arr2 = [1, 2, 3];
+ *
+ * print(arr1); // ['A','B','C']
+ * print(arr2); // [1,2,3]
+ *
+ * let arr3 = concat(arr1, arr2);
+ *
+ * print(arr1); // ['A','B','C']
+ * print(arr2); // [1, 2, 3]
+ * print(arr3); // ['A','B','C', 1, 2, 3]
+ * }
+ *
+ * function setup() {
+ * let myArray = ['A', 'B', 'C'];
+ * print(myArray); // ['A','B','C']
+ *
+ * reverse(myArray);
+ * print(myArray); // ['C','B','A']
+ * }
+ *
+ * function setup() {
+ * let myArray = ['A', 'B', 'C'];
+ * print(myArray); // ['A', 'B', 'C']
+ * let newArray = shorten(myArray);
+ * print(myArray); // ['A','B','C']
+ * print(newArray); // ['A','B']
+ * }
+ *
+ * function setup() {
+ * let regularArr = ['ABC', 'def', createVector(), TAU, Math.E];
+ * print(regularArr);
+ * shuffle(regularArr, true); // force modifications to passed array
+ * print(regularArr);
+ *
+ * // By default shuffle() returns a shuffled cloned array:
+ * let newArr = shuffle(regularArr);
+ * print(regularArr);
+ * print(newArr);
+ * }
+ *
+ * function setup() {
+ * let words = ['banana', 'apple', 'pear', 'lime'];
+ * print(words); // ['banana', 'apple', 'pear', 'lime']
+ * let count = 4; // length of array
+ *
+ * words = sort(words, count);
+ * print(words); // ['apple', 'banana', 'lime', 'pear']
+ * }
+ *
+ * function setup() {
+ * let numbers = [2, 6, 1, 5, 14, 9, 8, 12];
+ * print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12]
+ * let count = 5; // Less than the length of the array
+ *
+ * numbers = sort(numbers, count);
+ * print(numbers); // [1,2,5,6,14,9,8,12]
+ * }
+ *
+ * function setup() {
+ * let myArray = [0, 1, 2, 3, 4];
+ * let insArray = ['A', 'B', 'C'];
+ * print(myArray); // [0, 1, 2, 3, 4]
+ * print(insArray); // ['A','B','C']
+ *
+ * splice(myArray, insArray, 3);
+ * print(myArray); // [0,1,2,'A','B','C',3,4]
+ * }
+ *
+ * function setup() {
+ * let myArray = [1, 2, 3, 4, 5];
+ * print(myArray); // [1, 2, 3, 4, 5]
+ *
+ * let sub1 = subset(myArray, 0, 3);
+ * let sub2 = subset(myArray, 2, 2);
+ * print(sub1); // [1,2,3]
+ * print(sub2); // [3,4]
+ * }
+ *
+ * let str = '20';
+ * let diameter = float(str);
+ * ellipse(width / 2, height / 2, diameter, diameter);
+ *
+ * print(float('10.31')); // 10.31
+ * print(float('Infinity')); // Infinity
+ * print(float('-Infinity')); // -Infinity
+ *
+ * print(int('10')); // 10
+ * print(int(10.31)); // 10
+ * print(int(-10)); // -10
+ * print(int(true)); // 1
+ * print(int(false)); // 0
+ * print(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9]
+ * print(int(Infinity)); // Infinity
+ * print(int('-Infinity')); // -Infinity
+ *
+ * print(str('10')); // "10"
+ * print(str(10.31)); // "10.31"
+ * print(str(-10)); // "-10"
+ * print(str(true)); // "true"
+ * print(str(false)); // "false"
+ * print(str([true, '10.3', 9.8])); // [ "true", "10.3", "9.8" ]
+ *
+ * print(boolean(0)); // false
+ * print(boolean(1)); // true
+ * print(boolean('true')); // true
+ * print(boolean('abcd')); // false
+ * print(boolean([0, 12, 'true'])); // [false, true, true]
+ *
+ * print(byte(127)); // 127
+ * print(byte(128)); // -128
+ * print(byte(23.4)); // 23
+ * print(byte('23.4')); // 23
+ * print(byte('hello')); // NaN
+ * print(byte(true)); // 1
+ * print(byte([0, 255, '100'])); // [0, -1, 100]
+ *
+ * print(char(65)); // "A"
+ * print(char('65')); // "A"
+ * print(char([65, 66, 67])); // [ "A", "B", "C" ]
+ * print(join(char([65, 66, 67]), '')); // "ABC"
+ *
+ * print(unchar('A')); // 65
+ * print(unchar(['A', 'B', 'C'])); // [ 65, 66, 67 ]
+ * print(unchar(split('ABC', ''))); // [ 65, 66, 67 ]
+ *
+ * print(hex(255)); // "000000FF"
+ * print(hex(255, 6)); // "0000FF"
+ * print(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ]
+ * print(Infinity); // "FFFFFFFF"
+ * print(-Infinity); // "00000000"
+ *
+ * print(unhex('A')); // 10
+ * print(unhex('FF')); // 255
+ * print(unhex(['FF', 'AA', '00'])); // [ 255, 170, 0 ]
+ *
+ * let array = ['Hello', 'world!'];
+ * let separator = ' ';
+ * let message = join(array, separator);
+ * text(message, 5, 50);
+ *
+ *
+ * let string = 'Hello p5js*!';
+ * let regexp = 'p5js\\*';
+ * let m = match(string, regexp);
+ * text(m, 5, 50);
+ *
+ *
+ * let string = 'Hello p5js*! Hello world!';
+ * let regexp = 'Hello';
+ * matchAll(string, regexp);
+ *
+ *
+ * let myFont;
+ * function preload() {
+ * myFont = loadFont('assets/fonts/inconsolata.ttf');
+ * }
+ * function setup() {
+ * background(200);
+ * let num1 = 321;
+ * let num2 = -1321;
+ *
+ * noStroke();
+ * fill(0);
+ * textFont(myFont);
+ * textSize(22);
+ *
+ * text(nf(num1, 4, 2), 10, 30);
+ * text(nf(num2, 4, 2), 10, 80);
+ * // Draw dividing line
+ * stroke(120);
+ * line(0, 50, width, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * background(200);
+ * let num = 11253106.115;
+ * let numArr = [1, 1, 2];
+ *
+ * noStroke();
+ * fill(0);
+ * textSize(12);
+ *
+ * // Draw formatted numbers
+ * text(nfc(num, 4), 10, 30);
+ * text(nfc(numArr, 2), 10, 80);
+ *
+ * // Draw dividing line
+ * stroke(120);
+ * line(0, 50, width, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * background(200);
+ * let num1 = 11253106.115;
+ * let num2 = -11253106.115;
+ *
+ * noStroke();
+ * fill(0);
+ * textSize(12);
+ *
+ * // Draw formatted numbers
+ * text(nfp(num1, 4, 2), 10, 30);
+ * text(nfp(num2, 4, 2), 10, 80);
+ *
+ * // Draw dividing line
+ * stroke(120);
+ * line(0, 50, width, 50);
+ * }
+ *
+ *
+ * let myFont;
+ * function preload() {
+ * myFont = loadFont('assets/fonts/inconsolata.ttf');
+ * }
+ * function setup() {
+ * background(200);
+ * let num1 = 321;
+ * let num2 = -1321;
+ *
+ * noStroke();
+ * fill(0);
+ * textFont(myFont);
+ * textSize(22);
+ *
+ * // nfs() aligns num1 (positive number) with num2 (negative number) by
+ * // adding a blank space in front of the num1 (positive number)
+ * // [left = 4] in num1 add one 0 in front, to align the digits with num2
+ * // [right = 2] in num1 and num2 adds two 0's after both numbers
+ * // To see the differences check the example of nf() too.
+ * text(nfs(num1, 4, 2), 10, 30);
+ * text(nfs(num2, 4, 2), 10, 80);
+ * // Draw dividing line
+ * stroke(120);
+ * line(0, 50, width, 50);
+ * }
+ *
+ *
+ * let names = 'Pat,Xio,Alex';
+ * let splitString = split(names, ',');
+ * text(splitString[0], 5, 30);
+ * text(splitString[1], 5, 50);
+ * text(splitString[2], 5, 70);
+ *
+ *
+ * function setup() {
+ * let myStr = 'Mango, Banana, Lime';
+ * let myStrArr = splitTokens(myStr, ',');
+ *
+ * print(myStrArr); // prints : ["Mango"," Banana"," Lime"]
+ * }
+ *
+ *
+ * let string = trim(' No new lines\n ');
+ * text(string + ' here', 2, 50);
+ *
+ *
+ * let d = day();
+ * text('Current day: \n' + d, 5, 50);
+ *
+ *
+ * let h = hour();
+ * text('Current hour:\n' + h, 5, 50);
+ *
+ *
+ * let m = minute();
+ * text('Current minute: \n' + m, 5, 50);
+ *
+ *
+ * let millisecond = millis();
+ * text('Milliseconds \nrunning: \n' + millisecond, 5, 40);
+ *
+ *
+ * let m = month();
+ * text('Current month: \n' + m, 5, 50);
+ *
+ *
+ * let s = second();
+ * text('Current second: \n' + s, 5, 50);
+ *
+ *
+ * let y = year();
+ * text('Current year: \n' + y, 5, 50);
+ *
+ *
+ * // draw a plane
+ * // with width 50 and height 50
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * plane(50, 50);
+ * }
+ *
+ *
+ * // draw a spinning box
+ * // with width, height and depth of 50
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * box(50);
+ * }
+ *
+ *
+ * // draw a sphere with radius 40
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(205, 102, 94);
+ * sphere(40);
+ * }
+ *
+ *
+ * let detailX;
+ * // slide to see how detailX works
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailX = createSlider(3, 24, 3);
+ * detailX.position(10, height + 5);
+ * detailX.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * rotateY(millis() / 1000);
+ * sphere(40, detailX.value(), 16);
+ * }
+ *
+ *
+ * let detailY;
+ * // slide to see how detailY works
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailY = createSlider(3, 16, 3);
+ * detailY.position(10, height + 5);
+ * detailY.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * rotateY(millis() / 1000);
+ * sphere(40, 16, detailY.value());
+ * }
+ *
+ *
+ * // draw a spinning cylinder
+ * // with radius 20 and height 50
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * rotateX(frameCount * 0.01);
+ * rotateZ(frameCount * 0.01);
+ * cylinder(20, 50);
+ * }
+ *
+ *
+ * // slide to see how detailX works
+ * let detailX;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailX = createSlider(3, 24, 3);
+ * detailX.position(10, height + 5);
+ * detailX.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * rotateY(millis() / 1000);
+ * cylinder(20, 75, detailX.value(), 1);
+ * }
+ *
+ *
+ * // slide to see how detailY works
+ * let detailY;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailY = createSlider(1, 16, 1);
+ * detailY.position(10, height + 5);
+ * detailY.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * rotateY(millis() / 1000);
+ * cylinder(20, 75, 16, detailY.value());
+ * }
+ *
+ *
+ * // draw a spinning cone
+ * // with radius 40 and height 70
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateX(frameCount * 0.01);
+ * rotateZ(frameCount * 0.01);
+ * cone(40, 70);
+ * }
+ *
+ *
+ * // slide to see how detailx works
+ * let detailX;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailX = createSlider(3, 16, 3);
+ * detailX.position(10, height + 5);
+ * detailX.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 102, 94);
+ * rotateY(millis() / 1000);
+ * cone(30, 65, detailX.value(), 16);
+ * }
+ *
+ *
+ * // slide to see how detailY works
+ * let detailY;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailY = createSlider(3, 16, 3);
+ * detailY.position(10, height + 5);
+ * detailY.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 102, 94);
+ * rotateY(millis() / 1000);
+ * cone(30, 65, 16, detailY.value());
+ * }
+ *
+ *
+ * // draw an ellipsoid
+ * // with radius 30, 40 and 40.
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * ellipsoid(30, 40, 40);
+ * }
+ *
+ *
+ * // slide to see how detailX works
+ * let detailX;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailX = createSlider(2, 24, 12);
+ * detailX.position(10, height + 5);
+ * detailX.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 94);
+ * rotateY(millis() / 1000);
+ * ellipsoid(30, 40, 40, detailX.value(), 8);
+ * }
+ *
+ *
+ * // slide to see how detailY works
+ * let detailY;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailY = createSlider(2, 24, 6);
+ * detailY.position(10, height + 5);
+ * detailY.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 105, 9);
+ * rotateY(millis() / 1000);
+ * ellipsoid(30, 40, 40, 12, detailY.value());
+ * }
+ *
+ *
+ * // draw a spinning torus
+ * // with ring radius 30 and tube radius 15
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(205, 102, 94);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * torus(30, 15);
+ * }
+ *
+ *
+ * // slide to see how detailX works
+ * let detailX;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailX = createSlider(3, 24, 3);
+ * detailX.position(10, height + 5);
+ * detailX.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 102, 94);
+ * rotateY(millis() / 1000);
+ * torus(30, 15, detailX.value(), 12);
+ * }
+ *
+ *
+ * // slide to see how detailY works
+ * let detailY;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * detailY = createSlider(3, 16, 3);
+ * detailY.position(10, height + 5);
+ * detailY.style('width', '80px');
+ * }
+ *
+ * function draw() {
+ * background(205, 102, 94);
+ * rotateY(millis() / 1000);
+ * torus(30, 15, 16, detailY.value());
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(50);
+ * stroke(255);
+ * strokeWeight(4);
+ * point(25, 0);
+ * strokeWeight(3);
+ * point(-25, 0);
+ * strokeWeight(2);
+ * point(0, 25);
+ * strokeWeight(1);
+ * point(0, -25);
+ * }
+ *
+ *
+ * //draw a line
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * // Use fill instead of stroke to change the color of shape.
+ * fill(255, 0, 0);
+ * line(10, 10, 0, 60, 60, 20);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * }
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * rotateY(0.5);
+ * box(30, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
+ * normalMaterial();
+ * debugMode();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * box(15, 30);
+ * // Press the spacebar to turn debugMode off!
+ * if (keyIsDown(32)) {
+ * noDebugMode();
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
+ * normalMaterial();
+ * debugMode(GRID);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * box(15, 30);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
+ * normalMaterial();
+ * debugMode(AXES);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * box(15, 30);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
+ * normalMaterial();
+ * debugMode(GRID, 100, 10, 0, 0, 0);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * box(15, 30);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
+ * normalMaterial();
+ * debugMode(100, 10, 0, 0, 0, 20, 0, -40, 0);
+ * }
+ *
+ * function draw() {
+ * noStroke();
+ * background(200);
+ * orbitControl();
+ * box(15, 30);
+ * // set the stroke color and weight for the grid!
+ * stroke(255, 0, 150);
+ * strokeWeight(0.8);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * camera(0, -30, 100, 0, 0, 0, 0, 1, 0);
+ * normalMaterial();
+ * debugMode();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * box(15, 30);
+ * // Press the spacebar to turn debugMode off!
+ * if (keyIsDown(32)) {
+ * noDebugMode();
+ * }
+ * }
+ *
+ *
+ * createCanvas(100, 100, WEBGL);
+ * ambientLight(0);
+ * ambientMaterial(250);
+ * sphere(40);
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(51);
+ * ambientLight(100); // white light
+ * ambientMaterial(255, 102, 94); // magenta material
+ * box(30);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * noStroke();
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * shininess(20);
+ * ambientLight(50);
+ * specularColor(255, 0, 0);
+ * pointLight(255, 0, 0, 0, -50, 50);
+ * specularColor(0, 255, 0);
+ * pointLight(0, 255, 0, 0, 50, 50);
+ * specularMaterial(255);
+ * sphere(40);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * //move your mouse to change light direction
+ * let dirX = (mouseX / width - 0.5) * 2;
+ * let dirY = (mouseY / height - 0.5) * 2;
+ * directionalLight(250, 250, 250, -dirX, -dirY, -1);
+ * noStroke();
+ * sphere(40);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * //move your mouse to change light position
+ * let locX = mouseX - width / 2;
+ * let locY = mouseY - height / 2;
+ * // to set the light position,
+ * // think of the world's coordinate as:
+ * // -width/2,-height/2 -------- width/2,-height/2
+ * // | |
+ * // | 0,0 |
+ * // | |
+ * // -width/2,height/2--------width/2,height/2
+ * pointLight(250, 250, 250, locX, locY, 50);
+ * noStroke();
+ * sphere(40);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * lights();
+ * rotateX(millis() / 1000);
+ * rotateY(millis() / 1000);
+ * rotateZ(millis() / 1000);
+ * box();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * noStroke();
+ * }
+ * function draw() {
+ * background(0);
+ * let locX = mouseX - width / 2;
+ * let locY = mouseY - height / 2;
+ * translate(-25, 0, 0);
+ * lightFalloff(1, 0, 0);
+ * pointLight(250, 250, 250, locX, locY, 50);
+ * sphere(20);
+ * translate(50, 0, 0);
+ * lightFalloff(0.9, 0.01, 0);
+ * pointLight(250, 250, 250, locX, locY, 50);
+ * sphere(20);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * //move your mouse to change light position
+ * let locX = mouseX - width / 2;
+ * let locY = mouseY - height / 2;
+ * // to set the light position,
+ * // think of the world's coordinate as:
+ * // -width/2,-height/2 -------- width/2,-height/2
+ * // | |
+ * // | 0,0 |
+ * // | |
+ * // -width/2,height/2--------width/2,height/2
+ * ambientLight(50);
+ * spotLight(0, 250, 0, locX, locY, 100, 0, 0, -1, Math.PI / 16);
+ * noStroke();
+ * sphere(40);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * noStroke();
+ *
+ * ambientLight(150, 0, 0);
+ * translate(-25, 0, 0);
+ * ambientMaterial(250);
+ * sphere(20);
+ *
+ * noLights();
+ * ambientLight(0, 150, 0);
+ * translate(50, 0, 0);
+ * ambientMaterial(250);
+ * sphere(20);
+ * }
+ *
+ * .stl
, .obj
).
+ * @return {p5.Geometry} the p5.Geometry object
+ *
+ * @example
+ *
+ * //draw a spinning octahedron
+ * let octahedron;
+ *
+ * function preload() {
+ * octahedron = loadModel('assets/octahedron.obj');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * model(octahedron);
+ * }
+ *
+ *
+ * //draw a spinning teapot
+ * let teapot;
+ *
+ * function preload() {
+ * // Load model with normalise parameter set to true
+ * teapot = loadModel('assets/teapot.obj', true);
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * scale(0.4); // Scaled to make model fit into canvas
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * normalMaterial(); // For effect
+ * model(teapot);
+ * }
+ *
+ *
+ * //draw a spinning octahedron
+ * let octahedron;
+ *
+ * function preload() {
+ * octahedron = loadModel('assets/octahedron.obj');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * model(octahedron);
+ * }
+ *
+ *
+ * let mandel;
+ * function preload() {
+ * // load the shader definitions from files
+ * mandel = loadShader('assets/shader.vert', 'assets/shader.frag');
+ * }
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * // use the shader
+ * shader(mandel);
+ * noStroke();
+ * mandel.setUniform('p', [-0.74364388703, 0.13182590421]);
+ * }
+ *
+ * function draw() {
+ * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));
+ * quad(-1, -1, 1, -1, 1, 1, -1, 1);
+ * }
+ *
+ *
+ * // the 'varying's are shared between both vertex & fragment shaders
+ * let varying = 'precision highp float; varying vec2 vPos;';
+ *
+ * // the vertex shader is called for each vertex
+ * let vs =
+ * varying +
+ * 'attribute vec3 aPosition;' +
+ * 'void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }';
+ *
+ * // the fragment shader is called for each pixel
+ * let fs =
+ * varying +
+ * 'uniform vec2 p;' +
+ * 'uniform float r;' +
+ * 'const int I = 500;' +
+ * 'void main() {' +
+ * ' vec2 c = p + vPos * r, z = c;' +
+ * ' float n = 0.0;' +
+ * ' for (int i = I; i > 0; i --) {' +
+ * ' if(z.x*z.x+z.y*z.y > 4.0) {' +
+ * ' n = float(i)/float(I);' +
+ * ' break;' +
+ * ' }' +
+ * ' z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;' +
+ * ' }' +
+ * ' gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);' +
+ * '}';
+ *
+ * let mandel;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * // create and initialize the shader
+ * mandel = createShader(vs, fs);
+ * shader(mandel);
+ * noStroke();
+ *
+ * // 'p' is the center point of the Mandelbrot image
+ * mandel.setUniform('p', [-0.74364388703, 0.13182590421]);
+ * }
+ *
+ * function draw() {
+ * // 'r' is the size of the image in Mandelbrot-space
+ * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));
+ * quad(-1, -1, 1, -1, 1, 1, -1, 1);
+ * }
+ *
+ *
+ * // Click within the image to toggle
+ * // the shader used by the quad shape
+ * // Note: for an alternative approach to the same example,
+ * // involving changing uniforms please refer to:
+ * // https://p5js.org/reference/#/p5.Shader/setUniform
+ *
+ * let redGreen;
+ * let orangeBlue;
+ * let showRedGreen = false;
+ *
+ * function preload() {
+ * // note that we are using two instances
+ * // of the same vertex and fragment shaders
+ * redGreen = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');
+ * orangeBlue = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * // initialize the colors for redGreen shader
+ * shader(redGreen);
+ * redGreen.setUniform('colorCenter', [1.0, 0.0, 0.0]);
+ * redGreen.setUniform('colorBackground', [0.0, 1.0, 0.0]);
+ *
+ * // initialize the colors for orangeBlue shader
+ * shader(orangeBlue);
+ * orangeBlue.setUniform('colorCenter', [1.0, 0.5, 0.0]);
+ * orangeBlue.setUniform('colorBackground', [0.226, 0.0, 0.615]);
+ *
+ * noStroke();
+ * }
+ *
+ * function draw() {
+ * // update the offset values for each shader,
+ * // moving orangeBlue in vertical and redGreen
+ * // in horizontal direction
+ * orangeBlue.setUniform('offset', [0, sin(millis() / 2000) + 1]);
+ * redGreen.setUniform('offset', [sin(millis() / 2000), 1]);
+ *
+ * if (showRedGreen === true) {
+ * shader(redGreen);
+ * } else {
+ * shader(orangeBlue);
+ * }
+ * quad(-1, -1, 1, -1, 1, 1, -1, 1);
+ * }
+ *
+ * function mouseClicked() {
+ * showRedGreen = !showRedGreen;
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * normalMaterial();
+ * sphere(40);
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * rotateZ(frameCount * 0.01);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * //pass image as texture
+ * texture(img);
+ * box(200, 200, 200);
+ * }
+ *
+ *
+ * let pg;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * pg = createGraphics(200, 200);
+ * pg.textSize(75);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * pg.background(255);
+ * pg.text('hello!', 0, 100);
+ * //pass image as texture
+ * texture(pg);
+ * rotateX(0.5);
+ * noStroke();
+ * plane(50);
+ * }
+ *
+ *
+ * let vid;
+ * function preload() {
+ * vid = createVideo('assets/fingers.mov');
+ * vid.hide();
+ * }
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * //pass video frame as texture
+ * texture(vid);
+ * rect(-40, -40, 80, 80);
+ * }
+ *
+ * function mousePressed() {
+ * vid.loop();
+ * }
+ *
+ *
+ * let img;
+ *
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * texture(img);
+ * textureMode(NORMAL);
+ * beginShape();
+ * vertex(-50, -50, 0, 0);
+ * vertex(50, -50, 1, 0);
+ * vertex(50, 50, 1, 1);
+ * vertex(-50, 50, 0, 1);
+ * endShape();
+ * }
+ *
+ *
+ * let img;
+ *
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * texture(img);
+ * textureMode(NORMAL);
+ * beginShape();
+ * vertex(-50, -50, 0, 0);
+ * vertex(50, -50, img.width, 0);
+ * vertex(50, 50, img.width, img.height);
+ * vertex(-50, 50, 0, img.height);
+ * endShape();
+ * }
+ *
+ *
+ * let img;
+ * function preload() {
+ * img = loadImage('assets/rockies128.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * textureWrap(MIRROR);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ *
+ * let dX = mouseX;
+ * let dY = mouseY;
+ *
+ * let u = lerp(1.0, 2.0, dX);
+ * let v = lerp(1.0, 2.0, dY);
+ *
+ * scale(width / 2);
+ *
+ * texture(img);
+ *
+ * beginShape(TRIANGLES);
+ * vertex(-1, -1, 0, 0, 0);
+ * vertex(1, -1, 0, u, 0);
+ * vertex(1, 1, 0, u, v);
+ *
+ * vertex(1, 1, 0, u, v);
+ * vertex(-1, 1, 0, 0, v);
+ * vertex(-1, -1, 0, 0, 0);
+ * endShape();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * noStroke();
+ * ambientLight(200);
+ * ambientMaterial(70, 130, 230);
+ * sphere(40);
+ * }
+ *
+ *
+ * // ambientLight is both red and blue (magenta),
+ * // so object only reflects it's red and blue components
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(70);
+ * ambientLight(100); // white light
+ * ambientMaterial(255, 0, 255); // pink material
+ * box(30);
+ * }
+ *
+ *
+ * // ambientLight is green. Since object does not contain
+ * // green, it does not reflect any light
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(70);
+ * ambientLight(0, 255, 0); // green light
+ * ambientMaterial(255, 0, 255); // pink material
+ * box(30);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * noStroke();
+ * ambientLight(0);
+ * emissiveMaterial(130, 230, 0);
+ * sphere(40);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * ambientLight(50);
+ * pointLight(250, 250, 250, 100, 100, 30);
+ * specularMaterial(250);
+ * sphere(40);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * noStroke();
+ * let locX = mouseX - width / 2;
+ * let locY = mouseY - height / 2;
+ * ambientLight(60, 60, 60);
+ * pointLight(255, 255, 255, locX, locY, 50);
+ * specularMaterial(250);
+ * translate(-25, 0, 0);
+ * shininess(1);
+ * sphere(20);
+ * translate(50, 0, 0);
+ * shininess(20);
+ * sphere(20);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(204);
+ * //move the camera away from the plane by a sin wave
+ * camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0);
+ * plane(10, 10);
+ * }
+ *
+ *
+ * //move slider to see changes!
+ * //sliders control the first 6 parameters of camera()
+ * let sliderGroup = [];
+ * let X;
+ * let Y;
+ * let Z;
+ * let centerX;
+ * let centerY;
+ * let centerZ;
+ * let h = 20;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * //create sliders
+ * for (var i = 0; i < 6; i++) {
+ * if (i === 2) {
+ * sliderGroup[i] = createSlider(10, 400, 200);
+ * } else {
+ * sliderGroup[i] = createSlider(-400, 400, 0);
+ * }
+ * h = map(i, 0, 6, 5, 85);
+ * sliderGroup[i].position(10, height + h);
+ * sliderGroup[i].style('width', '80px');
+ * }
+ * }
+ *
+ * function draw() {
+ * background(60);
+ * // assigning sliders' value to each parameters
+ * X = sliderGroup[0].value();
+ * Y = sliderGroup[1].value();
+ * Z = sliderGroup[2].value();
+ * centerX = sliderGroup[3].value();
+ * centerY = sliderGroup[4].value();
+ * centerZ = sliderGroup[5].value();
+ * camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0);
+ * stroke(255);
+ * fill(255, 102, 94);
+ * box(85);
+ * }
+ *
+ *
+ * //drag the mouse to look around!
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * perspective(PI / 3.0, width / height, 0.1, 500);
+ * }
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * normalMaterial();
+ *
+ * rotateX(-0.3);
+ * rotateY(-0.2);
+ * translate(0, 0, -50);
+ *
+ * push();
+ * translate(-15, 0, sin(frameCount / 30) * 95);
+ * box(30);
+ * pop();
+ * push();
+ * translate(15, 0, sin(frameCount / 30 + PI) * 95);
+ * box(30);
+ * pop();
+ * }
+ *
+ *
+ * //drag the mouse to look around!
+ * //there's no vanishing point
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500);
+ * }
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * normalMaterial();
+ *
+ * rotateX(0.2);
+ * rotateY(-0.2);
+ * push();
+ * translate(-15, 0, sin(frameCount / 30) * 65);
+ * box(30);
+ * pop();
+ * push();
+ * translate(15, 0, sin(frameCount / 30 + PI) * 65);
+ * box(30);
+ * pop();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * setAttributes('antialias', true);
+ * frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200);
+ * }
+ * function draw() {
+ * background(200);
+ * orbitControl();
+ * strokeWeight(10);
+ * stroke(0, 0, 255);
+ * noFill();
+ *
+ * rotateY(-0.2);
+ * rotateX(-0.3);
+ * push();
+ * translate(-15, 0, sin(frameCount / 30) * 25);
+ * box(30);
+ * pop();
+ * push();
+ * translate(15, 0, sin(frameCount / 30 + PI) * 25);
+ * box(30);
+ * pop();
+ * }
+ *
+ *
+ * // Creates a camera object and animates it around a box.
+ * let camera;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(0);
+ * camera = createCamera();
+ * setCamera(camera);
+ * }
+ *
+ * function draw() {
+ * camera.lookAt(0, 0, 0);
+ * camera.setPosition(sin(frameCount / 60) * 200, 0, 100);
+ * box(20);
+ * }
+ *
eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ
+ * which describes camera position, orientation, and projection
+ * are also accessible via the camera object generated using
+ * createCamera()
+ *
+ * @class p5.Camera
+ * @param {rendererGL} rendererGL instance of WebGL renderer
+ * @example
+ *
+ * let cam;
+ * let delta = 0.01;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * cam = createCamera();
+ * // set initial pan angle
+ * cam.pan(-0.8);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // pan camera according to angle 'delta'
+ * cam.pan(delta);
+ *
+ * // every 160 frames, switch direction
+ * if (frameCount % 160 === 0) {
+ * delta *= -1;
+ * }
+ *
+ * rotateX(frameCount * 0.01);
+ * translate(-100, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * }
+ *
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(0);
+ * cam = createCamera();
+ * div = createDiv();
+ * div.position(0, 0);
+ * }
+ *
+ * function draw() {
+ * orbitControl();
+ * box(10);
+ * div.html('eyeX = ' + cam.eyeX);
+ * }
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(0);
+ * cam = createCamera();
+ * div = createDiv();
+ * div.position(0, 0);
+ * }
+ *
+ * function draw() {
+ * orbitControl();
+ * box(10);
+ * div.html('eyeY = ' + cam.eyeY);
+ * }
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(0);
+ * cam = createCamera();
+ * div = createDiv();
+ * div.position(0, 0);
+ * }
+ *
+ * function draw() {
+ * orbitControl();
+ * box(10);
+ * div.html('eyeZ = ' + cam.eyeZ);
+ * }
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(255);
+ * cam = createCamera();
+ * cam.lookAt(1, 0, 0);
+ * div = createDiv('centerX = ' + cam.centerX);
+ * div.position(0, 0);
+ * div.style('color', 'white');
+ * }
+ *
+ * function draw() {
+ * orbitControl();
+ * box(10);
+ * }
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(255);
+ * cam = createCamera();
+ * cam.lookAt(0, 1, 0);
+ * div = createDiv('centerY = ' + cam.centerY);
+ * div.position(0, 0);
+ * div.style('color', 'white');
+ * }
+ *
+ * function draw() {
+ * orbitControl();
+ * box(10);
+ * }
+ *
+ * @alt
+ * An example showing the use of camera object properties
+ *
+ */
+
+ /**
+ * z coordinate representing center of the sketch
+ * @property {Number} centerZ
+ * @readonly
+ * @example
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(255);
+ * cam = createCamera();
+ * cam.lookAt(0, 0, 1);
+ * div = createDiv('centerZ = ' + cam.centerZ);
+ * div.position(0, 0);
+ * div.style('color', 'white');
+ * }
+ *
+ * function draw() {
+ * orbitControl();
+ * box(10);
+ * }
+ *
+ * @alt
+ * An example showing the use of camera object properties
+ *
+ */
+
+ /**
+ * x component of direction 'up' from camera
+ * @property {Number} upX
+ * @readonly
+ * @example
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(255);
+ * cam = createCamera();
+ * div = createDiv('upX = ' + cam.upX);
+ * div.position(0, 0);
+ * div.style('color', 'blue');
+ * div.style('font-size', '18px');
+ * }
+ *
+ *
+ * @alt
+ * An example showing the use of camera object properties
+ *
+ */
+
+ /**
+ * y component of direction 'up' from camera
+ * @property {Number} upY
+ * @readonly
+ * @example
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(255);
+ * cam = createCamera();
+ * div = createDiv('upY = ' + cam.upY);
+ * div.position(0, 0);
+ * div.style('color', 'blue');
+ * div.style('font-size', '18px');
+ * }
+ *
+ *
+ * @alt
+ * An example showing the use of camera object properties
+ *
+ */
+
+ /**
+ * z component of direction 'up' from camera
+ * @property {Number} upZ
+ * @readonly
+ * @example
+ *
+ * let cam, div;
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * background(255);
+ * cam = createCamera();
+ * div = createDiv('upZ = ' + cam.upZ);
+ * div.position(0, 0);
+ * div.style('color', 'blue');
+ * div.style('font-size', '18px');
+ * }
+ *
+ *
+ * @alt
+ * An example showing the use of camera object properties
+ *
+ */
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // Camera Projection Methods
+ ////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Sets a perspective projection for a p5.Camera object and sets parameters
+ * for that projection according to perspective()
+ * syntax.
+ * @method perspective
+ * @for p5.Camera
+ */
+ _main.default.Camera.prototype.perspective = function(fovy, aspect, near, far) {
+ this.cameraType = arguments.length > 0 ? 'custom' : 'default';
+ if (typeof fovy === 'undefined') {
+ fovy = this.defaultCameraFOV;
+ // this avoids issue where setting angleMode(DEGREES) before calling
+ // perspective leads to a smaller than expected FOV (because
+ // _computeCameraDefaultSettings computes in radians)
+ this.cameraFOV = fovy;
+ } else {
+ this.cameraFOV = this._renderer._pInst._toRadians(fovy);
+ }
+ if (typeof aspect === 'undefined') {
+ aspect = this.defaultAspectRatio;
+ }
+ if (typeof near === 'undefined') {
+ near = this.defaultCameraNear;
+ }
+ if (typeof far === 'undefined') {
+ far = this.defaultCameraFar;
+ }
+
+ if (near <= 0.0001) {
+ near = 0.01;
+ console.log(
+ 'Avoid perspective near plane values close to or below 0. ' +
+ 'Setting value to 0.01.'
+ );
+ }
+
+ if (far < near) {
+ console.log(
+ 'Perspective far plane value is less than near plane value. ' +
+ 'Nothing will be shown.'
+ );
+ }
+
+ this.aspectRatio = aspect;
+ this.cameraNear = near;
+ this.cameraFar = far;
+
+ this.projMatrix = _main.default.Matrix.identity();
+
+ var f = 1.0 / Math.tan(this.cameraFOV / 2);
+ var nf = 1.0 / (this.cameraNear - this.cameraFar);
+
+ // prettier-ignore
+ this.projMatrix.set(f / aspect, 0, 0, 0,
+ 0, -f, 0, 0,
+ 0, 0, (far + near) * nf, -1,
+ 0, 0, 2 * far * near * nf, 0);
+
+ if (this._isActive()) {
+ this._renderer.uPMatrix.set(
+ this.projMatrix.mat4[0],
+ this.projMatrix.mat4[1],
+ this.projMatrix.mat4[2],
+ this.projMatrix.mat4[3],
+ this.projMatrix.mat4[4],
+ this.projMatrix.mat4[5],
+ this.projMatrix.mat4[6],
+ this.projMatrix.mat4[7],
+ this.projMatrix.mat4[8],
+ this.projMatrix.mat4[9],
+ this.projMatrix.mat4[10],
+ this.projMatrix.mat4[11],
+ this.projMatrix.mat4[12],
+ this.projMatrix.mat4[13],
+ this.projMatrix.mat4[14],
+ this.projMatrix.mat4[15]
+ );
+ }
+ };
+
+ /**
+ * Sets an orthographic projection for a p5.Camera object and sets parameters
+ * for that projection according to ortho() syntax.
+ * @method ortho
+ * @for p5.Camera
+ */
+ _main.default.Camera.prototype.ortho = function(
+ left,
+ right,
+ bottom,
+ top,
+ near,
+ far
+ ) {
+ if (left === undefined) left = -this._renderer.width / 2;
+ if (right === undefined) right = +this._renderer.width / 2;
+ if (bottom === undefined) bottom = -this._renderer.height / 2;
+ if (top === undefined) top = +this._renderer.height / 2;
+ if (near === undefined) near = 0;
+ if (far === undefined)
+ far = Math.max(this._renderer.width, this._renderer.height);
+
+ var w = right - left;
+ var h = top - bottom;
+ var d = far - near;
+
+ var x = +2.0 / w;
+ var y = +2.0 / h;
+ var z = -2.0 / d;
+
+ var tx = -(right + left) / w;
+ var ty = -(top + bottom) / h;
+ var tz = -(far + near) / d;
+
+ this.projMatrix = _main.default.Matrix.identity();
+
+ // prettier-ignore
+ this.projMatrix.set(x, 0, 0, 0,
+ 0, -y, 0, 0,
+ 0, 0, z, 0,
+ tx, ty, tz, 1);
+
+ if (this._isActive()) {
+ this._renderer.uPMatrix.set(
+ this.projMatrix.mat4[0],
+ this.projMatrix.mat4[1],
+ this.projMatrix.mat4[2],
+ this.projMatrix.mat4[3],
+ this.projMatrix.mat4[4],
+ this.projMatrix.mat4[5],
+ this.projMatrix.mat4[6],
+ this.projMatrix.mat4[7],
+ this.projMatrix.mat4[8],
+ this.projMatrix.mat4[9],
+ this.projMatrix.mat4[10],
+ this.projMatrix.mat4[11],
+ this.projMatrix.mat4[12],
+ this.projMatrix.mat4[13],
+ this.projMatrix.mat4[14],
+ this.projMatrix.mat4[15]
+ );
+ }
+
+ this.cameraType = 'custom';
+ };
+
+ /**
+ * @method frustum
+ * @for p5.Camera
+ */
+ _main.default.Camera.prototype.frustum = function(
+ left,
+ right,
+ bottom,
+ top,
+ near,
+ far
+ ) {
+ if (left === undefined) left = -this._renderer.width / 2;
+ if (right === undefined) right = +this._renderer.width / 2;
+ if (bottom === undefined) bottom = -this._renderer.height / 2;
+ if (top === undefined) top = +this._renderer.height / 2;
+ if (near === undefined) near = 0;
+ if (far === undefined)
+ far = Math.max(this._renderer.width, this._renderer.height);
+
+ var w = right - left;
+ var h = top - bottom;
+ var d = far - near;
+
+ var x = +(2.0 * near) / w;
+ var y = +(2.0 * near) / h;
+ var z = -(2.0 * far * near) / d;
+
+ var tx = (right + left) / w;
+ var ty = (top + bottom) / h;
+ var tz = -(far + near) / d;
+
+ this.projMatrix = _main.default.Matrix.identity();
+
+ // prettier-ignore
+ this.projMatrix.set(x, 0, 0, 0,
+ 0, y, 0, 0,
+ tx, ty, tz, -1,
+ 0, 0, z, 0);
+
+ if (this._isActive()) {
+ this._renderer.uPMatrix.set(
+ this.projMatrix.mat4[0],
+ this.projMatrix.mat4[1],
+ this.projMatrix.mat4[2],
+ this.projMatrix.mat4[3],
+ this.projMatrix.mat4[4],
+ this.projMatrix.mat4[5],
+ this.projMatrix.mat4[6],
+ this.projMatrix.mat4[7],
+ this.projMatrix.mat4[8],
+ this.projMatrix.mat4[9],
+ this.projMatrix.mat4[10],
+ this.projMatrix.mat4[11],
+ this.projMatrix.mat4[12],
+ this.projMatrix.mat4[13],
+ this.projMatrix.mat4[14],
+ this.projMatrix.mat4[15]
+ );
+ }
+
+ this.cameraType = 'custom';
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // Camera Orientation Methods
+ ////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Rotate camera view about arbitrary axis defined by x,y,z
+ * based on http://learnwebgl.brown37.net/07_cameras/camera_rotating_motion.html
+ * @method _rotateView
+ * @private
+ */
+ _main.default.Camera.prototype._rotateView = function(a, x, y, z) {
+ var centerX = this.centerX;
+ var centerY = this.centerY;
+ var centerZ = this.centerZ;
+
+ // move center by eye position such that rotation happens around eye position
+ centerX -= this.eyeX;
+ centerY -= this.eyeY;
+ centerZ -= this.eyeZ;
+
+ var rotation = _main.default.Matrix.identity(this._renderer._pInst);
+ rotation.rotate(this._renderer._pInst._toRadians(a), x, y, z);
+
+ // prettier-ignore
+ var rotatedCenter = [
+ centerX * rotation.mat4[0] + centerY * rotation.mat4[4] + centerZ * rotation.mat4[8],
+ centerX * rotation.mat4[1] + centerY * rotation.mat4[5] + centerZ * rotation.mat4[9],
+ centerX * rotation.mat4[2] + centerY * rotation.mat4[6] + centerZ * rotation.mat4[10]];
+
+ // add eye position back into center
+ rotatedCenter[0] += this.eyeX;
+ rotatedCenter[1] += this.eyeY;
+ rotatedCenter[2] += this.eyeZ;
+
+ this.camera(
+ this.eyeX,
+ this.eyeY,
+ this.eyeZ,
+ rotatedCenter[0],
+ rotatedCenter[1],
+ rotatedCenter[2],
+ this.upX,
+ this.upY,
+ this.upZ
+ );
+ };
+
+ /**
+ * Panning rotates the camera view to the left and right.
+ * @method pan
+ * @param {Number} angle amount to rotate camera in current
+ * angleMode units.
+ * Greater than 0 values rotate counterclockwise (to the left).
+ * @example
+ *
+ *
+ * let cam;
+ * let delta = 0.01;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * cam = createCamera();
+ * // set initial pan angle
+ * cam.pan(-0.8);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // pan camera according to angle 'delta'
+ * cam.pan(delta);
+ *
+ * // every 160 frames, switch direction
+ * if (frameCount % 160 === 0) {
+ * delta *= -1;
+ * }
+ *
+ * rotateX(frameCount * 0.01);
+ * translate(-100, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * }
+ *
+ *
+ *
+ * @alt
+ * camera view pans left and right across a series of rotating 3D boxes.
+ */
+ _main.default.Camera.prototype.pan = function(amount) {
+ var local = this._getLocalAxes();
+ this._rotateView(amount, local.y[0], local.y[1], local.y[2]);
+ };
+
+ /**
+ * Tilting rotates the camera view up and down.
+ * @method tilt
+ * @param {Number} angle amount to rotate camera in current
+ * angleMode units.
+ * Greater than 0 values rotate counterclockwise (to the left).
+ * @example
+ *
+ *
+ * let cam;
+ * let delta = 0.01;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * cam = createCamera();
+ * // set initial tilt
+ * cam.tilt(-0.8);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // pan camera according to angle 'delta'
+ * cam.tilt(delta);
+ *
+ * // every 160 frames, switch direction
+ * if (frameCount % 160 === 0) {
+ * delta *= -1;
+ * }
+ *
+ * rotateY(frameCount * 0.01);
+ * translate(0, -100, 0);
+ * box(20);
+ * translate(0, 35, 0);
+ * box(20);
+ * translate(0, 35, 0);
+ * box(20);
+ * translate(0, 35, 0);
+ * box(20);
+ * translate(0, 35, 0);
+ * box(20);
+ * translate(0, 35, 0);
+ * box(20);
+ * translate(0, 35, 0);
+ * box(20);
+ * }
+ *
+ *
+ *
+ * @alt
+ * camera view tilts up and down across a series of rotating 3D boxes.
+ */
+ _main.default.Camera.prototype.tilt = function(amount) {
+ var local = this._getLocalAxes();
+ this._rotateView(amount, local.x[0], local.x[1], local.x[2]);
+ };
+
+ /**
+ * Reorients the camera to look at a position in world space.
+ * @method lookAt
+ * @for p5.Camera
+ * @param {Number} x x position of a point in world space
+ * @param {Number} y y position of a point in world space
+ * @param {Number} z z position of a point in world space
+ * @example
+ *
+ *
+ * let cam;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * cam = createCamera();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // look at a new random point every 60 frames
+ * if (frameCount % 60 === 0) {
+ * cam.lookAt(random(-100, 100), random(-50, 50), 0);
+ * }
+ *
+ * rotateX(frameCount * 0.01);
+ * translate(-100, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * }
+ *
+ *
+ *
+ * @alt
+ * camera view of rotating 3D cubes changes to look at a new random
+ * point every second .
+ */
+ _main.default.Camera.prototype.lookAt = function(x, y, z) {
+ this.camera(
+ this.eyeX,
+ this.eyeY,
+ this.eyeZ,
+ x,
+ y,
+ z,
+ this.upX,
+ this.upY,
+ this.upZ
+ );
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // Camera Position Methods
+ ////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Sets a camera's position and orientation. This is equivalent to calling
+ * camera() on a p5.Camera object.
+ * @method camera
+ * @for p5.Camera
+ */
+ _main.default.Camera.prototype.camera = function(
+ eyeX,
+ eyeY,
+ eyeZ,
+ centerX,
+ centerY,
+ centerZ,
+ upX,
+ upY,
+ upZ
+ ) {
+ if (typeof eyeX === 'undefined') {
+ eyeX = this.defaultEyeX;
+ eyeY = this.defaultEyeY;
+ eyeZ = this.defaultEyeZ;
+ centerX = eyeX;
+ centerY = eyeY;
+ centerZ = 0;
+ upX = 0;
+ upY = 1;
+ upZ = 0;
+ }
+
+ this.eyeX = eyeX;
+ this.eyeY = eyeY;
+ this.eyeZ = eyeZ;
+
+ if (typeof centerX !== 'undefined') {
+ this.centerX = centerX;
+ this.centerY = centerY;
+ this.centerZ = centerZ;
+ }
+
+ if (typeof upX !== 'undefined') {
+ this.upX = upX;
+ this.upY = upY;
+ this.upZ = upZ;
+ }
+
+ var local = this._getLocalAxes();
+
+ // the camera affects the model view matrix, insofar as it
+ // inverse translates the world to the eye position of the camera
+ // and rotates it.
+ // prettier-ignore
+ this.cameraMatrix.set(local.x[0], local.y[0], local.z[0], 0,
+ local.x[1], local.y[1], local.z[1], 0,
+ local.x[2], local.y[2], local.z[2], 0,
+ 0, 0, 0, 1);
+
+ var tx = -eyeX;
+ var ty = -eyeY;
+ var tz = -eyeZ;
+
+ this.cameraMatrix.translate([tx, ty, tz]);
+
+ if (this._isActive()) {
+ this._renderer.uMVMatrix.set(
+ this.cameraMatrix.mat4[0],
+ this.cameraMatrix.mat4[1],
+ this.cameraMatrix.mat4[2],
+ this.cameraMatrix.mat4[3],
+ this.cameraMatrix.mat4[4],
+ this.cameraMatrix.mat4[5],
+ this.cameraMatrix.mat4[6],
+ this.cameraMatrix.mat4[7],
+ this.cameraMatrix.mat4[8],
+ this.cameraMatrix.mat4[9],
+ this.cameraMatrix.mat4[10],
+ this.cameraMatrix.mat4[11],
+ this.cameraMatrix.mat4[12],
+ this.cameraMatrix.mat4[13],
+ this.cameraMatrix.mat4[14],
+ this.cameraMatrix.mat4[15]
+ );
+ }
+ return this;
+ };
+
+ /**
+ * Move camera along its local axes while maintaining current camera orientation.
+ * @method move
+ * @param {Number} x amount to move along camera's left-right axis
+ * @param {Number} y amount to move along camera's up-down axis
+ * @param {Number} z amount to move along camera's forward-backward axis
+ * @example
+ *
+ *
+ * // see the camera move along its own axes while maintaining its orientation
+ * let cam;
+ * let delta = 0.5;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * cam = createCamera();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // move the camera along its local axes
+ * cam.move(delta, delta, 0);
+ *
+ * // every 100 frames, switch direction
+ * if (frameCount % 150 === 0) {
+ * delta *= -1;
+ * }
+ *
+ * translate(-10, -10, 0);
+ * box(50, 8, 50);
+ * translate(15, 15, 0);
+ * box(50, 8, 50);
+ * translate(15, 15, 0);
+ * box(50, 8, 50);
+ * translate(15, 15, 0);
+ * box(50, 8, 50);
+ * translate(15, 15, 0);
+ * box(50, 8, 50);
+ * translate(15, 15, 0);
+ * box(50, 8, 50);
+ * }
+ *
+ *
+ *
+ * @alt
+ * camera view moves along a series of 3D boxes, maintaining the same
+ * orientation throughout the move
+ */
+ _main.default.Camera.prototype.move = function(x, y, z) {
+ var local = this._getLocalAxes();
+
+ // scale local axes by movement amounts
+ // based on http://learnwebgl.brown37.net/07_cameras/camera_linear_motion.html
+ var dx = [local.x[0] * x, local.x[1] * x, local.x[2] * x];
+ var dy = [local.y[0] * y, local.y[1] * y, local.y[2] * y];
+ var dz = [local.z[0] * z, local.z[1] * z, local.z[2] * z];
+
+ this.camera(
+ this.eyeX + dx[0] + dy[0] + dz[0],
+ this.eyeY + dx[1] + dy[1] + dz[1],
+ this.eyeZ + dx[2] + dy[2] + dz[2],
+ this.centerX + dx[0] + dy[0] + dz[0],
+ this.centerY + dx[1] + dy[1] + dz[1],
+ this.centerZ + dx[2] + dy[2] + dz[2],
+ 0,
+ 1,
+ 0
+ );
+ };
+
+ /**
+ * Set camera position in world-space while maintaining current camera
+ * orientation.
+ * @method setPosition
+ * @param {Number} x x position of a point in world space
+ * @param {Number} y y position of a point in world space
+ * @param {Number} z z position of a point in world space
+ * @example
+ *
+ *
+ * // press '1' '2' or '3' keys to set camera position
+ *
+ * let cam;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ * cam = createCamera();
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // '1' key
+ * if (keyIsDown(49)) {
+ * cam.setPosition(30, 0, 80);
+ * }
+ * // '2' key
+ * if (keyIsDown(50)) {
+ * cam.setPosition(0, 0, 80);
+ * }
+ * // '3' key
+ * if (keyIsDown(51)) {
+ * cam.setPosition(-30, 0, 80);
+ * }
+ *
+ * box(20);
+ * }
+ *
+ *
+ *
+ * @alt
+ * camera position changes as the user presses keys, altering view of a 3D box
+ */
+ _main.default.Camera.prototype.setPosition = function(x, y, z) {
+ var diffX = x - this.eyeX;
+ var diffY = y - this.eyeY;
+ var diffZ = z - this.eyeZ;
+
+ this.camera(
+ x,
+ y,
+ z,
+ this.centerX + diffX,
+ this.centerY + diffY,
+ this.centerZ + diffZ,
+ 0,
+ 1,
+ 0
+ );
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // Camera Helper Methods
+ ////////////////////////////////////////////////////////////////////////////////
+
+ // @TODO: combine this function with _setDefaultCamera to compute these values
+ // as-needed
+ _main.default.Camera.prototype._computeCameraDefaultSettings = function() {
+ this.defaultCameraFOV = 60 / 180 * Math.PI;
+ this.defaultAspectRatio = this._renderer.width / this._renderer.height;
+ this.defaultEyeX = 0;
+ this.defaultEyeY = 0;
+ this.defaultEyeZ =
+ this._renderer.height / 2.0 / Math.tan(this.defaultCameraFOV / 2.0);
+ this.defaultCenterX = 0;
+ this.defaultCenterY = 0;
+ this.defaultCenterZ = 0;
+ this.defaultCameraNear = this.defaultEyeZ * 0.1;
+ this.defaultCameraFar = this.defaultEyeZ * 10;
+ };
+
+ //detect if user didn't set the camera
+ //then call this function below
+ _main.default.Camera.prototype._setDefaultCamera = function() {
+ this.cameraFOV = this.defaultCameraFOV;
+ this.aspectRatio = this.defaultAspectRatio;
+ this.eyeX = this.defaultEyeX;
+ this.eyeY = this.defaultEyeY;
+ this.eyeZ = this.defaultEyeZ;
+ this.centerX = this.defaultCenterX;
+ this.centerY = this.defaultCenterY;
+ this.centerZ = this.defaultCenterZ;
+ this.upX = 0;
+ this.upY = 1;
+ this.upZ = 0;
+ this.cameraNear = this.defaultCameraNear;
+ this.cameraFar = this.defaultCameraFar;
+
+ this.perspective();
+ this.camera();
+
+ this.cameraType = 'default';
+ };
+
+ _main.default.Camera.prototype._resize = function() {
+ // If we're using the default camera, update the aspect ratio
+ if (this.cameraType === 'default') {
+ this._computeCameraDefaultSettings();
+ this._setDefaultCamera();
+ } else {
+ this.perspective(
+ this.cameraFOV,
+ this._renderer.width / this._renderer.height
+ );
+ }
+ };
+
+ /**
+ * Returns a copy of a camera.
+ * @method copy
+ * @private
+ */
+ _main.default.Camera.prototype.copy = function() {
+ var _cam = new _main.default.Camera(this._renderer);
+ _cam.cameraFOV = this.cameraFOV;
+ _cam.aspectRatio = this.aspectRatio;
+ _cam.eyeX = this.eyeX;
+ _cam.eyeY = this.eyeY;
+ _cam.eyeZ = this.eyeZ;
+ _cam.centerX = this.centerX;
+ _cam.centerY = this.centerY;
+ _cam.centerZ = this.centerZ;
+ _cam.cameraNear = this.cameraNear;
+ _cam.cameraFar = this.cameraFar;
+
+ _cam.cameraType = this.cameraType;
+
+ _cam.cameraMatrix = this.cameraMatrix.copy();
+ _cam.projMatrix = this.projMatrix.copy();
+
+ return _cam;
+ };
+
+ /**
+ * Returns a camera's local axes: left-right, up-down, and forward-backward,
+ * as defined by vectors in world-space.
+ * @method _getLocalAxes
+ * @private
+ */
+ _main.default.Camera.prototype._getLocalAxes = function() {
+ // calculate camera local Z vector
+ var z0 = this.eyeX - this.centerX;
+ var z1 = this.eyeY - this.centerY;
+ var z2 = this.eyeZ - this.centerZ;
+
+ // normalize camera local Z vector
+ var eyeDist = Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
+ if (eyeDist !== 0) {
+ z0 /= eyeDist;
+ z1 /= eyeDist;
+ z2 /= eyeDist;
+ }
+
+ // calculate camera Y vector
+ var y0 = this.upX;
+ var y1 = this.upY;
+ var y2 = this.upZ;
+
+ // compute camera local X vector as up vector (local Y) cross local Z
+ var x0 = y1 * z2 - y2 * z1;
+ var x1 = -y0 * z2 + y2 * z0;
+ var x2 = y0 * z1 - y1 * z0;
+
+ // recompute y = z cross x
+ y0 = z1 * x2 - z2 * x1;
+ y1 = -z0 * x2 + z2 * x0;
+ y2 = z0 * x1 - z1 * x0;
+
+ // cross product gives area of parallelogram, which is < 1.0 for
+ // non-perpendicular unit-length vectors; so normalize x, y here:
+ var xmag = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
+ if (xmag !== 0) {
+ x0 /= xmag;
+ x1 /= xmag;
+ x2 /= xmag;
+ }
+
+ var ymag = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
+ if (ymag !== 0) {
+ y0 /= ymag;
+ y1 /= ymag;
+ y2 /= ymag;
+ }
+
+ return {
+ x: [x0, x1, x2],
+ y: [y0, y1, y2],
+ z: [z0, z1, z2]
+ };
+ };
+
+ /**
+ * Orbits the camera about center point. For use with orbitControl().
+ * @method _orbit
+ * @private
+ * @param {Number} dTheta change in spherical coordinate theta
+ * @param {Number} dPhi change in spherical coordinate phi
+ * @param {Number} dRadius change in radius
+ */
+ _main.default.Camera.prototype._orbit = function(dTheta, dPhi, dRadius) {
+ var diffX = this.eyeX - this.centerX;
+ var diffY = this.eyeY - this.centerY;
+ var diffZ = this.eyeZ - this.centerZ;
+
+ // get spherical coorinates for current camera position about origin
+ var camRadius = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ);
+ // from https://github.com/mrdoob/three.js/blob/dev/src/math/Spherical.js#L72-L73
+ var camTheta = Math.atan2(diffX, diffZ); // equatorial angle
+ var camPhi = Math.acos(Math.max(-1, Math.min(1, diffY / camRadius))); // polar angle
+
+ // add change
+ camTheta += dTheta;
+ camPhi += dPhi;
+ camRadius += dRadius;
+
+ // prevent zooming through the center:
+ if (camRadius < 0) {
+ camRadius = 0.1;
+ }
+
+ // prevent rotation over the zenith / under bottom
+ if (camPhi > Math.PI) {
+ camPhi = Math.PI;
+ } else if (camPhi <= 0) {
+ camPhi = 0.001;
+ }
+
+ // from https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js#L628-L632
+ var _x = Math.sin(camPhi) * camRadius * Math.sin(camTheta);
+ var _y = Math.cos(camPhi) * camRadius;
+ var _z = Math.sin(camPhi) * camRadius * Math.cos(camTheta);
+
+ this.camera(
+ _x + this.centerX,
+ _y + this.centerY,
+ _z + this.centerZ,
+ this.centerX,
+ this.centerY,
+ this.centerZ,
+ 0,
+ 1,
+ 0
+ );
+ };
+
+ /**
+ * Returns true if camera is currently attached to renderer.
+ * @method _isActive
+ * @private
+ */
+ _main.default.Camera.prototype._isActive = function() {
+ return this === this._renderer._curCamera;
+ };
+
+ /**
+ * Sets rendererGL's current camera to a p5.Camera object. Allows switching
+ * between multiple cameras.
+ * @method setCamera
+ * @param {p5.Camera} cam p5.Camera object
+ * @for p5
+ * @example
+ *
+ *
+ * let cam1, cam2;
+ * let currentCamera;
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * normalMaterial();
+ *
+ * cam1 = createCamera();
+ * cam2 = createCamera();
+ * cam2.setPosition(30, 0, 50);
+ * cam2.lookAt(0, 0, 0);
+ * cam2.ortho();
+ *
+ * // set variable for previously active camera:
+ * currentCamera = 1;
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // camera 1:
+ * cam1.lookAt(0, 0, 0);
+ * cam1.setPosition(sin(frameCount / 60) * 200, 0, 100);
+ *
+ * // every 100 frames, switch between the two cameras
+ * if (frameCount % 100 === 0) {
+ * if (currentCamera === 1) {
+ * setCamera(cam1);
+ * currentCamera = 0;
+ * } else {
+ * setCamera(cam2);
+ * currentCamera = 1;
+ * }
+ * }
+ *
+ * drawBoxes();
+ * }
+ *
+ * function drawBoxes() {
+ * rotateX(frameCount * 0.01);
+ * translate(-100, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * translate(35, 0, 0);
+ * box(20);
+ * }
+ *
+ *
+ *
+ * @alt
+ * Canvas switches between two camera views, each showing a series of spinning
+ * 3D boxes.
+ */
+ _main.default.prototype.setCamera = function(cam) {
+ this._renderer._curCamera = cam;
+
+ // set the projection matrix (which is not normally updated each frame)
+ this._renderer.uPMatrix.set(
+ cam.projMatrix.mat4[0],
+ cam.projMatrix.mat4[1],
+ cam.projMatrix.mat4[2],
+ cam.projMatrix.mat4[3],
+ cam.projMatrix.mat4[4],
+ cam.projMatrix.mat4[5],
+ cam.projMatrix.mat4[6],
+ cam.projMatrix.mat4[7],
+ cam.projMatrix.mat4[8],
+ cam.projMatrix.mat4[9],
+ cam.projMatrix.mat4[10],
+ cam.projMatrix.mat4[11],
+ cam.projMatrix.mat4[12],
+ cam.projMatrix.mat4[13],
+ cam.projMatrix.mat4[14],
+ cam.projMatrix.mat4[15]
+ );
+ };
+ var _default = _main.default.Camera;
+ exports.default = _default;
+ },
+ { '../core/main': 283 }
+ ],
+ 332: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ _dereq_('core-js/modules/es.string.sub');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ } /** //some of the functions are adjusted from Three.js(http://threejs.org)
+ * @module Lights, Camera
+ * @submodule Material
+ * @for p5
+ * @requires core
+ * @requires p5.Geometry
+ */
+ /**
+ * p5 Geometry class
+ * @class p5.Geometry
+ * @constructor
+ * @param {Integer} [detailX] number of vertices on horizontal surface
+ * @param {Integer} [detailY] number of vertices on horizontal surface
+ * @param {function} [callback] function to call upon object instantiation.
+ */ _main.default.Geometry = function(detailX, detailY, callback) {
+ //an array containing every vertex
+ //@type [p5.Vector]
+ this.vertices = []; //an array containing every vertex for stroke drawing
+ this.lineVertices = []; //an array 1 normal per lineVertex with
+ //final position representing which direction to
+ //displace for strokeWeight
+ //[[0,0,-1,1], [0,1,0,-1] ...];
+ this.lineNormals = [];
+
+ //an array containing 1 normal per vertex
+ //@type [p5.Vector]
+ //[p5.Vector, p5.Vector, p5.Vector,p5.Vector, p5.Vector, p5.Vector,...]
+ this.vertexNormals = [];
+ //an array containing each three vertex indices that form a face
+ //[[0, 1, 2], [2, 1, 3], ...]
+ this.faces = [];
+ //a 2D array containing uvs for every vertex
+ //[[0.0,0.0],[1.0,0.0], ...]
+ this.uvs = [];
+ // a 2D array containing edge connectivity pattern for create line vertices
+ //based on faces for most objects;
+ this.edges = [];
+ this.vertexColors = [];
+ this.detailX = detailX !== undefined ? detailX : 1;
+ this.detailY = detailY !== undefined ? detailY : 1;
+ this.dirtyFlags = {};
+
+ if (callback instanceof Function) {
+ callback.call(this);
+ }
+ return this; // TODO: is this a constructor?
+ };
+
+ _main.default.Geometry.prototype.reset = function() {
+ this.lineVertices.length = 0;
+ this.lineNormals.length = 0;
+
+ this.vertices.length = 0;
+ this.edges.length = 0;
+ this.vertexColors.length = 0;
+ this.vertexNormals.length = 0;
+ this.uvs.length = 0;
+
+ this.dirtyFlags = {};
+ };
+
+ /**
+ * computes faces for geometry objects based on the vertices.
+ * @method computeFaces
+ * @chainable
+ */
+ _main.default.Geometry.prototype.computeFaces = function() {
+ this.faces.length = 0;
+ var sliceCount = this.detailX + 1;
+ var a, b, c, d;
+ for (var i = 0; i < this.detailY; i++) {
+ for (var j = 0; j < this.detailX; j++) {
+ a = i * sliceCount + j; // + offset;
+ b = i * sliceCount + j + 1; // + offset;
+ c = (i + 1) * sliceCount + j + 1; // + offset;
+ d = (i + 1) * sliceCount + j; // + offset;
+ this.faces.push([a, b, d]);
+ this.faces.push([d, b, c]);
+ }
+ }
+ return this;
+ };
+
+ _main.default.Geometry.prototype._getFaceNormal = function(faceId) {
+ //This assumes that vA->vB->vC is a counter-clockwise ordering
+ var face = this.faces[faceId];
+ var vA = this.vertices[face[0]];
+ var vB = this.vertices[face[1]];
+ var vC = this.vertices[face[2]];
+ var ab = _main.default.Vector.sub(vB, vA);
+ var ac = _main.default.Vector.sub(vC, vA);
+ var n = _main.default.Vector.cross(ab, ac);
+ var ln = _main.default.Vector.mag(n);
+ var sinAlpha =
+ ln / (_main.default.Vector.mag(ab) * _main.default.Vector.mag(ac));
+ if (sinAlpha === 0 || isNaN(sinAlpha)) {
+ console.warn(
+ 'p5.Geometry.prototype._getFaceNormal:',
+ 'face has colinear sides or a repeated vertex'
+ );
+
+ return n;
+ }
+ if (sinAlpha > 1) sinAlpha = 1; // handle float rounding error
+ return n.mult(Math.asin(sinAlpha) / ln);
+ };
+ /**
+ * computes smooth normals per vertex as an average of each
+ * face.
+ * @method computeNormals
+ * @chainable
+ */
+ _main.default.Geometry.prototype.computeNormals = function() {
+ var vertexNormals = this.vertexNormals;
+ var vertices = this.vertices;
+ var faces = this.faces;
+ var iv;
+
+ // initialize the vertexNormals array with empty vectors
+ vertexNormals.length = 0;
+ for (iv = 0; iv < vertices.length; ++iv) {
+ vertexNormals.push(new _main.default.Vector());
+ }
+
+ // loop through all the faces adding its normal to the normal
+ // of each of its vertices
+ for (var f = 0; f < faces.length; ++f) {
+ var face = faces[f];
+ var faceNormal = this._getFaceNormal(f);
+
+ // all three vertices get the normal added
+ for (var fv = 0; fv < 3; ++fv) {
+ var vertexIndex = face[fv];
+ vertexNormals[vertexIndex].add(faceNormal);
+ }
+ }
+
+ // normalize the normals
+ for (iv = 0; iv < vertices.length; ++iv) {
+ vertexNormals[iv].normalize();
+ }
+
+ return this;
+ };
+
+ /**
+ * Averages the vertex normals. Used in curved
+ * surfaces
+ * @method averageNormals
+ * @chainable
+ */
+ _main.default.Geometry.prototype.averageNormals = function() {
+ for (var i = 0; i <= this.detailY; i++) {
+ var offset = this.detailX + 1;
+ var temp = _main.default.Vector.add(
+ this.vertexNormals[i * offset],
+ this.vertexNormals[i * offset + this.detailX]
+ );
+
+ temp = _main.default.Vector.div(temp, 2);
+ this.vertexNormals[i * offset] = temp;
+ this.vertexNormals[i * offset + this.detailX] = temp;
+ }
+ return this;
+ };
+
+ /**
+ * Averages pole normals. Used in spherical primitives
+ * @method averagePoleNormals
+ * @chainable
+ */
+ _main.default.Geometry.prototype.averagePoleNormals = function() {
+ //average the north pole
+ var sum = new _main.default.Vector(0, 0, 0);
+ for (var i = 0; i < this.detailX; i++) {
+ sum.add(this.vertexNormals[i]);
+ }
+ sum = _main.default.Vector.div(sum, this.detailX);
+
+ for (var _i = 0; _i < this.detailX; _i++) {
+ this.vertexNormals[_i] = sum;
+ }
+
+ //average the south pole
+ sum = new _main.default.Vector(0, 0, 0);
+ for (
+ var _i2 = this.vertices.length - 1;
+ _i2 > this.vertices.length - 1 - this.detailX;
+ _i2--
+ ) {
+ sum.add(this.vertexNormals[_i2]);
+ }
+ sum = _main.default.Vector.div(sum, this.detailX);
+
+ for (
+ var _i3 = this.vertices.length - 1;
+ _i3 > this.vertices.length - 1 - this.detailX;
+ _i3--
+ ) {
+ this.vertexNormals[_i3] = sum;
+ }
+ return this;
+ };
+
+ /**
+ * Create a 2D array for establishing stroke connections
+ * @private
+ * @chainable
+ */
+ _main.default.Geometry.prototype._makeTriangleEdges = function() {
+ this.edges.length = 0;
+ if (Array.isArray(this.strokeIndices)) {
+ for (var i = 0, max = this.strokeIndices.length; i < max; i++) {
+ this.edges.push(this.strokeIndices[i]);
+ }
+ } else {
+ for (var j = 0; j < this.faces.length; j++) {
+ this.edges.push([this.faces[j][0], this.faces[j][1]]);
+ this.edges.push([this.faces[j][1], this.faces[j][2]]);
+ this.edges.push([this.faces[j][2], this.faces[j][0]]);
+ }
+ }
+ return this;
+ };
+
+ /**
+ * Create 4 vertices for each stroke line, two at the beginning position
+ * and two at the end position. These vertices are displaced relative to
+ * that line's normal on the GPU
+ * @private
+ * @chainable
+ */
+ _main.default.Geometry.prototype._edgesToVertices = function() {
+ this.lineVertices.length = 0;
+ this.lineNormals.length = 0;
+
+ for (var i = 0; i < this.edges.length; i++) {
+ var begin = this.vertices[this.edges[i][0]];
+ var end = this.vertices[this.edges[i][1]];
+ var dir = end
+ .copy()
+ .sub(begin)
+ .normalize();
+ var a = begin.array();
+ var b = begin.array();
+ var c = end.array();
+ var d = end.array();
+ var dirAdd = dir.array();
+ var dirSub = dir.array();
+ // below is used to displace the pair of vertices at beginning and end
+ // in opposite directions
+ dirAdd.push(1);
+ dirSub.push(-1);
+ this.lineNormals.push(dirAdd, dirSub, dirAdd, dirAdd, dirSub, dirSub);
+ this.lineVertices.push(a, b, c, c, b, d);
+ }
+ return this;
+ };
+
+ /**
+ * Modifies all vertices to be centered within the range -100 to 100.
+ * @method normalize
+ * @chainable
+ */
+ _main.default.Geometry.prototype.normalize = function() {
+ if (this.vertices.length > 0) {
+ // Find the corners of our bounding box
+ var maxPosition = this.vertices[0].copy();
+ var minPosition = this.vertices[0].copy();
+
+ for (var i = 0; i < this.vertices.length; i++) {
+ maxPosition.x = Math.max(maxPosition.x, this.vertices[i].x);
+ minPosition.x = Math.min(minPosition.x, this.vertices[i].x);
+ maxPosition.y = Math.max(maxPosition.y, this.vertices[i].y);
+ minPosition.y = Math.min(minPosition.y, this.vertices[i].y);
+ maxPosition.z = Math.max(maxPosition.z, this.vertices[i].z);
+ minPosition.z = Math.min(minPosition.z, this.vertices[i].z);
+ }
+
+ var center = _main.default.Vector.lerp(maxPosition, minPosition, 0.5);
+ var dist = _main.default.Vector.sub(maxPosition, minPosition);
+ var longestDist = Math.max(Math.max(dist.x, dist.y), dist.z);
+ var scale = 200 / longestDist;
+
+ for (var _i4 = 0; _i4 < this.vertices.length; _i4++) {
+ this.vertices[_i4].sub(center);
+ this.vertices[_i4].mult(scale);
+ }
+ }
+ return this;
+ };
+ var _default = _main.default.Geometry;
+ exports.default = _default;
+ },
+ { '../core/main': 283, 'core-js/modules/es.string.sub': 207 }
+ ],
+ 333: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.typed-array.float32-array');
+ _dereq_('core-js/modules/es.typed-array.copy-within');
+ _dereq_('core-js/modules/es.typed-array.every');
+ _dereq_('core-js/modules/es.typed-array.fill');
+ _dereq_('core-js/modules/es.typed-array.filter');
+ _dereq_('core-js/modules/es.typed-array.find');
+ _dereq_('core-js/modules/es.typed-array.find-index');
+ _dereq_('core-js/modules/es.typed-array.for-each');
+ _dereq_('core-js/modules/es.typed-array.includes');
+ _dereq_('core-js/modules/es.typed-array.index-of');
+ _dereq_('core-js/modules/es.typed-array.iterator');
+ _dereq_('core-js/modules/es.typed-array.join');
+ _dereq_('core-js/modules/es.typed-array.last-index-of');
+ _dereq_('core-js/modules/es.typed-array.map');
+ _dereq_('core-js/modules/es.typed-array.reduce');
+ _dereq_('core-js/modules/es.typed-array.reduce-right');
+ _dereq_('core-js/modules/es.typed-array.reverse');
+ _dereq_('core-js/modules/es.typed-array.set');
+ _dereq_('core-js/modules/es.typed-array.slice');
+ _dereq_('core-js/modules/es.typed-array.some');
+ _dereq_('core-js/modules/es.typed-array.sort');
+ _dereq_('core-js/modules/es.typed-array.subarray');
+ _dereq_('core-js/modules/es.typed-array.to-locale-string');
+ _dereq_('core-js/modules/es.typed-array.to-string');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+ /**
+ * @requires constants
+ * @todo see methods below needing further implementation.
+ * future consideration: implement SIMD optimizations
+ * when browser compatibility becomes available
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/
+ * Reference/Global_Objects/SIMD
+ */ var GLMAT_ARRAY_TYPE = Array;
+ var isMatrixArray = function isMatrixArray(x) {
+ return x instanceof Array;
+ };
+ if (typeof Float32Array !== 'undefined') {
+ GLMAT_ARRAY_TYPE = Float32Array;
+ isMatrixArray = function isMatrixArray(x) {
+ return x instanceof Array || x instanceof Float32Array;
+ };
+ }
+
+ /**
+ * A class to describe a 4x4 matrix
+ * for model and view matrix manipulation in the p5js webgl renderer.
+ * @class p5.Matrix
+ * @private
+ * @constructor
+ * @param {Array} [mat4] array literal of our 4x4 matrix
+ */
+ _main.default.Matrix = function() {
+ var args = new Array(arguments.length);
+ for (var i = 0; i < args.length; ++i) {
+ args[i] = arguments[i];
+ }
+
+ // This is default behavior when object
+ // instantiated using createMatrix()
+ // @todo implement createMatrix() in core/math.js
+ if (args.length && args[args.length - 1] instanceof _main.default) {
+ this.p5 = args[args.length - 1];
+ }
+
+ if (args[0] === 'mat3') {
+ this.mat3 = Array.isArray(args[1])
+ ? args[1]
+ : new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 1, 0, 0, 0, 1]);
+ } else {
+ this.mat4 = Array.isArray(args[0])
+ ? args[0]
+ : new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
+ }
+ return this;
+ };
+
+ /**
+ * Sets the x, y, and z component of the vector using two or three separate
+ * variables, the data from a p5.Matrix, or the values from a float array.
+ *
+ * @method set
+ * @param {p5.Matrix|Float32Array|Number[]} [inMatrix] the input p5.Matrix or
+ * an Array of length 16
+ * @chainable
+ */
+ /**
+ * @method set
+ * @param {Number[]} elements 16 numbers passed by value to avoid
+ * array copying.
+ * @chainable
+ */
+ _main.default.Matrix.prototype.set = function(inMatrix) {
+ if (inMatrix instanceof _main.default.Matrix) {
+ this.mat4 = inMatrix.mat4;
+ return this;
+ } else if (isMatrixArray(inMatrix)) {
+ this.mat4 = inMatrix;
+ return this;
+ } else if (arguments.length === 16) {
+ this.mat4[0] = arguments[0];
+ this.mat4[1] = arguments[1];
+ this.mat4[2] = arguments[2];
+ this.mat4[3] = arguments[3];
+ this.mat4[4] = arguments[4];
+ this.mat4[5] = arguments[5];
+ this.mat4[6] = arguments[6];
+ this.mat4[7] = arguments[7];
+ this.mat4[8] = arguments[8];
+ this.mat4[9] = arguments[9];
+ this.mat4[10] = arguments[10];
+ this.mat4[11] = arguments[11];
+ this.mat4[12] = arguments[12];
+ this.mat4[13] = arguments[13];
+ this.mat4[14] = arguments[14];
+ this.mat4[15] = arguments[15];
+ }
+ return this;
+ };
+
+ /**
+ * Gets a copy of the vector, returns a p5.Matrix object.
+ *
+ * @method get
+ * @return {p5.Matrix} the copy of the p5.Matrix object
+ */
+ _main.default.Matrix.prototype.get = function() {
+ return new _main.default.Matrix(this.mat4, this.p5);
+ };
+
+ /**
+ * return a copy of a matrix
+ * @method copy
+ * @return {p5.Matrix} the result matrix
+ */
+ _main.default.Matrix.prototype.copy = function() {
+ var copied = new _main.default.Matrix(this.p5);
+ copied.mat4[0] = this.mat4[0];
+ copied.mat4[1] = this.mat4[1];
+ copied.mat4[2] = this.mat4[2];
+ copied.mat4[3] = this.mat4[3];
+ copied.mat4[4] = this.mat4[4];
+ copied.mat4[5] = this.mat4[5];
+ copied.mat4[6] = this.mat4[6];
+ copied.mat4[7] = this.mat4[7];
+ copied.mat4[8] = this.mat4[8];
+ copied.mat4[9] = this.mat4[9];
+ copied.mat4[10] = this.mat4[10];
+ copied.mat4[11] = this.mat4[11];
+ copied.mat4[12] = this.mat4[12];
+ copied.mat4[13] = this.mat4[13];
+ copied.mat4[14] = this.mat4[14];
+ copied.mat4[15] = this.mat4[15];
+ return copied;
+ };
+
+ /**
+ * return an identity matrix
+ * @method identity
+ * @return {p5.Matrix} the result matrix
+ */
+ _main.default.Matrix.identity = function(pInst) {
+ return new _main.default.Matrix(pInst);
+ };
+
+ /**
+ * transpose according to a given matrix
+ * @method transpose
+ * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be
+ * based on to transpose
+ * @chainable
+ */
+ _main.default.Matrix.prototype.transpose = function(a) {
+ var a01, a02, a03, a12, a13, a23;
+ if (a instanceof _main.default.Matrix) {
+ a01 = a.mat4[1];
+ a02 = a.mat4[2];
+ a03 = a.mat4[3];
+ a12 = a.mat4[6];
+ a13 = a.mat4[7];
+ a23 = a.mat4[11];
+
+ this.mat4[0] = a.mat4[0];
+ this.mat4[1] = a.mat4[4];
+ this.mat4[2] = a.mat4[8];
+ this.mat4[3] = a.mat4[12];
+ this.mat4[4] = a01;
+ this.mat4[5] = a.mat4[5];
+ this.mat4[6] = a.mat4[9];
+ this.mat4[7] = a.mat4[13];
+ this.mat4[8] = a02;
+ this.mat4[9] = a12;
+ this.mat4[10] = a.mat4[10];
+ this.mat4[11] = a.mat4[14];
+ this.mat4[12] = a03;
+ this.mat4[13] = a13;
+ this.mat4[14] = a23;
+ this.mat4[15] = a.mat4[15];
+ } else if (isMatrixArray(a)) {
+ a01 = a[1];
+ a02 = a[2];
+ a03 = a[3];
+ a12 = a[6];
+ a13 = a[7];
+ a23 = a[11];
+
+ this.mat4[0] = a[0];
+ this.mat4[1] = a[4];
+ this.mat4[2] = a[8];
+ this.mat4[3] = a[12];
+ this.mat4[4] = a01;
+ this.mat4[5] = a[5];
+ this.mat4[6] = a[9];
+ this.mat4[7] = a[13];
+ this.mat4[8] = a02;
+ this.mat4[9] = a12;
+ this.mat4[10] = a[10];
+ this.mat4[11] = a[14];
+ this.mat4[12] = a03;
+ this.mat4[13] = a13;
+ this.mat4[14] = a23;
+ this.mat4[15] = a[15];
+ }
+ return this;
+ };
+
+ /**
+ * invert matrix according to a give matrix
+ * @method invert
+ * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be
+ * based on to invert
+ * @chainable
+ */
+ _main.default.Matrix.prototype.invert = function(a) {
+ var a00, a01, a02, a03, a10, a11, a12, a13;
+ var a20, a21, a22, a23, a30, a31, a32, a33;
+ if (a instanceof _main.default.Matrix) {
+ a00 = a.mat4[0];
+ a01 = a.mat4[1];
+ a02 = a.mat4[2];
+ a03 = a.mat4[3];
+ a10 = a.mat4[4];
+ a11 = a.mat4[5];
+ a12 = a.mat4[6];
+ a13 = a.mat4[7];
+ a20 = a.mat4[8];
+ a21 = a.mat4[9];
+ a22 = a.mat4[10];
+ a23 = a.mat4[11];
+ a30 = a.mat4[12];
+ a31 = a.mat4[13];
+ a32 = a.mat4[14];
+ a33 = a.mat4[15];
+ } else if (isMatrixArray(a)) {
+ a00 = a[0];
+ a01 = a[1];
+ a02 = a[2];
+ a03 = a[3];
+ a10 = a[4];
+ a11 = a[5];
+ a12 = a[6];
+ a13 = a[7];
+ a20 = a[8];
+ a21 = a[9];
+ a22 = a[10];
+ a23 = a[11];
+ a30 = a[12];
+ a31 = a[13];
+ a32 = a[14];
+ a33 = a[15];
+ }
+ var b00 = a00 * a11 - a01 * a10;
+ var b01 = a00 * a12 - a02 * a10;
+ var b02 = a00 * a13 - a03 * a10;
+ var b03 = a01 * a12 - a02 * a11;
+ var b04 = a01 * a13 - a03 * a11;
+ var b05 = a02 * a13 - a03 * a12;
+ var b06 = a20 * a31 - a21 * a30;
+ var b07 = a20 * a32 - a22 * a30;
+ var b08 = a20 * a33 - a23 * a30;
+ var b09 = a21 * a32 - a22 * a31;
+ var b10 = a21 * a33 - a23 * a31;
+ var b11 = a22 * a33 - a23 * a32;
+
+ // Calculate the determinant
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
+
+ if (!det) {
+ return null;
+ }
+ det = 1.0 / det;
+
+ this.mat4[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
+ this.mat4[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
+ this.mat4[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
+ this.mat4[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
+ this.mat4[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
+ this.mat4[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
+ this.mat4[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
+ this.mat4[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
+ this.mat4[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
+ this.mat4[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
+ this.mat4[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
+ this.mat4[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
+ this.mat4[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
+ this.mat4[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
+ this.mat4[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
+ this.mat4[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
+
+ return this;
+ };
+
+ /**
+ * Inverts a 3x3 matrix
+ * @method invert3x3
+ * @chainable
+ */
+ _main.default.Matrix.prototype.invert3x3 = function() {
+ var a00 = this.mat3[0];
+ var a01 = this.mat3[1];
+ var a02 = this.mat3[2];
+ var a10 = this.mat3[3];
+ var a11 = this.mat3[4];
+ var a12 = this.mat3[5];
+ var a20 = this.mat3[6];
+ var a21 = this.mat3[7];
+ var a22 = this.mat3[8];
+ var b01 = a22 * a11 - a12 * a21;
+ var b11 = -a22 * a10 + a12 * a20;
+ var b21 = a21 * a10 - a11 * a20;
+
+ // Calculate the determinant
+ var det = a00 * b01 + a01 * b11 + a02 * b21;
+ if (!det) {
+ return null;
+ }
+ det = 1.0 / det;
+ this.mat3[0] = b01 * det;
+ this.mat3[1] = (-a22 * a01 + a02 * a21) * det;
+ this.mat3[2] = (a12 * a01 - a02 * a11) * det;
+ this.mat3[3] = b11 * det;
+ this.mat3[4] = (a22 * a00 - a02 * a20) * det;
+ this.mat3[5] = (-a12 * a00 + a02 * a10) * det;
+ this.mat3[6] = b21 * det;
+ this.mat3[7] = (-a21 * a00 + a01 * a20) * det;
+ this.mat3[8] = (a11 * a00 - a01 * a10) * det;
+ return this;
+ };
+
+ /**
+ * transposes a 3x3 p5.Matrix by a mat3
+ * @method transpose3x3
+ * @param {Number[]} mat3 1-dimensional array
+ * @chainable
+ */
+ _main.default.Matrix.prototype.transpose3x3 = function(mat3) {
+ var a01 = mat3[1],
+ a02 = mat3[2],
+ a12 = mat3[5];
+ this.mat3[1] = mat3[3];
+ this.mat3[2] = mat3[6];
+ this.mat3[3] = a01;
+ this.mat3[5] = mat3[7];
+ this.mat3[6] = a02;
+ this.mat3[7] = a12;
+ return this;
+ };
+
+ /**
+ * converts a 4x4 matrix to its 3x3 inverse transform
+ * commonly used in MVMatrix to NMatrix conversions.
+ * @method invertTranspose
+ * @param {p5.Matrix} mat4 the matrix to be based on to invert
+ * @chainable
+ * @todo finish implementation
+ */
+ _main.default.Matrix.prototype.inverseTranspose = function(matrix) {
+ if (this.mat3 === undefined) {
+ console.error('sorry, this function only works with mat3');
+ } else {
+ //convert mat4 -> mat3
+ this.mat3[0] = matrix.mat4[0];
+ this.mat3[1] = matrix.mat4[1];
+ this.mat3[2] = matrix.mat4[2];
+ this.mat3[3] = matrix.mat4[4];
+ this.mat3[4] = matrix.mat4[5];
+ this.mat3[5] = matrix.mat4[6];
+ this.mat3[6] = matrix.mat4[8];
+ this.mat3[7] = matrix.mat4[9];
+ this.mat3[8] = matrix.mat4[10];
+ }
+
+ var inverse = this.invert3x3();
+ // check inverse succeeded
+ if (inverse) {
+ inverse.transpose3x3(this.mat3);
+ } else {
+ // in case of singularity, just zero the matrix
+ for (var i = 0; i < 9; i++) {
+ this.mat3[i] = 0;
+ }
+ }
+ return this;
+ };
+
+ /**
+ * inspired by Toji's mat4 determinant
+ * @method determinant
+ * @return {Number} Determinant of our 4x4 matrix
+ */
+ _main.default.Matrix.prototype.determinant = function() {
+ var d00 = this.mat4[0] * this.mat4[5] - this.mat4[1] * this.mat4[4],
+ d01 = this.mat4[0] * this.mat4[6] - this.mat4[2] * this.mat4[4],
+ d02 = this.mat4[0] * this.mat4[7] - this.mat4[3] * this.mat4[4],
+ d03 = this.mat4[1] * this.mat4[6] - this.mat4[2] * this.mat4[5],
+ d04 = this.mat4[1] * this.mat4[7] - this.mat4[3] * this.mat4[5],
+ d05 = this.mat4[2] * this.mat4[7] - this.mat4[3] * this.mat4[6],
+ d06 = this.mat4[8] * this.mat4[13] - this.mat4[9] * this.mat4[12],
+ d07 = this.mat4[8] * this.mat4[14] - this.mat4[10] * this.mat4[12],
+ d08 = this.mat4[8] * this.mat4[15] - this.mat4[11] * this.mat4[12],
+ d09 = this.mat4[9] * this.mat4[14] - this.mat4[10] * this.mat4[13],
+ d10 = this.mat4[9] * this.mat4[15] - this.mat4[11] * this.mat4[13],
+ d11 = this.mat4[10] * this.mat4[15] - this.mat4[11] * this.mat4[14];
+
+ // Calculate the determinant
+ return d00 * d11 - d01 * d10 + d02 * d09 + d03 * d08 - d04 * d07 + d05 * d06;
+ };
+
+ /**
+ * multiply two mat4s
+ * @method mult
+ * @param {p5.Matrix|Float32Array|Number[]} multMatrix The matrix
+ * we want to multiply by
+ * @chainable
+ */
+ _main.default.Matrix.prototype.mult = function(multMatrix) {
+ var _src;
+
+ if (multMatrix === this || multMatrix === this.mat4) {
+ _src = this.copy().mat4; // only need to allocate in this rare case
+ } else if (multMatrix instanceof _main.default.Matrix) {
+ _src = multMatrix.mat4;
+ } else if (isMatrixArray(multMatrix)) {
+ _src = multMatrix;
+ } else if (arguments.length === 16) {
+ _src = arguments;
+ } else {
+ return; // nothing to do.
+ }
+
+ // each row is used for the multiplier
+ var b0 = this.mat4[0],
+ b1 = this.mat4[1],
+ b2 = this.mat4[2],
+ b3 = this.mat4[3];
+ this.mat4[0] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
+ this.mat4[1] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
+ this.mat4[2] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
+ this.mat4[3] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
+
+ b0 = this.mat4[4];
+ b1 = this.mat4[5];
+ b2 = this.mat4[6];
+ b3 = this.mat4[7];
+ this.mat4[4] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
+ this.mat4[5] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
+ this.mat4[6] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
+ this.mat4[7] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
+
+ b0 = this.mat4[8];
+ b1 = this.mat4[9];
+ b2 = this.mat4[10];
+ b3 = this.mat4[11];
+ this.mat4[8] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
+ this.mat4[9] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
+ this.mat4[10] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
+ this.mat4[11] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
+
+ b0 = this.mat4[12];
+ b1 = this.mat4[13];
+ b2 = this.mat4[14];
+ b3 = this.mat4[15];
+ this.mat4[12] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12];
+ this.mat4[13] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13];
+ this.mat4[14] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14];
+ this.mat4[15] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15];
+
+ return this;
+ };
+
+ _main.default.Matrix.prototype.apply = function(multMatrix) {
+ var _src;
+
+ if (multMatrix === this || multMatrix === this.mat4) {
+ _src = this.copy().mat4; // only need to allocate in this rare case
+ } else if (multMatrix instanceof _main.default.Matrix) {
+ _src = multMatrix.mat4;
+ } else if (isMatrixArray(multMatrix)) {
+ _src = multMatrix;
+ } else if (arguments.length === 16) {
+ _src = arguments;
+ } else {
+ return; // nothing to do.
+ }
+
+ var mat4 = this.mat4;
+
+ // each row is used for the multiplier
+ var m0 = mat4[0];
+ var m4 = mat4[4];
+ var m8 = mat4[8];
+ var m12 = mat4[12];
+ mat4[0] = _src[0] * m0 + _src[1] * m4 + _src[2] * m8 + _src[3] * m12;
+ mat4[4] = _src[4] * m0 + _src[5] * m4 + _src[6] * m8 + _src[7] * m12;
+ mat4[8] = _src[8] * m0 + _src[9] * m4 + _src[10] * m8 + _src[11] * m12;
+ mat4[12] = _src[12] * m0 + _src[13] * m4 + _src[14] * m8 + _src[15] * m12;
+
+ var m1 = mat4[1];
+ var m5 = mat4[5];
+ var m9 = mat4[9];
+ var m13 = mat4[13];
+ mat4[1] = _src[0] * m1 + _src[1] * m5 + _src[2] * m9 + _src[3] * m13;
+ mat4[5] = _src[4] * m1 + _src[5] * m5 + _src[6] * m9 + _src[7] * m13;
+ mat4[9] = _src[8] * m1 + _src[9] * m5 + _src[10] * m9 + _src[11] * m13;
+ mat4[13] = _src[12] * m1 + _src[13] * m5 + _src[14] * m9 + _src[15] * m13;
+
+ var m2 = mat4[2];
+ var m6 = mat4[6];
+ var m10 = mat4[10];
+ var m14 = mat4[14];
+ mat4[2] = _src[0] * m2 + _src[1] * m6 + _src[2] * m10 + _src[3] * m14;
+ mat4[6] = _src[4] * m2 + _src[5] * m6 + _src[6] * m10 + _src[7] * m14;
+ mat4[10] = _src[8] * m2 + _src[9] * m6 + _src[10] * m10 + _src[11] * m14;
+ mat4[14] = _src[12] * m2 + _src[13] * m6 + _src[14] * m10 + _src[15] * m14;
+
+ var m3 = mat4[3];
+ var m7 = mat4[7];
+ var m11 = mat4[11];
+ var m15 = mat4[15];
+ mat4[3] = _src[0] * m3 + _src[1] * m7 + _src[2] * m11 + _src[3] * m15;
+ mat4[7] = _src[4] * m3 + _src[5] * m7 + _src[6] * m11 + _src[7] * m15;
+ mat4[11] = _src[8] * m3 + _src[9] * m7 + _src[10] * m11 + _src[11] * m15;
+ mat4[15] = _src[12] * m3 + _src[13] * m7 + _src[14] * m11 + _src[15] * m15;
+
+ return this;
+ };
+
+ /**
+ * scales a p5.Matrix by scalars or a vector
+ * @method scale
+ * @param {p5.Vector|Float32Array|Number[]} s vector to scale by
+ * @chainable
+ */
+ _main.default.Matrix.prototype.scale = function(x, y, z) {
+ if (x instanceof _main.default.Vector) {
+ // x is a vector, extract the components from it.
+ y = x.y;
+ z = x.z;
+ x = x.x; // must be last
+ } else if (x instanceof Array) {
+ // x is an array, extract the components from it.
+ y = x[1];
+ z = x[2];
+ x = x[0]; // must be last
+ }
+
+ this.mat4[0] *= x;
+ this.mat4[1] *= x;
+ this.mat4[2] *= x;
+ this.mat4[3] *= x;
+ this.mat4[4] *= y;
+ this.mat4[5] *= y;
+ this.mat4[6] *= y;
+ this.mat4[7] *= y;
+ this.mat4[8] *= z;
+ this.mat4[9] *= z;
+ this.mat4[10] *= z;
+ this.mat4[11] *= z;
+
+ return this;
+ };
+
+ /**
+ * rotate our Matrix around an axis by the given angle.
+ * @method rotate
+ * @param {Number} a The angle of rotation in radians
+ * @param {p5.Vector|Number[]} axis the axis(es) to rotate around
+ * @chainable
+ * inspired by Toji's gl-matrix lib, mat4 rotation
+ */
+ _main.default.Matrix.prototype.rotate = function(a, x, y, z) {
+ if (x instanceof _main.default.Vector) {
+ // x is a vector, extract the components from it.
+ y = x.y;
+ z = x.z;
+ x = x.x; //must be last
+ } else if (x instanceof Array) {
+ // x is an array, extract the components from it.
+ y = x[1];
+ z = x[2];
+ x = x[0]; //must be last
+ }
+
+ var len = Math.sqrt(x * x + y * y + z * z);
+ x *= 1 / len;
+ y *= 1 / len;
+ z *= 1 / len;
+
+ var a00 = this.mat4[0];
+ var a01 = this.mat4[1];
+ var a02 = this.mat4[2];
+ var a03 = this.mat4[3];
+ var a10 = this.mat4[4];
+ var a11 = this.mat4[5];
+ var a12 = this.mat4[6];
+ var a13 = this.mat4[7];
+ var a20 = this.mat4[8];
+ var a21 = this.mat4[9];
+ var a22 = this.mat4[10];
+ var a23 = this.mat4[11];
+
+ //sin,cos, and tan of respective angle
+ var sA = Math.sin(a);
+ var cA = Math.cos(a);
+ var tA = 1 - cA;
+ // Construct the elements of the rotation matrix
+ var b00 = x * x * tA + cA;
+ var b01 = y * x * tA + z * sA;
+ var b02 = z * x * tA - y * sA;
+ var b10 = x * y * tA - z * sA;
+ var b11 = y * y * tA + cA;
+ var b12 = z * y * tA + x * sA;
+ var b20 = x * z * tA + y * sA;
+ var b21 = y * z * tA - x * sA;
+ var b22 = z * z * tA + cA;
+
+ // rotation-specific matrix multiplication
+ this.mat4[0] = a00 * b00 + a10 * b01 + a20 * b02;
+ this.mat4[1] = a01 * b00 + a11 * b01 + a21 * b02;
+ this.mat4[2] = a02 * b00 + a12 * b01 + a22 * b02;
+ this.mat4[3] = a03 * b00 + a13 * b01 + a23 * b02;
+ this.mat4[4] = a00 * b10 + a10 * b11 + a20 * b12;
+ this.mat4[5] = a01 * b10 + a11 * b11 + a21 * b12;
+ this.mat4[6] = a02 * b10 + a12 * b11 + a22 * b12;
+ this.mat4[7] = a03 * b10 + a13 * b11 + a23 * b12;
+ this.mat4[8] = a00 * b20 + a10 * b21 + a20 * b22;
+ this.mat4[9] = a01 * b20 + a11 * b21 + a21 * b22;
+ this.mat4[10] = a02 * b20 + a12 * b21 + a22 * b22;
+ this.mat4[11] = a03 * b20 + a13 * b21 + a23 * b22;
+
+ return this;
+ };
+
+ /**
+ * @todo finish implementing this method!
+ * translates
+ * @method translate
+ * @param {Number[]} v vector to translate by
+ * @chainable
+ */
+ _main.default.Matrix.prototype.translate = function(v) {
+ var x = v[0],
+ y = v[1],
+ z = v[2] || 0;
+ this.mat4[12] += this.mat4[0] * x + this.mat4[4] * y + this.mat4[8] * z;
+ this.mat4[13] += this.mat4[1] * x + this.mat4[5] * y + this.mat4[9] * z;
+ this.mat4[14] += this.mat4[2] * x + this.mat4[6] * y + this.mat4[10] * z;
+ this.mat4[15] += this.mat4[3] * x + this.mat4[7] * y + this.mat4[11] * z;
+ };
+
+ _main.default.Matrix.prototype.rotateX = function(a) {
+ this.rotate(a, 1, 0, 0);
+ };
+ _main.default.Matrix.prototype.rotateY = function(a) {
+ this.rotate(a, 0, 1, 0);
+ };
+ _main.default.Matrix.prototype.rotateZ = function(a) {
+ this.rotate(a, 0, 0, 1);
+ };
+
+ /**
+ * sets the perspective matrix
+ * @method perspective
+ * @param {Number} fovy [description]
+ * @param {Number} aspect [description]
+ * @param {Number} near near clipping plane
+ * @param {Number} far far clipping plane
+ * @chainable
+ */
+ _main.default.Matrix.prototype.perspective = function(fovy, aspect, near, far) {
+ var f = 1.0 / Math.tan(fovy / 2),
+ nf = 1 / (near - far);
+
+ this.mat4[0] = f / aspect;
+ this.mat4[1] = 0;
+ this.mat4[2] = 0;
+ this.mat4[3] = 0;
+ this.mat4[4] = 0;
+ this.mat4[5] = f;
+ this.mat4[6] = 0;
+ this.mat4[7] = 0;
+ this.mat4[8] = 0;
+ this.mat4[9] = 0;
+ this.mat4[10] = (far + near) * nf;
+ this.mat4[11] = -1;
+ this.mat4[12] = 0;
+ this.mat4[13] = 0;
+ this.mat4[14] = 2 * far * near * nf;
+ this.mat4[15] = 0;
+
+ return this;
+ };
+
+ /**
+ * sets the ortho matrix
+ * @method ortho
+ * @param {Number} left [description]
+ * @param {Number} right [description]
+ * @param {Number} bottom [description]
+ * @param {Number} top [description]
+ * @param {Number} near near clipping plane
+ * @param {Number} far far clipping plane
+ * @chainable
+ */
+ _main.default.Matrix.prototype.ortho = function(
+ left,
+ right,
+ bottom,
+ top,
+ near,
+ far
+ ) {
+ var lr = 1 / (left - right),
+ bt = 1 / (bottom - top),
+ nf = 1 / (near - far);
+ this.mat4[0] = -2 * lr;
+ this.mat4[1] = 0;
+ this.mat4[2] = 0;
+ this.mat4[3] = 0;
+ this.mat4[4] = 0;
+ this.mat4[5] = -2 * bt;
+ this.mat4[6] = 0;
+ this.mat4[7] = 0;
+ this.mat4[8] = 0;
+ this.mat4[9] = 0;
+ this.mat4[10] = 2 * nf;
+ this.mat4[11] = 0;
+ this.mat4[12] = (left + right) * lr;
+ this.mat4[13] = (top + bottom) * bt;
+ this.mat4[14] = (far + near) * nf;
+ this.mat4[15] = 1;
+
+ return this;
+ };
+
+ /**
+ * PRIVATE
+ */
+ // matrix methods adapted from:
+ // https://developer.mozilla.org/en-US/docs/Web/WebGL/
+ // gluPerspective
+ //
+ // function _makePerspective(fovy, aspect, znear, zfar){
+ // const ymax = znear * Math.tan(fovy * Math.PI / 360.0);
+ // const ymin = -ymax;
+ // const xmin = ymin * aspect;
+ // const xmax = ymax * aspect;
+ // return _makeFrustum(xmin, xmax, ymin, ymax, znear, zfar);
+ // }
+
+ ////
+ //// glFrustum
+ ////
+ //function _makeFrustum(left, right, bottom, top, znear, zfar){
+ // const X = 2*znear/(right-left);
+ // const Y = 2*znear/(top-bottom);
+ // const A = (right+left)/(right-left);
+ // const B = (top+bottom)/(top-bottom);
+ // const C = -(zfar+znear)/(zfar-znear);
+ // const D = -2*zfar*znear/(zfar-znear);
+ // const frustrumMatrix =[
+ // X, 0, A, 0,
+ // 0, Y, B, 0,
+ // 0, 0, C, D,
+ // 0, 0, -1, 0
+ //];
+ //return frustrumMatrix;
+ // }
+
+ // function _setMVPMatrices(){
+ ////an identity matrix
+ ////@TODO use the p5.Matrix class to abstract away our MV matrices and
+ ///other math
+ //const _mvMatrix =
+ //[
+ // 1.0,0.0,0.0,0.0,
+ // 0.0,1.0,0.0,0.0,
+ // 0.0,0.0,1.0,0.0,
+ // 0.0,0.0,0.0,1.0
+ //];
+ var _default = _main.default.Matrix;
+ exports.default = _default;
+ },
+ {
+ '../core/main': 283,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.typed-array.copy-within': 212,
+ 'core-js/modules/es.typed-array.every': 213,
+ 'core-js/modules/es.typed-array.fill': 214,
+ 'core-js/modules/es.typed-array.filter': 215,
+ 'core-js/modules/es.typed-array.find': 217,
+ 'core-js/modules/es.typed-array.find-index': 216,
+ 'core-js/modules/es.typed-array.float32-array': 218,
+ 'core-js/modules/es.typed-array.for-each': 220,
+ 'core-js/modules/es.typed-array.includes': 221,
+ 'core-js/modules/es.typed-array.index-of': 222,
+ 'core-js/modules/es.typed-array.iterator': 225,
+ 'core-js/modules/es.typed-array.join': 226,
+ 'core-js/modules/es.typed-array.last-index-of': 227,
+ 'core-js/modules/es.typed-array.map': 228,
+ 'core-js/modules/es.typed-array.reduce': 230,
+ 'core-js/modules/es.typed-array.reduce-right': 229,
+ 'core-js/modules/es.typed-array.reverse': 231,
+ 'core-js/modules/es.typed-array.set': 232,
+ 'core-js/modules/es.typed-array.slice': 233,
+ 'core-js/modules/es.typed-array.some': 234,
+ 'core-js/modules/es.typed-array.sort': 235,
+ 'core-js/modules/es.typed-array.subarray': 236,
+ 'core-js/modules/es.typed-array.to-locale-string': 237,
+ 'core-js/modules/es.typed-array.to-string': 238
+ }
+ ],
+ 334: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ _dereq_('core-js/modules/es.array.map');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+
+ _main.default.RenderBuffer = function(size, src, dst, attr, renderer, map) {
+ this.size = size; // the number of FLOATs in each vertex
+ this.src = src; // the name of the model's source array
+ this.dst = dst; // the name of the geometry's buffer
+ this.attr = attr; // the name of the vertex attribute
+ this._renderer = renderer;
+ this.map = map; // optional, a transformation function to apply to src
+ };
+
+ /**
+ * Enables and binds the buffers used by shader when the appropriate data exists in geometry.
+ * Must always be done prior to drawing geometry in WebGL.
+ * @param {p5.Geometry} geometry Geometry that is going to be drawn
+ * @param {p5.Shader} shader Active shader
+ * @private
+ */
+ _main.default.RenderBuffer.prototype._prepareBuffer = function(geometry, shader) {
+ var attributes = shader.attributes;
+ var gl = this._renderer.GL;
+ var model;
+ if (geometry.model) {
+ model = geometry.model;
+ } else {
+ model = geometry;
+ }
+
+ // loop through each of the buffer definitions
+ var attr = attributes[this.attr];
+ if (!attr) {
+ return;
+ }
+
+ // check if the model has the appropriate source array
+ var buffer = geometry[this.dst];
+ var src = model[this.src];
+ if (src.length > 0) {
+ // check if we need to create the GL buffer
+ var createBuffer = !buffer;
+ if (createBuffer) {
+ // create and remember the buffer
+ geometry[this.dst] = buffer = gl.createBuffer();
+ }
+ // bind the buffer
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+
+ // check if we need to fill the buffer with data
+ if (createBuffer || model.dirtyFlags[this.src] !== false) {
+ var map = this.map;
+ // get the values from the model, possibly transformed
+ var values = map ? map(src) : src;
+ // fill the buffer with the values
+ this._renderer._bindBuffer(buffer, gl.ARRAY_BUFFER, values);
+
+ // mark the model's source array as clean
+ model.dirtyFlags[this.src] = false;
+ }
+ // enable the attribute
+ shader.enableAttrib(attr, this.size);
+ }
+ };
+ var _default = _main.default.RenderBuffer;
+ exports.default = _default;
+ },
+ { '../core/main': 283, 'core-js/modules/es.array.map': 177 }
+ ],
+ 335: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ function _typeof(obj) {
+ if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
+ _typeof = function _typeof(obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function _typeof(obj) {
+ return obj &&
+ typeof Symbol === 'function' &&
+ obj.constructor === Symbol &&
+ obj !== Symbol.prototype
+ ? 'symbol'
+ : typeof obj;
+ };
+ }
+ return _typeof(obj);
+ }
+ _dereq_('core-js/modules/es.symbol');
+ _dereq_('core-js/modules/es.symbol.description');
+ _dereq_('core-js/modules/es.symbol.iterator');
+ _dereq_('core-js/modules/es.array.fill');
+ _dereq_('core-js/modules/es.array.for-each');
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.string.iterator');
+ _dereq_('core-js/modules/es.typed-array.float32-array');
+ _dereq_('core-js/modules/es.typed-array.copy-within');
+ _dereq_('core-js/modules/es.typed-array.every');
+ _dereq_('core-js/modules/es.typed-array.fill');
+ _dereq_('core-js/modules/es.typed-array.filter');
+ _dereq_('core-js/modules/es.typed-array.find');
+ _dereq_('core-js/modules/es.typed-array.find-index');
+ _dereq_('core-js/modules/es.typed-array.for-each');
+ _dereq_('core-js/modules/es.typed-array.includes');
+ _dereq_('core-js/modules/es.typed-array.index-of');
+ _dereq_('core-js/modules/es.typed-array.iterator');
+ _dereq_('core-js/modules/es.typed-array.join');
+ _dereq_('core-js/modules/es.typed-array.last-index-of');
+ _dereq_('core-js/modules/es.typed-array.map');
+ _dereq_('core-js/modules/es.typed-array.reduce');
+ _dereq_('core-js/modules/es.typed-array.reduce-right');
+ _dereq_('core-js/modules/es.typed-array.reverse');
+ _dereq_('core-js/modules/es.typed-array.set');
+ _dereq_('core-js/modules/es.typed-array.slice');
+ _dereq_('core-js/modules/es.typed-array.some');
+ _dereq_('core-js/modules/es.typed-array.sort');
+ _dereq_('core-js/modules/es.typed-array.subarray');
+ _dereq_('core-js/modules/es.typed-array.to-locale-string');
+ _dereq_('core-js/modules/es.typed-array.to-string');
+ _dereq_('core-js/modules/web.dom-collections.for-each');
+ _dereq_('core-js/modules/web.dom-collections.iterator');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ var constants = _interopRequireWildcard(_dereq_('../core/constants'));
+ _dereq_('./p5.RenderBuffer');
+ function _getRequireWildcardCache() {
+ if (typeof WeakMap !== 'function') return null;
+ var cache = new WeakMap();
+ _getRequireWildcardCache = function _getRequireWildcardCache() {
+ return cache;
+ };
+ return cache;
+ }
+ function _interopRequireWildcard(obj) {
+ if (obj && obj.__esModule) {
+ return obj;
+ }
+ if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
+ return { default: obj };
+ }
+ var cache = _getRequireWildcardCache();
+ if (cache && cache.has(obj)) {
+ return cache.get(obj);
+ }
+ var newObj = {};
+ var hasPropertyDescriptor =
+ Object.defineProperty && Object.getOwnPropertyDescriptor;
+ for (var key in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
+ var desc = hasPropertyDescriptor
+ ? Object.getOwnPropertyDescriptor(obj, key)
+ : null;
+ if (desc && (desc.get || desc.set)) {
+ Object.defineProperty(newObj, key, desc);
+ } else {
+ newObj[key] = obj[key];
+ }
+ }
+ }
+ newObj.default = obj;
+ if (cache) {
+ cache.set(obj, newObj);
+ }
+ return newObj;
+ }
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+ /**
+ * Welcome to RendererGL Immediate Mode.
+ * Immediate mode is used for drawing custom shapes
+ * from a set of vertices. Immediate Mode is activated
+ * when you call beginShape() & de-activated when you call endShape().
+ * Immediate mode is a style of programming borrowed
+ * from OpenGL's (now-deprecated) immediate mode.
+ * It differs from p5.js' default, Retained Mode, which caches
+ * geometries and buffers on the CPU to reduce the number of webgl
+ * draw calls. Retained mode is more efficient & performative,
+ * however, Immediate Mode is useful for sketching quick
+ * geometric ideas.
+ */ /**
+ * Begin shape drawing. This is a helpful way of generating
+ * custom shapes quickly. However in WEBGL mode, application
+ * performance will likely drop as a result of too many calls to
+ * beginShape() / endShape(). As a high performance alternative,
+ * please use p5.js geometry primitives.
+ * @private
+ * @method beginShape
+ * @param {Number} mode webgl primitives mode. beginShape supports the
+ * following modes:
+ * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES,
+ * TRIANGLE_STRIP, TRIANGLE_FAN and TESS(WEBGL only)
+ * @chainable
+ */ _main.default.RendererGL.prototype.beginShape = function(mode) {
+ this.immediateMode.shapeMode =
+ mode !== undefined ? mode : constants.TRIANGLE_FAN;
+ this.immediateMode.geometry.reset();
+ return this;
+ };
+ /**
+ * adds a vertex to be drawn in a custom Shape.
+ * @private
+ * @method vertex
+ * @param {Number} x x-coordinate of vertex
+ * @param {Number} y y-coordinate of vertex
+ * @param {Number} z z-coordinate of vertex
+ * @chainable
+ * @TODO implement handling of p5.Vector args
+ */ _main.default.RendererGL.prototype.vertex = function(x, y) {
+ var z, u, v;
+
+ // default to (x, y) mode: all other arugments assumed to be 0.
+ z = u = v = 0;
+
+ if (arguments.length === 3) {
+ // (x, y, z) mode: (u, v) assumed to be 0.
+ z = arguments[2];
+ } else if (arguments.length === 4) {
+ // (x, y, u, v) mode: z assumed to be 0.
+ u = arguments[2];
+ v = arguments[3];
+ } else if (arguments.length === 5) {
+ // (x, y, z, u, v) mode
+ z = arguments[2];
+ u = arguments[3];
+ v = arguments[4];
+ }
+ var vert = new _main.default.Vector(x, y, z);
+ this.immediateMode.geometry.vertices.push(vert);
+ var vertexColor = this.curFillColor || [0.5, 0.5, 0.5, 1.0];
+ this.immediateMode.geometry.vertexColors.push(
+ vertexColor[0],
+ vertexColor[1],
+ vertexColor[2],
+ vertexColor[3]
+ );
+
+ if (this.textureMode === constants.IMAGE) {
+ if (this._tex !== null) {
+ if (this._tex.width > 0 && this._tex.height > 0) {
+ u /= this._tex.width;
+ v /= this._tex.height;
+ }
+ } else if (this._tex === null && arguments.length >= 4) {
+ // Only throw this warning if custom uv's have been provided
+ console.warn(
+ 'You must first call texture() before using' +
+ ' vertex() with image based u and v coordinates'
+ );
+ }
+ }
+
+ this.immediateMode.geometry.uvs.push(u, v);
+
+ this.immediateMode._bezierVertex[0] = x;
+ this.immediateMode._bezierVertex[1] = y;
+ this.immediateMode._bezierVertex[2] = z;
+
+ this.immediateMode._quadraticVertex[0] = x;
+ this.immediateMode._quadraticVertex[1] = y;
+ this.immediateMode._quadraticVertex[2] = z;
+
+ return this;
+ };
+
+ /**
+ * End shape drawing and render vertices to screen.
+ * @chainable
+ */
+ _main.default.RendererGL.prototype.endShape = function(
+ mode,
+ isCurve,
+ isBezier,
+ isQuadratic,
+ isContour,
+ shapeKind
+ ) {
+ if (this.immediateMode.shapeMode === constants.POINTS) {
+ this._drawPoints(
+ this.immediateMode.geometry.vertices,
+ this.immediateMode.buffers.point
+ );
+
+ return this;
+ }
+ this._processVertices.apply(this, arguments);
+ if (this._doFill) {
+ if (this.immediateMode.geometry.vertices.length > 1) {
+ this._drawImmediateFill();
+ }
+ }
+ if (this._doStroke) {
+ if (this.immediateMode.geometry.lineVertices.length > 1) {
+ this._drawImmediateStroke();
+ }
+ }
+
+ this.isBezier = false;
+ this.isQuadratic = false;
+ this.isCurve = false;
+ this.immediateMode._bezierVertex.length = 0;
+ this.immediateMode._quadraticVertex.length = 0;
+ this.immediateMode._curveVertex.length = 0;
+ return this;
+ };
+
+ /**
+ * Called from endShape(). This function calculates the stroke vertices for custom shapes and
+ * tesselates shapes when applicable.
+ * @private
+ * @param {Number} mode webgl primitives mode. beginShape supports the
+ * following modes:
+ * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES,
+ * TRIANGLE_STRIP, TRIANGLE_FAN and TESS(WEBGL only)
+ */
+ _main.default.RendererGL.prototype._processVertices = function(mode) {
+ if (this.immediateMode.geometry.vertices.length === 0) return;
+
+ var calculateStroke = this._doStroke && this.drawMode !== constants.TEXTURE;
+ var shouldClose = mode === constants.CLOSE;
+ if (calculateStroke) {
+ this.immediateMode.geometry.edges = this._calculateEdges(
+ this.immediateMode.shapeMode,
+ this.immediateMode.geometry.vertices,
+ shouldClose
+ );
+
+ this.immediateMode.geometry._edgesToVertices();
+ }
+ // For hollow shapes, user must set mode to TESS
+ var convexShape = this.immediateMode.shapeMode === constants.TESS;
+ // We tesselate when drawing curves or convex shapes
+ var shouldTess =
+ (this.isBezier || this.isQuadratic || this.isCurve || convexShape) &&
+ this.immediateMode.shapeMode !== constants.LINES;
+
+ if (shouldTess) {
+ this._tesselateShape();
+ }
+ };
+
+ /**
+ * Called from _processVertices(). This function calculates the stroke vertices for custom shapes and
+ * tesselates shapes when applicable.
+ * @private
+ * @returns {Array[Number]} indices for custom shape vertices indicating edges.
+ */
+ _main.default.RendererGL.prototype._calculateEdges = function(
+ shapeMode,
+ verts,
+ shouldClose
+ ) {
+ var res = [];
+ var i = 0;
+ switch (shapeMode) {
+ case constants.TRIANGLE_STRIP:
+ for (i = 0; i < verts.length - 2; i++) {
+ res.push([i, i + 1]);
+ res.push([i, i + 2]);
+ }
+ res.push([i, i + 1]);
+ break;
+ case constants.TRIANGLES:
+ for (i = 0; i < verts.length - 2; i = i + 3) {
+ res.push([i, i + 1]);
+ res.push([i + 1, i + 2]);
+ res.push([i + 2, i]);
+ }
+ break;
+ case constants.LINES:
+ for (i = 0; i < verts.length - 1; i = i + 2) {
+ res.push([i, i + 1]);
+ }
+ break;
+ default:
+ for (i = 0; i < verts.length - 1; i++) {
+ res.push([i, i + 1]);
+ }
+ break;
+ }
+
+ if (shouldClose) {
+ res.push([verts.length - 1, 0]);
+ }
+ return res;
+ };
+
+ /**
+ * Called from _processVertices() when applicable. This function tesselates immediateMode.geometry.
+ * @private
+ */
+ _main.default.RendererGL.prototype._tesselateShape = function() {
+ this.immediateMode.shapeMode = constants.TRIANGLES;
+ var contours = [
+ new Float32Array(this._vToNArray(this.immediateMode.geometry.vertices))
+ ];
+
+ var polyTriangles = this._triangulate(contours);
+ this.immediateMode.geometry.vertices = [];
+ for (
+ var j = 0, polyTriLength = polyTriangles.length;
+ j < polyTriLength;
+ j = j + 3
+ ) {
+ this.vertex(polyTriangles[j], polyTriangles[j + 1], polyTriangles[j + 2]);
+ }
+ };
+
+ /**
+ * Called from endShape(). Responsible for calculating normals, setting shader uniforms,
+ * enabling all appropriate buffers, applying color blend, and drawing the fill geometry.
+ * @private
+ */
+ _main.default.RendererGL.prototype._drawImmediateFill = function() {
+ var gl = this.GL;
+ var shader = this._getImmediateFillShader();
+
+ this._calculateNormals(this.immediateMode.geometry);
+ this._setFillUniforms(shader);
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+ try {
+ for (
+ var _iterator = this.immediateMode.buffers.fill[Symbol.iterator](), _step;
+ !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
+ _iteratorNormalCompletion = true
+ ) {
+ var buff = _step.value;
+ buff._prepareBuffer(this.immediateMode.geometry, shader);
+ }
+
+ // LINE_STRIP and LINES are not used for rendering, instead
+ // they only indicate a way to modify vertices during the _processVertices() step
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+ if (
+ this.immediateMode.shapeMode === constants.LINE_STRIP ||
+ this.immediateMode.shapeMode === constants.LINES
+ ) {
+ this.immediateMode.shapeMode = constants.TRIANGLE_FAN;
+ }
+
+ this._applyColorBlend(this.curFillColor);
+ gl.drawArrays(
+ this.immediateMode.shapeMode,
+ 0,
+ this.immediateMode.geometry.vertices.length
+ );
+
+ shader.unbindShader();
+ };
+
+ /**
+ * Called from endShape(). Responsible for calculating normals, setting shader uniforms,
+ * enabling all appropriate buffers, applying color blend, and drawing the stroke geometry.
+ * @private
+ */
+ _main.default.RendererGL.prototype._drawImmediateStroke = function() {
+ var gl = this.GL;
+ var shader = this._getImmediateStrokeShader();
+ this._setStrokeUniforms(shader);
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+ try {
+ for (
+ var _iterator2 = this.immediateMode.buffers.stroke[Symbol.iterator](),
+ _step2;
+ !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
+ _iteratorNormalCompletion2 = true
+ ) {
+ var buff = _step2.value;
+ buff._prepareBuffer(this.immediateMode.geometry, shader);
+ }
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+ this._applyColorBlend(this.curStrokeColor);
+ gl.drawArrays(gl.TRIANGLES, 0, this.immediateMode.geometry.lineVertices.length);
+
+ shader.unbindShader();
+ };
+
+ /**
+ * Called from _drawImmediateFill(). Currently adds default normals which
+ * only work for flat shapes.
+ * @parem
+ * @private
+ */
+ _main.default.RendererGL.prototype._calculateNormals = function(geometry) {
+ geometry.vertices.forEach(function() {
+ geometry.vertexNormals.push(new _main.default.Vector(0, 0, 1));
+ });
+ };
+ var _default = _main.default.RendererGL;
+ exports.default = _default;
+ },
+ {
+ '../core/constants': 272,
+ '../core/main': 283,
+ './p5.RenderBuffer': 334,
+ 'core-js/modules/es.array.fill': 168,
+ 'core-js/modules/es.array.for-each': 170,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.string.iterator': 201,
+ 'core-js/modules/es.symbol': 211,
+ 'core-js/modules/es.symbol.description': 209,
+ 'core-js/modules/es.symbol.iterator': 210,
+ 'core-js/modules/es.typed-array.copy-within': 212,
+ 'core-js/modules/es.typed-array.every': 213,
+ 'core-js/modules/es.typed-array.fill': 214,
+ 'core-js/modules/es.typed-array.filter': 215,
+ 'core-js/modules/es.typed-array.find': 217,
+ 'core-js/modules/es.typed-array.find-index': 216,
+ 'core-js/modules/es.typed-array.float32-array': 218,
+ 'core-js/modules/es.typed-array.for-each': 220,
+ 'core-js/modules/es.typed-array.includes': 221,
+ 'core-js/modules/es.typed-array.index-of': 222,
+ 'core-js/modules/es.typed-array.iterator': 225,
+ 'core-js/modules/es.typed-array.join': 226,
+ 'core-js/modules/es.typed-array.last-index-of': 227,
+ 'core-js/modules/es.typed-array.map': 228,
+ 'core-js/modules/es.typed-array.reduce': 230,
+ 'core-js/modules/es.typed-array.reduce-right': 229,
+ 'core-js/modules/es.typed-array.reverse': 231,
+ 'core-js/modules/es.typed-array.set': 232,
+ 'core-js/modules/es.typed-array.slice': 233,
+ 'core-js/modules/es.typed-array.some': 234,
+ 'core-js/modules/es.typed-array.sort': 235,
+ 'core-js/modules/es.typed-array.subarray': 236,
+ 'core-js/modules/es.typed-array.to-locale-string': 237,
+ 'core-js/modules/es.typed-array.to-string': 238,
+ 'core-js/modules/web.dom-collections.for-each': 243,
+ 'core-js/modules/web.dom-collections.iterator': 244
+ }
+ ],
+ 336: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ _dereq_('core-js/modules/es.symbol');
+ _dereq_('core-js/modules/es.symbol.description');
+ _dereq_('core-js/modules/es.symbol.iterator');
+ _dereq_('core-js/modules/es.array.fill');
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.object.keys');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.string.iterator');
+ _dereq_('core-js/modules/es.typed-array.float32-array');
+ _dereq_('core-js/modules/es.typed-array.uint16-array');
+ _dereq_('core-js/modules/es.typed-array.copy-within');
+ _dereq_('core-js/modules/es.typed-array.every');
+ _dereq_('core-js/modules/es.typed-array.fill');
+ _dereq_('core-js/modules/es.typed-array.filter');
+ _dereq_('core-js/modules/es.typed-array.find');
+ _dereq_('core-js/modules/es.typed-array.find-index');
+ _dereq_('core-js/modules/es.typed-array.for-each');
+ _dereq_('core-js/modules/es.typed-array.includes');
+ _dereq_('core-js/modules/es.typed-array.index-of');
+ _dereq_('core-js/modules/es.typed-array.iterator');
+ _dereq_('core-js/modules/es.typed-array.join');
+ _dereq_('core-js/modules/es.typed-array.last-index-of');
+ _dereq_('core-js/modules/es.typed-array.map');
+ _dereq_('core-js/modules/es.typed-array.reduce');
+ _dereq_('core-js/modules/es.typed-array.reduce-right');
+ _dereq_('core-js/modules/es.typed-array.reverse');
+ _dereq_('core-js/modules/es.typed-array.set');
+ _dereq_('core-js/modules/es.typed-array.slice');
+ _dereq_('core-js/modules/es.typed-array.some');
+ _dereq_('core-js/modules/es.typed-array.sort');
+ _dereq_('core-js/modules/es.typed-array.subarray');
+ _dereq_('core-js/modules/es.typed-array.to-locale-string');
+ _dereq_('core-js/modules/es.typed-array.to-string');
+ _dereq_('core-js/modules/web.dom-collections.iterator');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ _dereq_('./p5.RendererGL');
+ _dereq_('./p5.RenderBuffer');
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ } //Retained Mode. The default mode for rendering 3D primitives
+ //in WEBGL.
+ var hashCount = 0;
+ /**
+ * _initBufferDefaults
+ * @private
+ * @description initializes buffer defaults. runs each time a new geometry is
+ * registered
+ * @param {String} gId key of the geometry object
+ * @returns {Object} a new buffer object
+ */
+ _main.default.RendererGL.prototype._initBufferDefaults = function(gId) {
+ this._freeBuffers(gId);
+
+ //@TODO remove this limit on hashes in retainedMode.geometry
+ hashCount++;
+ if (hashCount > 1000) {
+ var key = Object.keys(this.retainedMode.geometry)[0];
+ delete this.retainedMode.geometry[key];
+ hashCount--;
+ }
+
+ //create a new entry in our retainedMode.geometry
+ return (this.retainedMode.geometry[gId] = {});
+ };
+
+ _main.default.RendererGL.prototype._freeBuffers = function(gId) {
+ var buffers = this.retainedMode.geometry[gId];
+ if (!buffers) {
+ return;
+ }
+
+ delete this.retainedMode.geometry[gId];
+ hashCount--;
+
+ var gl = this.GL;
+ if (buffers.indexBuffer) {
+ gl.deleteBuffer(buffers.indexBuffer);
+ }
+
+ function freeBuffers(defs) {
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+ try {
+ for (
+ var _iterator = defs[Symbol.iterator](), _step;
+ !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
+ _iteratorNormalCompletion = true
+ ) {
+ var def = _step.value;
+ if (buffers[def.dst]) {
+ gl.deleteBuffer(buffers[def.dst]);
+ buffers[def.dst] = null;
+ }
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+ }
+
+ // free all the buffers
+ freeBuffers(this.retainedMode.buffers.stroke);
+ freeBuffers(this.retainedMode.buffers.fill);
+ };
+
+ /**
+ * creates a buffers object that holds the WebGL render buffers
+ * for a geometry.
+ * @private
+ * @param {String} gId key of the geometry object
+ * @param {p5.Geometry} model contains geometry data
+ */
+ _main.default.RendererGL.prototype.createBuffers = function(gId, model) {
+ var gl = this.GL;
+ //initialize the gl buffers for our geom groups
+ var buffers = this._initBufferDefaults(gId);
+ buffers.model = model;
+
+ var indexBuffer = buffers.indexBuffer;
+
+ if (model.faces.length) {
+ // allocate space for faces
+ if (!indexBuffer) indexBuffer = buffers.indexBuffer = gl.createBuffer();
+ var vals = _main.default.RendererGL.prototype._flatten(model.faces);
+ this._bindBuffer(indexBuffer, gl.ELEMENT_ARRAY_BUFFER, vals, Uint16Array);
+
+ // the vertex count is based on the number of faces
+ buffers.vertexCount = model.faces.length * 3;
+ } else {
+ // the index buffer is unused, remove it
+ if (indexBuffer) {
+ gl.deleteBuffer(indexBuffer);
+ buffers.indexBuffer = null;
+ }
+ // the vertex count comes directly from the model
+ buffers.vertexCount = model.vertices ? model.vertices.length : 0;
+ }
+
+ buffers.lineVertexCount = model.lineVertices ? model.lineVertices.length : 0;
+
+ return buffers;
+ };
+
+ /**
+ * Draws buffers given a geometry key ID
+ * @private
+ * @param {String} gId ID in our geom hash
+ * @chainable
+ */
+ _main.default.RendererGL.prototype.drawBuffers = function(gId) {
+ var gl = this.GL;
+ var geometry = this.retainedMode.geometry[gId];
+
+ if (this._doStroke && geometry.lineVertexCount > 0) {
+ var strokeShader = this._getRetainedStrokeShader();
+ this._setStrokeUniforms(strokeShader);
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+ try {
+ for (
+ var _iterator2 = this.retainedMode.buffers.stroke[Symbol.iterator](),
+ _step2;
+ !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
+ _iteratorNormalCompletion2 = true
+ ) {
+ var buff = _step2.value;
+ buff._prepareBuffer(geometry, strokeShader);
+ }
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+ this._applyColorBlend(this.curStrokeColor);
+ this._drawArrays(gl.TRIANGLES, gId);
+ strokeShader.unbindShader();
+ }
+
+ if (this._doFill) {
+ var fillShader = this._getRetainedFillShader();
+ this._setFillUniforms(fillShader);
+ var _iteratorNormalCompletion3 = true;
+ var _didIteratorError3 = false;
+ var _iteratorError3 = undefined;
+ try {
+ for (
+ var _iterator3 = this.retainedMode.buffers.fill[Symbol.iterator](),
+ _step3;
+ !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
+ _iteratorNormalCompletion3 = true
+ ) {
+ var _buff = _step3.value;
+ _buff._prepareBuffer(geometry, fillShader);
+ }
+ } catch (err) {
+ _didIteratorError3 = true;
+ _iteratorError3 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
+ _iterator3.return();
+ }
+ } finally {
+ if (_didIteratorError3) {
+ throw _iteratorError3;
+ }
+ }
+ }
+ if (geometry.indexBuffer) {
+ //vertex index buffer
+ this._bindBuffer(geometry.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
+ }
+ this._applyColorBlend(this.curFillColor);
+ this._drawElements(gl.TRIANGLES, gId);
+ fillShader.unbindShader();
+ }
+ return this;
+ };
+
+ /**
+ * Calls drawBuffers() with a scaled model/view matrix.
+ *
+ * This is used by various 3d primitive methods (in primitives.js, eg. plane,
+ * box, torus, etc...) to allow caching of un-scaled geometries. Those
+ * geometries are generally created with unit-length dimensions, cached as
+ * such, and then scaled appropriately in this method prior to rendering.
+ *
+ * @private
+ * @method drawBuffersScaled
+ * @param {String} gId ID in our geom hash
+ * @param {Number} scaleX the amount to scale in the X direction
+ * @param {Number} scaleY the amount to scale in the Y direction
+ * @param {Number} scaleZ the amount to scale in the Z direction
+ */
+ _main.default.RendererGL.prototype.drawBuffersScaled = function(
+ gId,
+ scaleX,
+ scaleY,
+ scaleZ
+ ) {
+ var uMVMatrix = this.uMVMatrix.copy();
+ try {
+ this.uMVMatrix.scale(scaleX, scaleY, scaleZ);
+ this.drawBuffers(gId);
+ } finally {
+ this.uMVMatrix = uMVMatrix;
+ }
+ };
+
+ _main.default.RendererGL.prototype._drawArrays = function(drawMode, gId) {
+ this.GL.drawArrays(
+ drawMode,
+ 0,
+ this.retainedMode.geometry[gId].lineVertexCount
+ );
+
+ return this;
+ };
+
+ _main.default.RendererGL.prototype._drawElements = function(drawMode, gId) {
+ var buffers = this.retainedMode.geometry[gId];
+ var gl = this.GL;
+ // render the fill
+ if (buffers.indexBuffer) {
+ // we're drawing faces
+ gl.drawElements(gl.TRIANGLES, buffers.vertexCount, gl.UNSIGNED_SHORT, 0);
+ } else {
+ // drawing vertices
+ gl.drawArrays(drawMode || gl.TRIANGLES, 0, buffers.vertexCount);
+ }
+ };
+
+ _main.default.RendererGL.prototype._drawPoints = function(
+ vertices,
+ vertexBuffer
+ ) {
+ var gl = this.GL;
+ var pointShader = this._getImmediatePointShader();
+ this._setPointUniforms(pointShader);
+
+ this._bindBuffer(
+ vertexBuffer,
+ gl.ARRAY_BUFFER,
+ this._vToNArray(vertices),
+ Float32Array,
+ gl.STATIC_DRAW
+ );
+
+ pointShader.enableAttrib(pointShader.attributes.aPosition, 3);
+
+ gl.drawArrays(gl.Points, 0, vertices.length);
+
+ pointShader.unbindShader();
+ };
+ var _default = _main.default.RendererGL;
+ exports.default = _default;
+ },
+ {
+ '../core/main': 283,
+ './p5.RenderBuffer': 334,
+ './p5.RendererGL': 337,
+ 'core-js/modules/es.array.fill': 168,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.object.keys': 191,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.string.iterator': 201,
+ 'core-js/modules/es.symbol': 211,
+ 'core-js/modules/es.symbol.description': 209,
+ 'core-js/modules/es.symbol.iterator': 210,
+ 'core-js/modules/es.typed-array.copy-within': 212,
+ 'core-js/modules/es.typed-array.every': 213,
+ 'core-js/modules/es.typed-array.fill': 214,
+ 'core-js/modules/es.typed-array.filter': 215,
+ 'core-js/modules/es.typed-array.find': 217,
+ 'core-js/modules/es.typed-array.find-index': 216,
+ 'core-js/modules/es.typed-array.float32-array': 218,
+ 'core-js/modules/es.typed-array.for-each': 220,
+ 'core-js/modules/es.typed-array.includes': 221,
+ 'core-js/modules/es.typed-array.index-of': 222,
+ 'core-js/modules/es.typed-array.iterator': 225,
+ 'core-js/modules/es.typed-array.join': 226,
+ 'core-js/modules/es.typed-array.last-index-of': 227,
+ 'core-js/modules/es.typed-array.map': 228,
+ 'core-js/modules/es.typed-array.reduce': 230,
+ 'core-js/modules/es.typed-array.reduce-right': 229,
+ 'core-js/modules/es.typed-array.reverse': 231,
+ 'core-js/modules/es.typed-array.set': 232,
+ 'core-js/modules/es.typed-array.slice': 233,
+ 'core-js/modules/es.typed-array.some': 234,
+ 'core-js/modules/es.typed-array.sort': 235,
+ 'core-js/modules/es.typed-array.subarray': 236,
+ 'core-js/modules/es.typed-array.to-locale-string': 237,
+ 'core-js/modules/es.typed-array.to-string': 238,
+ 'core-js/modules/es.typed-array.uint16-array': 239,
+ 'core-js/modules/web.dom-collections.iterator': 244
+ }
+ ],
+ 337: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ function _typeof(obj) {
+ if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
+ _typeof = function _typeof(obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function _typeof(obj) {
+ return obj &&
+ typeof Symbol === 'function' &&
+ obj.constructor === Symbol &&
+ obj !== Symbol.prototype
+ ? 'symbol'
+ : typeof obj;
+ };
+ }
+ return _typeof(obj);
+ }
+ _dereq_('core-js/modules/es.symbol');
+ _dereq_('core-js/modules/es.symbol.description');
+ _dereq_('core-js/modules/es.symbol.iterator');
+ _dereq_('core-js/modules/es.array.concat');
+ _dereq_('core-js/modules/es.array.fill');
+ _dereq_('core-js/modules/es.array.filter');
+ _dereq_('core-js/modules/es.array.from');
+ _dereq_('core-js/modules/es.array.includes');
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.array.slice');
+ _dereq_('core-js/modules/es.object.assign');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.regexp.to-string');
+ _dereq_('core-js/modules/es.string.includes');
+ _dereq_('core-js/modules/es.string.iterator');
+ _dereq_('core-js/modules/es.typed-array.float32-array');
+ _dereq_('core-js/modules/es.typed-array.float64-array');
+ _dereq_('core-js/modules/es.typed-array.int16-array');
+ _dereq_('core-js/modules/es.typed-array.uint8-array');
+ _dereq_('core-js/modules/es.typed-array.uint16-array');
+ _dereq_('core-js/modules/es.typed-array.uint32-array');
+ _dereq_('core-js/modules/es.typed-array.copy-within');
+ _dereq_('core-js/modules/es.typed-array.every');
+ _dereq_('core-js/modules/es.typed-array.fill');
+ _dereq_('core-js/modules/es.typed-array.filter');
+ _dereq_('core-js/modules/es.typed-array.find');
+ _dereq_('core-js/modules/es.typed-array.find-index');
+ _dereq_('core-js/modules/es.typed-array.for-each');
+ _dereq_('core-js/modules/es.typed-array.includes');
+ _dereq_('core-js/modules/es.typed-array.index-of');
+ _dereq_('core-js/modules/es.typed-array.iterator');
+ _dereq_('core-js/modules/es.typed-array.join');
+ _dereq_('core-js/modules/es.typed-array.last-index-of');
+ _dereq_('core-js/modules/es.typed-array.map');
+ _dereq_('core-js/modules/es.typed-array.reduce');
+ _dereq_('core-js/modules/es.typed-array.reduce-right');
+ _dereq_('core-js/modules/es.typed-array.reverse');
+ _dereq_('core-js/modules/es.typed-array.set');
+ _dereq_('core-js/modules/es.typed-array.slice');
+ _dereq_('core-js/modules/es.typed-array.some');
+ _dereq_('core-js/modules/es.typed-array.sort');
+ _dereq_('core-js/modules/es.typed-array.subarray');
+ _dereq_('core-js/modules/es.typed-array.to-locale-string');
+ _dereq_('core-js/modules/es.typed-array.to-string');
+ _dereq_('core-js/modules/web.dom-collections.iterator');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ var constants = _interopRequireWildcard(_dereq_('../core/constants'));
+ var _libtess = _interopRequireDefault(_dereq_('libtess'));
+ _dereq_('./p5.Shader');
+ _dereq_('./p5.Camera');
+ _dereq_('../core/p5.Renderer');
+ _dereq_('./p5.Matrix');
+
+ var _path = _dereq_('path');
+ function _getRequireWildcardCache() {
+ if (typeof WeakMap !== 'function') return null;
+ var cache = new WeakMap();
+ _getRequireWildcardCache = function _getRequireWildcardCache() {
+ return cache;
+ };
+ return cache;
+ }
+ function _interopRequireWildcard(obj) {
+ if (obj && obj.__esModule) {
+ return obj;
+ }
+ if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
+ return { default: obj };
+ }
+ var cache = _getRequireWildcardCache();
+ if (cache && cache.has(obj)) {
+ return cache.get(obj);
+ }
+ var newObj = {};
+ var hasPropertyDescriptor =
+ Object.defineProperty && Object.getOwnPropertyDescriptor;
+ for (var key in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
+ var desc = hasPropertyDescriptor
+ ? Object.getOwnPropertyDescriptor(obj, key)
+ : null;
+ if (desc && (desc.get || desc.set)) {
+ Object.defineProperty(newObj, key, desc);
+ } else {
+ newObj[key] = obj[key];
+ }
+ }
+ }
+ newObj.default = obj;
+ if (cache) {
+ cache.set(obj, newObj);
+ }
+ return newObj;
+ }
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+ function _toConsumableArray(arr) {
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
+ }
+ function _nonIterableSpread() {
+ throw new TypeError('Invalid attempt to spread non-iterable instance');
+ }
+ function _iterableToArray(iter) {
+ if (
+ Symbol.iterator in Object(iter) ||
+ Object.prototype.toString.call(iter) === '[object Arguments]'
+ )
+ return Array.from(iter);
+ }
+ function _arrayWithoutHoles(arr) {
+ if (Array.isArray(arr)) {
+ for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
+ arr2[i] = arr[i];
+ }
+ return arr2;
+ }
+ }
+
+ var lightingShader =
+ 'precision highp float;\nprecision highp int;\n\nuniform mat4 uViewMatrix;\n\nuniform bool uUseLighting;\n\nuniform int uAmbientLightCount;\nuniform vec3 uAmbientColor[5];\n\nuniform int uDirectionalLightCount;\nuniform vec3 uLightingDirection[5];\nuniform vec3 uDirectionalDiffuseColors[5];\nuniform vec3 uDirectionalSpecularColors[5];\n\nuniform int uPointLightCount;\nuniform vec3 uPointLightLocation[5];\nuniform vec3 uPointLightDiffuseColors[5];\t\nuniform vec3 uPointLightSpecularColors[5];\n\nuniform int uSpotLightCount;\nuniform float uSpotLightAngle[5];\nuniform float uSpotLightConc[5];\nuniform vec3 uSpotLightDiffuseColors[5];\nuniform vec3 uSpotLightSpecularColors[5];\nuniform vec3 uSpotLightLocation[5];\nuniform vec3 uSpotLightDirection[5];\n\nuniform bool uSpecular;\nuniform float uShininess;\n\nuniform float uConstantAttenuation;\nuniform float uLinearAttenuation;\nuniform float uQuadraticAttenuation;\n\nconst float specularFactor = 2.0;\nconst float diffuseFactor = 0.73;\n\nstruct LightResult {\n float specular;\n float diffuse;\n};\n\nfloat _phongSpecular(\n vec3 lightDirection,\n vec3 viewDirection,\n vec3 surfaceNormal,\n float shininess) {\n\n vec3 R = reflect(lightDirection, surfaceNormal);\n return pow(max(0.0, dot(R, viewDirection)), shininess);\n}\n\nfloat _lambertDiffuse(vec3 lightDirection, vec3 surfaceNormal) {\n return max(0.0, dot(-lightDirection, surfaceNormal));\n}\n\nLightResult _light(vec3 viewDirection, vec3 normal, vec3 lightVector) {\n\n vec3 lightDir = normalize(lightVector);\n\n //compute our diffuse & specular terms\n LightResult lr;\n if (uSpecular)\n lr.specular = _phongSpecular(lightDir, viewDirection, normal, uShininess);\n lr.diffuse = _lambertDiffuse(lightDir, normal);\n return lr;\n}\n\nvoid totalLight(\n vec3 modelPosition,\n vec3 normal,\n out vec3 totalDiffuse,\n out vec3 totalSpecular\n) {\n\n totalSpecular = vec3(0.0);\n\n if (!uUseLighting) {\n totalDiffuse = vec3(1.0);\n return;\n }\n\n totalDiffuse = vec3(0.0);\n\n vec3 viewDirection = normalize(-modelPosition);\n\n for (int j = 0; j < 5; j++) {\n if (j < uDirectionalLightCount) {\n vec3 lightVector = (uViewMatrix * vec4(uLightingDirection[j], 0.0)).xyz;\n vec3 lightColor = uDirectionalDiffuseColors[j];\n vec3 specularColor = uDirectionalSpecularColors[j];\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if (j < uPointLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uPointLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n //calculate attenuation\n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n vec3 lightColor = lightFalloff * uPointLightDiffuseColors[j];\n vec3 specularColor = lightFalloff * uPointLightSpecularColors[j];\n\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if(j < uSpotLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uSpotLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n\n vec3 lightDirection = (uViewMatrix * vec4(uSpotLightDirection[j], 0.0)).xyz;\n float spotDot = dot(normalize(lightVector), normalize(lightDirection));\n float spotFalloff;\n if(spotDot < uSpotLightAngle[j]) {\n spotFalloff = 0.0;\n }\n else {\n spotFalloff = pow(spotDot, uSpotLightConc[j]);\n }\n lightFalloff *= spotFalloff;\n\n vec3 lightColor = uSpotLightDiffuseColors[j];\n vec3 specularColor = uSpotLightSpecularColors[j];\n \n LightResult result = _light(viewDirection, normal, lightVector);\n \n totalDiffuse += result.diffuse * lightColor * lightFalloff;\n totalSpecular += result.specular * lightColor * specularColor * lightFalloff;\n }\n }\n\n totalDiffuse *= diffuseFactor;\n totalSpecular *= specularFactor;\n}\n';
+
+ var defaultShaders = {
+ immediateVert:
+ 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uResolution;\nuniform float uPointSize;\n\nvarying vec4 vColor;\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n gl_PointSize = uPointSize;\n}\n',
+
+ vertexColorVert:
+ 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvarying vec4 vColor;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n}\n',
+
+ vertexColorFrag:
+ 'precision mediump float;\nvarying vec4 vColor;\nvoid main(void) {\n gl_FragColor = vColor;\n}',
+
+ normalVert:
+ 'attribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvarying vec3 vVertexNormal;\nvarying highp vec2 vVertTexCoord;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vVertexNormal = normalize(vec3( uNormalMatrix * aNormal ));\n vVertTexCoord = aTexCoord;\n}\n',
+ normalFrag:
+ 'precision mediump float;\nvarying vec3 vVertexNormal;\nvoid main(void) {\n gl_FragColor = vec4(vVertexNormal, 1.0);\n}',
+ basicFrag:
+ 'precision mediump float;\nuniform vec4 uMaterialColor;\nvoid main(void) {\n gl_FragColor = uMaterialColor;\n}',
+ lightVert:
+ lightingShader +
+ '// include lighting.glgl\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * viewModelPosition;\n\n vec3 vertexNormal = normalize(uNormalMatrix * aNormal);\n vVertTexCoord = aTexCoord;\n\n totalLight(viewModelPosition.xyz, vertexNormal, vDiffuseColor, vSpecularColor);\n\n for (int i = 0; i < 8; i++) {\n if (i < uAmbientLightCount) {\n vDiffuseColor += uAmbientColor[i];\n }\n }\n}\n',
+
+ lightTextureFrag:
+ 'precision highp float;\n\nuniform vec4 uMaterialColor;\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\nuniform bool uEmissive;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\n\nvoid main(void) {\n if(uEmissive && !isTexture) {\n gl_FragColor = uMaterialColor;\n }\n else {\n gl_FragColor = isTexture ? texture2D(uSampler, vVertTexCoord) * (uTint / vec4(255, 255, 255, 255)) : uMaterialColor;\n gl_FragColor.rgb = gl_FragColor.rgb * vDiffuseColor + vSpecularColor;\n }\n}',
+
+ phongVert:
+ 'precision highp float;\nprecision highp int;\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform vec3 uAmbientColor[5];\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\nuniform int uAmbientLightCount;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n\n // Pass varyings to fragment shader\n vViewPosition = viewModelPosition.xyz;\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n vNormal = uNormalMatrix * aNormal;\n vTexCoord = aTexCoord;\n\n // TODO: this should be a uniform\n vAmbientColor = vec3(0.0);\n for (int i = 0; i < 5; i++) {\n if (i < uAmbientLightCount) {\n vAmbientColor += uAmbientColor[i];\n }\n }\n}\n',
+ phongFrag:
+ lightingShader +
+ '// include lighting.glsl\nprecision highp float;\nprecision highp int;\n\nuniform vec4 uMaterialColor;\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\nuniform bool uEmissive;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\n\nvoid main(void) {\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, normalize(vNormal), diffuse, specular);\n\n if(uEmissive && !isTexture) {\n gl_FragColor = uMaterialColor;\n }\n else {\n gl_FragColor = isTexture ? texture2D(uSampler, vTexCoord) * (uTint / vec4(255, 255, 255, 255)) : uMaterialColor;\n gl_FragColor.rgb = gl_FragColor.rgb * (diffuse + vAmbientColor) + specular;\n }\n}',
+
+ fontVert:
+ "precision mediump float;\n\nattribute vec3 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uGlyphRect;\nuniform float uGlyphOffset;\n\nvarying vec2 vTexCoord;\nvarying float w;\n\nvoid main() {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // scale by the size of the glyph's rectangle\n positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;\n\n // move to the corner of the glyph\n positionVec4.xy += uGlyphRect.xy;\n\n // move to the letter's line offset\n positionVec4.x += uGlyphOffset;\n \n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vTexCoord = aTexCoord;\n w = gl_Position.w;\n}\n",
+ fontFrag:
+ "#extension GL_OES_standard_derivatives : enable\nprecision mediump float;\n\n#if 0\n // simulate integer math using floats\n\t#define int float\n\t#define ivec2 vec2\n\t#define INT(x) float(x)\n\n\tint ifloor(float v) { return floor(v); }\n\tivec2 ifloor(vec2 v) { return floor(v); }\n\n#else\n // use native integer math\n\tprecision highp int;\n\t#define INT(x) x\n\n\tint ifloor(float v) { return int(v); }\n\tint ifloor(int v) { return v; }\n\tivec2 ifloor(vec2 v) { return ivec2(v); }\n\n#endif\n\nuniform sampler2D uSamplerStrokes;\nuniform sampler2D uSamplerRowStrokes;\nuniform sampler2D uSamplerRows;\nuniform sampler2D uSamplerColStrokes;\nuniform sampler2D uSamplerCols;\n\nuniform ivec2 uStrokeImageSize;\nuniform ivec2 uCellsImageSize;\nuniform ivec2 uGridImageSize;\n\nuniform ivec2 uGridOffset;\nuniform ivec2 uGridSize;\nuniform vec4 uMaterialColor;\n\nvarying vec2 vTexCoord;\n\n// some helper functions\nint round(float v) { return ifloor(v + 0.5); }\nivec2 round(vec2 v) { return ifloor(v + 0.5); }\nfloat saturate(float v) { return clamp(v, 0.0, 1.0); }\nvec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }\n\nint mul(float v1, int v2) {\n return ifloor(v1 * float(v2));\n}\n\nivec2 mul(vec2 v1, ivec2 v2) {\n return ifloor(v1 * vec2(v2) + 0.5);\n}\n\n// unpack a 16-bit integer from a float vec2\nint getInt16(vec2 v) {\n ivec2 iv = round(v * 255.0);\n return iv.x * INT(128) + iv.y;\n}\n\nvec2 pixelScale;\nvec2 coverage = vec2(0.0);\nvec2 weight = vec2(0.5);\nconst float minDistance = 1.0/8192.0;\nconst float hardness = 1.05; // amount of antialias\n\n// the maximum number of curves in a glyph\nconst int N = INT(250);\n\n// retrieves an indexed pixel from a sampler\nvec4 getTexel(sampler2D sampler, int pos, ivec2 size) {\n int width = size.x;\n int y = ifloor(pos / width);\n int x = pos - y * width; // pos % width\n\n return texture2D(sampler, (vec2(x, y) + 0.5) / vec2(size));\n}\n\nvoid calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {\n\n // get the coefficients of the quadratic in t\n vec2 a = p0 - p1 * 2.0 + p2;\n vec2 b = p0 - p1;\n vec2 c = p0 - vTexCoord;\n\n // found out which values of 't' it crosses the axes\n vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));\n vec2 t1 = ((b - surd) / a).yx;\n vec2 t2 = ((b + surd) / a).yx;\n\n // approximate straight lines to avoid rounding errors\n if (abs(a.y) < 0.001)\n t1.x = t2.x = c.y / (2.0 * b.y);\n\n if (abs(a.x) < 0.001)\n t1.y = t2.y = c.x / (2.0 * b.x);\n\n // plug into quadratic formula to find the corrdinates of the crossings\n C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;\n C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;\n}\n\nvoid coverageX(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n // determine on which side of the x-axis the points lie\n bool y0 = p0.y > vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n gl_FragColor = uMaterialColor;\n gl_FragColor.a *= saturate(max(antialias, cover));\n}",
+ lineVert:
+ "/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library; if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform vec4 uViewport;\nuniform int uPerspective;\n\nattribute vec4 aPosition;\nattribute vec4 aDirection;\n \nvoid main() {\n // using a scale <1 moves the lines towards the camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n vec3 scale = vec3(0.9995);\n\n vec4 posp = uModelViewMatrix * aPosition;\n vec4 posq = uModelViewMatrix * (aPosition + vec4(aDirection.xyz, 0));\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n posp.xyz = posp.xyz * scale;\n posq.xyz = posq.xyz * scale;\n\n vec4 p = uProjectionMatrix * posp;\n vec4 q = uProjectionMatrix * posq;\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don't care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can't remove because it has different components for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangent = normalize((q.xy*p.w - p.xy*q.w) * uViewport.zw);\n\n // flip tangent to normal (it's already normalized)\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float thickness = aDirection.w * uStrokeWeight;\n vec2 offset = normal * thickness / 2.0;\n\n vec2 curPerspScale;\n\n if(uPerspective == 1) {\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n // invert Y, projections in Processing invert Y\n curPerspScale = (uProjectionMatrix * vec4(1, -1, 0, 0)).xy;\n } else {\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n curPerspScale = p.w / (0.5 * uViewport.zw);\n }\n\n gl_Position.xy = p.xy + offset.xy * curPerspScale;\n gl_Position.zw = p.zw;\n}\n",
+ lineFrag:
+ 'precision mediump float;\nprecision mediump int;\n\nuniform vec4 uMaterialColor;\n\nvoid main() {\n gl_FragColor = uMaterialColor;\n}',
+ pointVert:
+ 'attribute vec3 aPosition;\nuniform float uPointSize;\nvarying float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nvoid main() {\n\tvec4 positionVec4 = vec4(aPosition, 1.0);\n\tgl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n\tgl_PointSize = uPointSize;\n\tvStrokeWeight = uPointSize;\n}',
+ pointFrag:
+ 'precision mediump float;\nprecision mediump int;\nuniform vec4 uMaterialColor;\nvarying float vStrokeWeight;\n\nvoid main(){\n\tfloat mask = 0.0;\n\n\t// make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n\tmask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n\t// if strokeWeight is 1 or less lets just draw a square\n\t// this prevents weird artifacting from carving circles when our points are really small\n\t// if strokeWeight is larger than 1, we just use it as is\n\n\tmask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n\t// throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n\tif(mask > 0.98){\n discard;\n \t}\n\n \tgl_FragColor = vec4(uMaterialColor.rgb * (1.0 - mask), uMaterialColor.a) ;\n}'
+ };
+
+ /**
+ * 3D graphics class
+ * @private
+ * @class p5.RendererGL
+ * @constructor
+ * @extends p5.Renderer
+ * @todo extend class to include public method for offscreen
+ * rendering (FBO).
+ */
+ _main.default.RendererGL = function(elt, pInst, isMainCanvas, attr) {
+ _main.default.Renderer.call(this, elt, pInst, isMainCanvas);
+ this._setAttributeDefaults(pInst);
+ this._initContext();
+ this.isP3D = true; //lets us know we're in 3d mode
+
+ // This redundant property is useful in reminding you that you are
+ // interacting with WebGLRenderingContext, still worth considering future removal
+ this.GL = this.drawingContext;
+ this._pInst._setProperty('drawingContext', this.drawingContext);
+
+ // erasing
+ this._isErasing = false;
+
+ // lights
+ this._enableLighting = false;
+
+ this.ambientLightColors = [];
+ this.specularColors = [1, 1, 1];
+
+ this.directionalLightDirections = [];
+ this.directionalLightDiffuseColors = [];
+ this.directionalLightSpecularColors = [];
+
+ this.pointLightPositions = [];
+ this.pointLightDiffuseColors = [];
+ this.pointLightSpecularColors = [];
+
+ this.spotLightPositions = [];
+ this.spotLightDirections = [];
+ this.spotLightDiffuseColors = [];
+ this.spotLightSpecularColors = [];
+ this.spotLightAngle = [];
+ this.spotLightConc = [];
+
+ this.drawMode = constants.FILL;
+
+ this.curFillColor = this._cachedFillStyle = [1, 1, 1, 1];
+ this.curStrokeColor = this._cachedStrokeStyle = [0, 0, 0, 1];
+
+ this.curBlendMode = constants.BLEND;
+ this._cachedBlendMode = undefined;
+ this.blendExt = this.GL.getExtension('EXT_blend_minmax');
+ this._isBlending = false;
+
+ this._useSpecularMaterial = false;
+ this._useEmissiveMaterial = false;
+ this._useNormalMaterial = false;
+ this._useShininess = 1;
+
+ this._tint = [255, 255, 255, 255];
+
+ // lightFalloff variables
+ this.constantAttenuation = 1;
+ this.linearAttenuation = 0;
+ this.quadraticAttenuation = 0;
+
+ /**
+ * model view, projection, & normal
+ * matrices
+ */
+ this.uMVMatrix = new _main.default.Matrix();
+ this.uPMatrix = new _main.default.Matrix();
+ this.uNMatrix = new _main.default.Matrix('mat3');
+
+ // Camera
+ this._curCamera = new _main.default.Camera(this);
+ this._curCamera._computeCameraDefaultSettings();
+ this._curCamera._setDefaultCamera();
+
+ this._defaultLightShader = undefined;
+ this._defaultImmediateModeShader = undefined;
+ this._defaultNormalShader = undefined;
+ this._defaultColorShader = undefined;
+ this._defaultPointShader = undefined;
+
+ this.userFillShader = undefined;
+ this.userStrokeShader = undefined;
+ this.userPointShader = undefined;
+
+ // Default drawing is done in Retained Mode
+ // Geometry and Material hashes stored here
+ this.retainedMode = {
+ geometry: {},
+ buffers: {
+ // prettier-ignore
+ stroke: [
+ new _main.default.RenderBuffer(3, 'lineVertices', 'lineVertexBuffer', 'aPosition', this, this._flatten),
+ new _main.default.RenderBuffer(4, 'lineNormals', 'lineNormalBuffer', 'aDirection', this, this._flatten)],
+
+ // prettier-ignore
+ fill: [
+ new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray),
+ new _main.default.RenderBuffer(3, 'vertexNormals', 'normalBuffer', 'aNormal', this, this._vToNArray),
+ new _main.default.RenderBuffer(4, 'vertexColors', 'colorBuffer', 'aMaterialColor', this),
+ new _main.default.RenderBuffer(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor', this),
+ //new BufferDef(3, 'vertexSpeculars', 'specularBuffer', 'aSpecularColor'),
+ new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten)],
+
+ // prettier-ignore
+ text: [
+ new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray),
+ new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten)]
+ }
+ };
+
+ // Immediate Mode
+ // Geometry and Material hashes stored here
+ this.immediateMode = {
+ geometry: new _main.default.Geometry(),
+ shapeMode: constants.TRIANGLE_FAN,
+ _bezierVertex: [],
+ _quadraticVertex: [],
+ _curveVertex: [],
+ buffers: {
+ // prettier-ignore
+ fill: [
+ new _main.default.RenderBuffer(3, 'vertices', 'vertexBuffer', 'aPosition', this, this._vToNArray),
+ new _main.default.RenderBuffer(3, 'vertexNormals', 'normalBuffer', 'aNormal', this, this._vToNArray),
+ new _main.default.RenderBuffer(4, 'vertexColors', 'colorBuffer', 'aVertexColor', this),
+ new _main.default.RenderBuffer(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor', this),
+ new _main.default.RenderBuffer(2, 'uvs', 'uvBuffer', 'aTexCoord', this, this._flatten)],
+
+ // prettier-ignore
+ stroke: [
+ new _main.default.RenderBuffer(3, 'lineVertices', 'lineVertexBuffer', 'aPosition', this, this._flatten),
+ new _main.default.RenderBuffer(4, 'lineNormals', 'lineNormalBuffer', 'aDirection', this, this._flatten)],
+
+ point: this.GL.createBuffer()
+ }
+ };
+
+ this.pointSize = 5.0; //default point size
+ this.curStrokeWeight = 1;
+
+ // array of textures created in this gl context via this.getTexture(src)
+ this.textures = [];
+
+ this.textureMode = constants.IMAGE;
+ // default wrap settings
+ this.textureWrapX = constants.CLAMP;
+ this.textureWrapY = constants.CLAMP;
+ this._tex = null;
+ this._curveTightness = 6;
+
+ // lookUpTable for coefficients needed to be calculated for bezierVertex, same are used for curveVertex
+ this._lookUpTableBezier = [];
+ // lookUpTable for coefficients needed to be calculated for quadraticVertex
+ this._lookUpTableQuadratic = [];
+
+ // current curveDetail in the Bezier lookUpTable
+ this._lutBezierDetail = 0;
+ // current curveDetail in the Quadratic lookUpTable
+ this._lutQuadraticDetail = 0;
+
+ this._tessy = this._initTessy();
+
+ this.fontInfos = {};
+
+ this._curShader = undefined;
+
+ return this;
+ };
+
+ _main.default.RendererGL.prototype = Object.create(
+ _main.default.Renderer.prototype
+ );
+
+ //////////////////////////////////////////////
+ // Setting
+ //////////////////////////////////////////////
+
+ _main.default.RendererGL.prototype._setAttributeDefaults = function(pInst) {
+ // See issue #3850, safer to enable AA in Safari
+ var applyAA = navigator.userAgent.toLowerCase().includes('safari');
+ var defaults = {
+ alpha: true,
+ depth: true,
+ stencil: true,
+ antialias: applyAA,
+ premultipliedAlpha: false,
+ preserveDrawingBuffer: true,
+ perPixelLighting: true
+ };
+
+ if (pInst._glAttributes === null) {
+ pInst._glAttributes = defaults;
+ } else {
+ pInst._glAttributes = Object.assign(defaults, pInst._glAttributes);
+ }
+ return;
+ };
+
+ _main.default.RendererGL.prototype._initContext = function() {
+ try {
+ this.drawingContext =
+ this.canvas.getContext('webgl', this._pInst._glAttributes) ||
+ this.canvas.getContext('experimental-webgl', this._pInst._glAttributes);
+ if (this.drawingContext === null) {
+ throw new Error('Error creating webgl context');
+ } else {
+ var gl = this.drawingContext;
+ gl.enable(gl.DEPTH_TEST);
+ gl.depthFunc(gl.LEQUAL);
+ gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ this._viewport = this.drawingContext.getParameter(
+ this.drawingContext.VIEWPORT
+ );
+ }
+ } catch (er) {
+ throw er;
+ }
+ };
+
+ //This is helper function to reset the context anytime the attributes
+ //are changed with setAttributes()
+
+ _main.default.RendererGL.prototype._resetContext = function(options, callback) {
+ var w = this.width;
+ var h = this.height;
+ var defaultId = this.canvas.id;
+ var isPGraphics = this._pInst instanceof _main.default.Graphics;
+
+ if (isPGraphics) {
+ var pg = this._pInst;
+ pg.canvas.parentNode.removeChild(pg.canvas);
+ pg.canvas = document.createElement('canvas');
+ var node = pg._pInst._userNode || document.body;
+ node.appendChild(pg.canvas);
+ _main.default.Element.call(pg, pg.canvas, pg._pInst);
+ pg.width = w;
+ pg.height = h;
+ } else {
+ var c = this.canvas;
+ if (c) {
+ c.parentNode.removeChild(c);
+ }
+ c = document.createElement('canvas');
+ c.id = defaultId;
+ if (this._pInst._userNode) {
+ this._pInst._userNode.appendChild(c);
+ } else {
+ document.body.appendChild(c);
+ }
+ this._pInst.canvas = c;
+ }
+
+ var renderer = new _main.default.RendererGL(
+ this._pInst.canvas,
+ this._pInst,
+ !isPGraphics
+ );
+
+ this._pInst._setProperty('_renderer', renderer);
+ renderer.resize(w, h);
+ renderer._applyDefaults();
+
+ if (!isPGraphics) {
+ this._pInst._elements.push(renderer);
+ }
+
+ if (typeof callback === 'function') {
+ //setTimeout with 0 forces the task to the back of the queue, this ensures that
+ //we finish switching out the renderer
+ setTimeout(function() {
+ callback.apply(window._renderer, options);
+ }, 0);
+ }
+ };
+ /**
+ * @module Rendering
+ * @submodule Rendering
+ * @for p5
+ */
+ /**
+ * Set attributes for the WebGL Drawing context.
+ * This is a way of adjusting how the WebGL
+ * renderer works to fine-tune the display and performance.
+ *
+ * Note that this will reinitialize the drawing context
+ * if called after the WebGL canvas is made.
+ *
+ * If an object is passed as the parameter, all attributes
+ * not declared in the object will be set to defaults.
+ *
+ * The available attributes are:
+ *
+ * alpha - indicates if the canvas contains an alpha buffer
+ * default is true
+ *
+ * depth - indicates whether the drawing buffer has a depth buffer
+ * of at least 16 bits - default is true
+ *
+ * stencil - indicates whether the drawing buffer has a stencil buffer
+ * of at least 8 bits
+ *
+ * antialias - indicates whether or not to perform anti-aliasing
+ * default is false (true in Safari)
+ *
+ * premultipliedAlpha - indicates that the page compositor will assume
+ * the drawing buffer contains colors with pre-multiplied alpha
+ * default is false
+ *
+ * preserveDrawingBuffer - if true the buffers will not be cleared and
+ * and will preserve their values until cleared or overwritten by author
+ * (note that p5 clears automatically on draw loop)
+ * default is true
+ *
+ * perPixelLighting - if true, per-pixel lighting will be used in the
+ * lighting shader otherwise per-vertex lighting is used.
+ * default is true.
+ *
+ * @method setAttributes
+ * @for p5
+ * @param {String} key Name of attribute
+ * @param {Boolean} value New value of named attribute
+ * @example
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * push();
+ * rotateZ(frameCount * 0.02);
+ * rotateX(frameCount * 0.02);
+ * rotateY(frameCount * 0.02);
+ * fill(0, 0, 0);
+ * box(50);
+ * pop();
+ * }
+ *
+ *
+ *
+ * Now with the antialias attribute set to true.
+ *
+ *
+ *
+ * function setup() {
+ * setAttributes('antialias', true);
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * push();
+ * rotateZ(frameCount * 0.02);
+ * rotateX(frameCount * 0.02);
+ * rotateY(frameCount * 0.02);
+ * fill(0, 0, 0);
+ * box(50);
+ * pop();
+ * }
+ *
+ *
+ *
+ *
+ *
+ * // press the mouse button to disable perPixelLighting
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * noStroke();
+ * fill(255);
+ * }
+ *
+ * let lights = [
+ * { c: '#f00', t: 1.12, p: 1.91, r: 0.2 },
+ * { c: '#0f0', t: 1.21, p: 1.31, r: 0.2 },
+ * { c: '#00f', t: 1.37, p: 1.57, r: 0.2 },
+ * { c: '#ff0', t: 1.12, p: 1.91, r: 0.7 },
+ * { c: '#0ff', t: 1.21, p: 1.31, r: 0.7 },
+ * { c: '#f0f', t: 1.37, p: 1.57, r: 0.7 }
+ * ];
+ *
+ * function draw() {
+ * let t = millis() / 1000 + 1000;
+ * background(0);
+ * directionalLight(color('#222'), 1, 1, 1);
+ *
+ * for (let i = 0; i < lights.length; i++) {
+ * let light = lights[i];
+ * pointLight(
+ * color(light.c),
+ * p5.Vector.fromAngles(t * light.t, t * light.p, width * light.r)
+ * );
+ * }
+ *
+ * specularMaterial(255);
+ * sphere(width * 0.1);
+ *
+ * rotateX(t * 0.77);
+ * rotateY(t * 0.83);
+ * rotateZ(t * 0.91);
+ * torus(width * 0.3, width * 0.07, 24, 10);
+ * }
+ *
+ * function mousePressed() {
+ * setAttributes('perPixelLighting', false);
+ * noStroke();
+ * fill(255);
+ * }
+ * function mouseReleased() {
+ * setAttributes('perPixelLighting', true);
+ * noStroke();
+ * fill(255);
+ * }
+ *
+ *
+ *
+ * @alt a rotating cube with smoother edges
+ */
+ /**
+ * @method setAttributes
+ * @for p5
+ * @param {Object} obj object with key-value pairs
+ */
+
+ _main.default.prototype.setAttributes = function(key, value) {
+ if (typeof this._glAttributes === 'undefined') {
+ console.log(
+ 'You are trying to use setAttributes on a p5.Graphics object ' +
+ 'that does not use a WEBGL renderer.'
+ );
+
+ return;
+ }
+ var unchanged = true;
+ if (typeof value !== 'undefined') {
+ //first time modifying the attributes
+ if (this._glAttributes === null) {
+ this._glAttributes = {};
+ }
+ if (this._glAttributes[key] !== value) {
+ //changing value of previously altered attribute
+ this._glAttributes[key] = value;
+ unchanged = false;
+ }
+ //setting all attributes with some change
+ } else if (key instanceof Object) {
+ if (this._glAttributes !== key) {
+ this._glAttributes = key;
+ unchanged = false;
+ }
+ }
+ //@todo_FES
+ if (!this._renderer.isP3D || unchanged) {
+ return;
+ }
+
+ if (!this._setupDone) {
+ for (var x in this._renderer.retainedMode.geometry) {
+ if (this._renderer.retainedMode.geometry.hasOwnProperty(x)) {
+ console.error(
+ 'Sorry, Could not set the attributes, you need to call setAttributes() ' +
+ 'before calling the other drawing methods in setup()'
+ );
+
+ return;
+ }
+ }
+ }
+
+ this.push();
+ this._renderer._resetContext();
+ this.pop();
+
+ if (this._renderer._curCamera) {
+ this._renderer._curCamera._renderer = this._renderer;
+ }
+ };
+
+ /**
+ * @class p5.RendererGL
+ */
+
+ _main.default.RendererGL.prototype._update = function() {
+ // reset model view and apply initial camera transform
+ // (containing only look at info; no projection).
+ this.uMVMatrix.set(
+ this._curCamera.cameraMatrix.mat4[0],
+ this._curCamera.cameraMatrix.mat4[1],
+ this._curCamera.cameraMatrix.mat4[2],
+ this._curCamera.cameraMatrix.mat4[3],
+ this._curCamera.cameraMatrix.mat4[4],
+ this._curCamera.cameraMatrix.mat4[5],
+ this._curCamera.cameraMatrix.mat4[6],
+ this._curCamera.cameraMatrix.mat4[7],
+ this._curCamera.cameraMatrix.mat4[8],
+ this._curCamera.cameraMatrix.mat4[9],
+ this._curCamera.cameraMatrix.mat4[10],
+ this._curCamera.cameraMatrix.mat4[11],
+ this._curCamera.cameraMatrix.mat4[12],
+ this._curCamera.cameraMatrix.mat4[13],
+ this._curCamera.cameraMatrix.mat4[14],
+ this._curCamera.cameraMatrix.mat4[15]
+ );
+
+ // reset light data for new frame.
+
+ this.ambientLightColors.length = 0;
+ this.specularColors = [1, 1, 1];
+
+ this.directionalLightDirections.length = 0;
+ this.directionalLightDiffuseColors.length = 0;
+ this.directionalLightSpecularColors.length = 0;
+
+ this.pointLightPositions.length = 0;
+ this.pointLightDiffuseColors.length = 0;
+ this.pointLightSpecularColors.length = 0;
+
+ this.spotLightPositions.length = 0;
+ this.spotLightDirections.length = 0;
+ this.spotLightDiffuseColors.length = 0;
+ this.spotLightSpecularColors.length = 0;
+ this.spotLightAngle.length = 0;
+ this.spotLightConc.length = 0;
+
+ this._enableLighting = false;
+
+ //reset tint value for new frame
+ this._tint = [255, 255, 255, 255];
+
+ //Clear depth every frame
+ this.GL.clear(this.GL.DEPTH_BUFFER_BIT);
+ };
+
+ /**
+ * [background description]
+ */
+ _main.default.RendererGL.prototype.background = function() {
+ var _this$_pInst;
+ var _col = (_this$_pInst = this._pInst).color.apply(_this$_pInst, arguments);
+ var _r = _col.levels[0] / 255;
+ var _g = _col.levels[1] / 255;
+ var _b = _col.levels[2] / 255;
+ var _a = _col.levels[3] / 255;
+ this.GL.clearColor(_r, _g, _b, _a);
+
+ this.GL.clear(this.GL.COLOR_BUFFER_BIT);
+ };
+
+ //////////////////////////////////////////////
+ // COLOR
+ //////////////////////////////////////////////
+ /**
+ * Basic fill material for geometry with a given color
+ * @method fill
+ * @class p5.RendererGL
+ * @param {Number|Number[]|String|p5.Color} v1 gray value,
+ * red or hue value (depending on the current color mode),
+ * or color Array, or CSS color string
+ * @param {Number} [v2] green or saturation value
+ * @param {Number} [v3] blue or brightness value
+ * @param {Number} [a] opacity
+ * @chainable
+ * @example
+ *
+ *
+ * function setup() {
+ * createCanvas(200, 200, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * noStroke();
+ * fill(100, 100, 240);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * box(75, 75, 75);
+ * }
+ *
+ *
+ *
+ * @alt
+ * black canvas with purple cube spinning
+ */
+ _main.default.RendererGL.prototype.fill = function(v1, v2, v3, a) {
+ //see material.js for more info on color blending in webgl
+ var color = _main.default.prototype.color.apply(this._pInst, arguments);
+ this.curFillColor = color._array;
+ this.drawMode = constants.FILL;
+ this._useNormalMaterial = false;
+ this._tex = null;
+ };
+
+ /**
+ * Basic stroke material for geometry with a given color
+ * @method stroke
+ * @param {Number|Number[]|String|p5.Color} v1 gray value,
+ * red or hue value (depending on the current color mode),
+ * or color Array, or CSS color string
+ * @param {Number} [v2] green or saturation value
+ * @param {Number} [v3] blue or brightness value
+ * @param {Number} [a] opacity
+ * @example
+ *
+ *
+ * function setup() {
+ * createCanvas(200, 200, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * stroke(240, 150, 150);
+ * fill(100, 100, 240);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * box(75, 75, 75);
+ * }
+ *
+ *
+ *
+ * @alt
+ * black canvas with purple cube with pink outline spinning
+ */
+ _main.default.RendererGL.prototype.stroke = function(r, g, b, a) {
+ //@todo allow transparency in stroking currently doesn't have
+ //any impact and causes problems with specularMaterial
+ arguments[3] = 255;
+ var color = _main.default.prototype.color.apply(this._pInst, arguments);
+ this.curStrokeColor = color._array;
+ };
+
+ _main.default.RendererGL.prototype.strokeCap = function(cap) {
+ // @TODO : to be implemented
+ console.error('Sorry, strokeCap() is not yet implemented in WEBGL mode');
+ };
+
+ _main.default.RendererGL.prototype.strokeJoin = function(join) {
+ // @TODO : to be implemented
+ // https://processing.org/reference/strokeJoin_.html
+ console.error('Sorry, strokeJoin() is not yet implemented in WEBGL mode');
+ };
+
+ _main.default.RendererGL.prototype.filter = function(filterType) {
+ // filter can be achieved using custom shaders.
+ // https://github.com/aferriss/p5jsShaderExamples
+ // https://itp-xstory.github.io/p5js-shaders/#/
+ console.error('filter() does not work in WEBGL mode');
+ };
+
+ _main.default.RendererGL.prototype.blendMode = function(mode) {
+ if (
+ mode === constants.DARKEST ||
+ mode === constants.LIGHTEST ||
+ mode === constants.ADD ||
+ mode === constants.BLEND ||
+ mode === constants.SUBTRACT ||
+ mode === constants.SCREEN ||
+ mode === constants.EXCLUSION ||
+ mode === constants.REPLACE ||
+ mode === constants.MULTIPLY ||
+ mode === constants.REMOVE
+ )
+ this.curBlendMode = mode;
+ else if (
+ mode === constants.BURN ||
+ mode === constants.OVERLAY ||
+ mode === constants.HARD_LIGHT ||
+ mode === constants.SOFT_LIGHT ||
+ mode === constants.DODGE
+ ) {
+ console.warn(
+ 'BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only work for blendMode in 2D mode.'
+ );
+ }
+ };
+
+ _main.default.RendererGL.prototype.erase = function(opacityFill, opacityStroke) {
+ if (!this._isErasing) {
+ this._applyBlendMode(constants.REMOVE);
+ this._isErasing = true;
+
+ this._cachedFillStyle = this.curFillColor.slice();
+ this.curFillColor = [1, 1, 1, opacityFill / 255];
+
+ this._cachedStrokeStyle = this.curStrokeColor.slice();
+ this.curStrokeColor = [1, 1, 1, opacityStroke / 255];
+ }
+ };
+
+ _main.default.RendererGL.prototype.noErase = function() {
+ if (this._isErasing) {
+ this._isErasing = false;
+ this.curFillColor = this._cachedFillStyle.slice();
+ this.curStrokeColor = this._cachedStrokeStyle.slice();
+ this.blendMode(this._cachedBlendMode);
+ }
+ };
+
+ /**
+ * Change weight of stroke
+ * @method strokeWeight
+ * @param {Number} stroke weight to be used for drawing
+ * @example
+ *
+ *
+ * function setup() {
+ * createCanvas(200, 400, WEBGL);
+ * setAttributes('antialias', true);
+ * }
+ *
+ * function draw() {
+ * background(0);
+ * noStroke();
+ * translate(0, -100, 0);
+ * stroke(240, 150, 150);
+ * fill(100, 100, 240);
+ * push();
+ * strokeWeight(8);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * sphere(75);
+ * pop();
+ * push();
+ * translate(0, 200, 0);
+ * strokeWeight(1);
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * sphere(75);
+ * pop();
+ * }
+ *
+ *
+ *
+ * @alt
+ * black canvas with two purple rotating spheres with pink
+ * outlines the sphere on top has much heavier outlines,
+ */
+ _main.default.RendererGL.prototype.strokeWeight = function(w) {
+ if (this.curStrokeWeight !== w) {
+ this.pointSize = w;
+ this.curStrokeWeight = w;
+ }
+ };
+
+ // x,y are canvas-relative (pre-scaled by _pixelDensity)
+ _main.default.RendererGL.prototype._getPixel = function(x, y) {
+ var imageData, index;
+ imageData = new Uint8Array(4);
+ // prettier-ignore
+ this.drawingContext.readPixels(
+ x, y, 1, 1,
+ this.drawingContext.RGBA, this.drawingContext.UNSIGNED_BYTE,
+ imageData);
+
+ index = 0;
+ return [
+ imageData[index + 0],
+ imageData[index + 1],
+ imageData[index + 2],
+ imageData[index + 3]
+ ];
+ };
+
+ /**
+ * Loads the pixels data for this canvas into the pixels[] attribute.
+ * Note that updatePixels() and set() do not work.
+ * Any pixel manipulation must be done directly to the pixels[] array.
+ *
+ * @private
+ * @method loadPixels
+ */
+
+ _main.default.RendererGL.prototype.loadPixels = function() {
+ var pixelsState = this._pixelsState;
+
+ //@todo_FES
+ if (this._pInst._glAttributes.preserveDrawingBuffer !== true) {
+ console.log(
+ 'loadPixels only works in WebGL when preserveDrawingBuffer ' + 'is true.'
+ );
+
+ return;
+ }
+
+ //if there isn't a renderer-level temporary pixels buffer
+ //make a new one
+ var pixels = pixelsState.pixels;
+ var len = this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4;
+ if (!(pixels instanceof Uint8Array) || pixels.length !== len) {
+ pixels = new Uint8Array(len);
+ this._pixelsState._setProperty('pixels', pixels);
+ }
+
+ var pd = this._pInst._pixelDensity;
+ // prettier-ignore
+ this.GL.readPixels(
+ 0, 0, this.width * pd, this.height * pd,
+ this.GL.RGBA, this.GL.UNSIGNED_BYTE,
+ pixels);
+ };
+
+ //////////////////////////////////////////////
+ // HASH | for geometry
+ //////////////////////////////////////////////
+
+ _main.default.RendererGL.prototype.geometryInHash = function(gId) {
+ return this.retainedMode.geometry[gId] !== undefined;
+ };
+
+ /**
+ * [resize description]
+ * @private
+ * @param {Number} w [description]
+ * @param {Number} h [description]
+ */
+ _main.default.RendererGL.prototype.resize = function(w, h) {
+ _main.default.Renderer.prototype.resize.call(this, w, h);
+ this.GL.viewport(0, 0, this.GL.drawingBufferWidth, this.GL.drawingBufferHeight);
+
+ this._viewport = this.GL.getParameter(this.GL.VIEWPORT);
+
+ this._curCamera._resize();
+
+ //resize pixels buffer
+ var pixelsState = this._pixelsState;
+ if (typeof pixelsState.pixels !== 'undefined') {
+ pixelsState._setProperty(
+ 'pixels',
+ new Uint8Array(this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4)
+ );
+ }
+ };
+
+ /**
+ * clears color and depth buffers
+ * with r,g,b,a
+ * @private
+ * @param {Number} r normalized red val.
+ * @param {Number} g normalized green val.
+ * @param {Number} b normalized blue val.
+ * @param {Number} a normalized alpha val.
+ */
+ _main.default.RendererGL.prototype.clear = function() {
+ var _r = (arguments.length <= 0 ? undefined : arguments[0]) || 0;
+ var _g = (arguments.length <= 1 ? undefined : arguments[1]) || 0;
+ var _b = (arguments.length <= 2 ? undefined : arguments[2]) || 0;
+ var _a = (arguments.length <= 3 ? undefined : arguments[3]) || 0;
+ this.GL.clearColor(_r, _g, _b, _a);
+ this.GL.clear(this.GL.COLOR_BUFFER_BIT | this.GL.DEPTH_BUFFER_BIT);
+ };
+
+ _main.default.RendererGL.prototype.applyMatrix = function(a, b, c, d, e, f) {
+ if (arguments.length === 16) {
+ _main.default.Matrix.prototype.apply.apply(this.uMVMatrix, arguments);
+ } else {
+ // prettier-ignore
+ this.uMVMatrix.apply([
+ a, b, 0, 0,
+ c, d, 0, 0,
+ 0, 0, 1, 0,
+ e, f, 0, 1]);
+ }
+ };
+
+ /**
+ * [translate description]
+ * @private
+ * @param {Number} x [description]
+ * @param {Number} y [description]
+ * @param {Number} z [description]
+ * @chainable
+ * @todo implement handle for components or vector as args
+ */
+ _main.default.RendererGL.prototype.translate = function(x, y, z) {
+ if (x instanceof _main.default.Vector) {
+ z = x.z;
+ y = x.y;
+ x = x.x;
+ }
+ this.uMVMatrix.translate([x, y, z]);
+ return this;
+ };
+
+ /**
+ * Scales the Model View Matrix by a vector
+ * @private
+ * @param {Number | p5.Vector | Array} x [description]
+ * @param {Number} [y] y-axis scalar
+ * @param {Number} [z] z-axis scalar
+ * @chainable
+ */
+ _main.default.RendererGL.prototype.scale = function(x, y, z) {
+ this.uMVMatrix.scale(x, y, z);
+ return this;
+ };
+
+ _main.default.RendererGL.prototype.rotate = function(rad, axis) {
+ if (typeof axis === 'undefined') {
+ return this.rotateZ(rad);
+ }
+ _main.default.Matrix.prototype.rotate.apply(this.uMVMatrix, arguments);
+ return this;
+ };
+
+ _main.default.RendererGL.prototype.rotateX = function(rad) {
+ this.rotate(rad, 1, 0, 0);
+ return this;
+ };
+
+ _main.default.RendererGL.prototype.rotateY = function(rad) {
+ this.rotate(rad, 0, 1, 0);
+ return this;
+ };
+
+ _main.default.RendererGL.prototype.rotateZ = function(rad) {
+ this.rotate(rad, 0, 0, 1);
+ return this;
+ };
+
+ _main.default.RendererGL.prototype.push = function() {
+ // get the base renderer style
+ var style = _main.default.Renderer.prototype.push.apply(this);
+
+ // add webgl-specific style properties
+ var properties = style.properties;
+
+ properties.uMVMatrix = this.uMVMatrix.copy();
+ properties.uPMatrix = this.uPMatrix.copy();
+ properties._curCamera = this._curCamera;
+
+ // make a copy of the current camera for the push state
+ // this preserves any references stored using 'createCamera'
+ this._curCamera = this._curCamera.copy();
+
+ properties.ambientLightColors = this.ambientLightColors.slice();
+ properties.specularColors = this.specularColors.slice();
+
+ properties.directionalLightDirections = this.directionalLightDirections.slice();
+ properties.directionalLightDiffuseColors = this.directionalLightDiffuseColors.slice();
+ properties.directionalLightSpecularColors = this.directionalLightSpecularColors.slice();
+
+ properties.pointLightPositions = this.pointLightPositions.slice();
+ properties.pointLightDiffuseColors = this.pointLightDiffuseColors.slice();
+ properties.pointLightSpecularColors = this.pointLightSpecularColors.slice();
+
+ properties.spotLightPositions = this.spotLightPositions.slice();
+ properties.spotLightDirections = this.spotLightDirections.slice();
+ properties.spotLightDiffuseColors = this.spotLightDiffuseColors.slice();
+ properties.spotLightSpecularColors = this.spotLightSpecularColors.slice();
+ properties.spotLightAngle = this.spotLightAngle.slice();
+ properties.spotLightConc = this.spotLightConc.slice();
+
+ properties.userFillShader = this.userFillShader;
+ properties.userStrokeShader = this.userStrokeShader;
+ properties.userPointShader = this.userPointShader;
+
+ properties.pointSize = this.pointSize;
+ properties.curStrokeWeight = this.curStrokeWeight;
+ properties.curStrokeColor = this.curStrokeColor;
+ properties.curFillColor = this.curFillColor;
+
+ properties._useSpecularMaterial = this._useSpecularMaterial;
+ properties._useEmissiveMaterial = this._useEmissiveMaterial;
+ properties._useShininess = this._useShininess;
+
+ properties.constantAttenuation = this.constantAttenuation;
+ properties.linearAttenuation = this.linearAttenuation;
+ properties.quadraticAttenuation = this.quadraticAttenuation;
+
+ properties._enableLighting = this._enableLighting;
+ properties._useNormalMaterial = this._useNormalMaterial;
+ properties._tex = this._tex;
+ properties.drawMode = this.drawMode;
+
+ return style;
+ };
+
+ _main.default.RendererGL.prototype.resetMatrix = function() {
+ this.uMVMatrix = _main.default.Matrix.identity(this._pInst);
+ return this;
+ };
+
+ //////////////////////////////////////////////
+ // SHADER
+ //////////////////////////////////////////////
+
+ /*
+ * shaders are created and cached on a per-renderer basis,
+ * on the grounds that each renderer will have its own gl context
+ * and the shader must be valid in that context.
+ */
+
+ _main.default.RendererGL.prototype._getImmediateStrokeShader = function() {
+ // select the stroke shader to use
+ var stroke = this.userStrokeShader;
+ if (!stroke || !stroke.isStrokeShader()) {
+ return this._getLineShader();
+ }
+ return stroke;
+ };
+
+ _main.default.RendererGL.prototype._getRetainedStrokeShader =
+ _main.default.RendererGL.prototype._getImmediateStrokeShader;
+
+ /*
+ * selects which fill shader should be used based on renderer state,
+ * for use with begin/endShape and immediate vertex mode.
+ */
+ _main.default.RendererGL.prototype._getImmediateFillShader = function() {
+ var fill = this.userFillShader;
+ if (this._useNormalMaterial) {
+ if (!fill || !fill.isNormalShader()) {
+ return this._getNormalShader();
+ }
+ }
+ if (this._enableLighting) {
+ if (!fill || !fill.isLightShader()) {
+ return this._getLightShader();
+ }
+ } else if (this._tex) {
+ if (!fill || !fill.isTextureShader()) {
+ return this._getLightShader();
+ }
+ } else if (!fill /*|| !fill.isColorShader()*/) {
+ return this._getImmediateModeShader();
+ }
+ return fill;
+ };
+
+ /*
+ * selects which fill shader should be used based on renderer state
+ * for retained mode.
+ */
+ _main.default.RendererGL.prototype._getRetainedFillShader = function() {
+ if (this._useNormalMaterial) {
+ return this._getNormalShader();
+ }
+
+ var fill = this.userFillShader;
+ if (this._enableLighting) {
+ if (!fill || !fill.isLightShader()) {
+ return this._getLightShader();
+ }
+ } else if (this._tex) {
+ if (!fill || !fill.isTextureShader()) {
+ return this._getLightShader();
+ }
+ } else if (!fill /* || !fill.isColorShader()*/) {
+ return this._getColorShader();
+ }
+ return fill;
+ };
+
+ _main.default.RendererGL.prototype._getImmediatePointShader = function() {
+ // select the point shader to use
+ var point = this.userPointShader;
+ if (!point || !point.isPointShader()) {
+ return this._getPointShader();
+ }
+ return point;
+ };
+
+ _main.default.RendererGL.prototype._getRetainedLineShader =
+ _main.default.RendererGL.prototype._getImmediateLineShader;
+
+ _main.default.RendererGL.prototype._getLightShader = function() {
+ if (!this._defaultLightShader) {
+ if (this._pInst._glAttributes.perPixelLighting) {
+ this._defaultLightShader = new _main.default.Shader(
+ this,
+ defaultShaders.phongVert,
+ defaultShaders.phongFrag
+ );
+ } else {
+ this._defaultLightShader = new _main.default.Shader(
+ this,
+ defaultShaders.lightVert,
+ defaultShaders.lightTextureFrag
+ );
+ }
+ }
+
+ return this._defaultLightShader;
+ };
+
+ _main.default.RendererGL.prototype._getImmediateModeShader = function() {
+ if (!this._defaultImmediateModeShader) {
+ this._defaultImmediateModeShader = new _main.default.Shader(
+ this,
+ defaultShaders.immediateVert,
+ defaultShaders.vertexColorFrag
+ );
+ }
+
+ return this._defaultImmediateModeShader;
+ };
+
+ _main.default.RendererGL.prototype._getNormalShader = function() {
+ if (!this._defaultNormalShader) {
+ this._defaultNormalShader = new _main.default.Shader(
+ this,
+ defaultShaders.normalVert,
+ defaultShaders.normalFrag
+ );
+ }
+
+ return this._defaultNormalShader;
+ };
+
+ _main.default.RendererGL.prototype._getColorShader = function() {
+ if (!this._defaultColorShader) {
+ this._defaultColorShader = new _main.default.Shader(
+ this,
+ defaultShaders.normalVert,
+ defaultShaders.basicFrag
+ );
+ }
+
+ return this._defaultColorShader;
+ };
+
+ _main.default.RendererGL.prototype._getPointShader = function() {
+ if (!this._defaultPointShader) {
+ this._defaultPointShader = new _main.default.Shader(
+ this,
+ defaultShaders.pointVert,
+ defaultShaders.pointFrag
+ );
+ }
+ return this._defaultPointShader;
+ };
+
+ _main.default.RendererGL.prototype._getLineShader = function() {
+ if (!this._defaultLineShader) {
+ this._defaultLineShader = new _main.default.Shader(
+ this,
+ defaultShaders.lineVert,
+ defaultShaders.lineFrag
+ );
+ }
+
+ return this._defaultLineShader;
+ };
+
+ _main.default.RendererGL.prototype._getFontShader = function() {
+ if (!this._defaultFontShader) {
+ this.GL.getExtension('OES_standard_derivatives');
+ this._defaultFontShader = new _main.default.Shader(
+ this,
+ defaultShaders.fontVert,
+ defaultShaders.fontFrag
+ );
+ }
+ return this._defaultFontShader;
+ };
+
+ _main.default.RendererGL.prototype._getEmptyTexture = function() {
+ if (!this._emptyTexture) {
+ // a plain white texture RGBA, full alpha, single pixel.
+ var im = new _main.default.Image(1, 1);
+ im.set(0, 0, 255);
+ this._emptyTexture = new _main.default.Texture(this, im);
+ }
+ return this._emptyTexture;
+ };
+
+ _main.default.RendererGL.prototype.getTexture = function(img) {
+ var textures = this.textures;
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+ try {
+ for (
+ var _iterator = textures[Symbol.iterator](), _step;
+ !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
+ _iteratorNormalCompletion = true
+ ) {
+ var texture = _step.value;
+ if (texture.src === img) return texture;
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+
+ var tex = new _main.default.Texture(this, img);
+ textures.push(tex);
+ return tex;
+ };
+
+ _main.default.RendererGL.prototype._setStrokeUniforms = function(strokeShader) {
+ strokeShader.bindShader();
+
+ // set the uniform values
+ strokeShader.setUniform('uMaterialColor', this.curStrokeColor);
+ strokeShader.setUniform('uStrokeWeight', this.curStrokeWeight);
+ };
+
+ _main.default.RendererGL.prototype._setFillUniforms = function(fillShader) {
+ fillShader.bindShader();
+
+ // TODO: optimize
+ fillShader.setUniform('uMaterialColor', this.curFillColor);
+ fillShader.setUniform('isTexture', !!this._tex);
+ if (this._tex) {
+ fillShader.setUniform('uSampler', this._tex);
+ }
+ fillShader.setUniform('uTint', this._tint);
+
+ fillShader.setUniform('uSpecular', this._useSpecularMaterial);
+ fillShader.setUniform('uEmissive', this._useEmissiveMaterial);
+ fillShader.setUniform('uShininess', this._useShininess);
+
+ fillShader.setUniform('uUseLighting', this._enableLighting);
+
+ var pointLightCount = this.pointLightDiffuseColors.length / 3;
+ fillShader.setUniform('uPointLightCount', pointLightCount);
+ fillShader.setUniform('uPointLightLocation', this.pointLightPositions);
+ fillShader.setUniform('uPointLightDiffuseColors', this.pointLightDiffuseColors);
+
+ fillShader.setUniform(
+ 'uPointLightSpecularColors',
+ this.pointLightSpecularColors
+ );
+
+ var directionalLightCount = this.directionalLightDiffuseColors.length / 3;
+ fillShader.setUniform('uDirectionalLightCount', directionalLightCount);
+ fillShader.setUniform('uLightingDirection', this.directionalLightDirections);
+ fillShader.setUniform(
+ 'uDirectionalDiffuseColors',
+ this.directionalLightDiffuseColors
+ );
+
+ fillShader.setUniform(
+ 'uDirectionalSpecularColors',
+ this.directionalLightSpecularColors
+ );
+
+ // TODO: sum these here...
+ var ambientLightCount = this.ambientLightColors.length / 3;
+ fillShader.setUniform('uAmbientLightCount', ambientLightCount);
+ fillShader.setUniform('uAmbientColor', this.ambientLightColors);
+
+ var spotLightCount = this.spotLightDiffuseColors.length / 3;
+ fillShader.setUniform('uSpotLightCount', spotLightCount);
+ fillShader.setUniform('uSpotLightAngle', this.spotLightAngle);
+ fillShader.setUniform('uSpotLightConc', this.spotLightConc);
+ fillShader.setUniform('uSpotLightDiffuseColors', this.spotLightDiffuseColors);
+ fillShader.setUniform('uSpotLightSpecularColors', this.spotLightSpecularColors);
+
+ fillShader.setUniform('uSpotLightLocation', this.spotLightPositions);
+ fillShader.setUniform('uSpotLightDirection', this.spotLightDirections);
+
+ fillShader.setUniform('uConstantAttenuation', this.constantAttenuation);
+ fillShader.setUniform('uLinearAttenuation', this.linearAttenuation);
+ fillShader.setUniform('uQuadraticAttenuation', this.quadraticAttenuation);
+
+ fillShader.bindTextures();
+ };
+
+ _main.default.RendererGL.prototype._setPointUniforms = function(pointShader) {
+ pointShader.bindShader();
+
+ // set the uniform values
+ pointShader.setUniform('uMaterialColor', this.curStrokeColor);
+ // @todo is there an instance where this isn't stroke weight?
+ // should be they be same var?
+ pointShader.setUniform(
+ 'uPointSize',
+ this.pointSize * this._pInst._pixelDensity
+ );
+ };
+
+ /* Binds a buffer to the drawing context
+ * when passed more than two arguments it also updates or initializes
+ * the data associated with the buffer
+ */
+ _main.default.RendererGL.prototype._bindBuffer = function(
+ buffer,
+ target,
+ values,
+ type,
+ usage
+ ) {
+ if (!target) target = this.GL.ARRAY_BUFFER;
+ this.GL.bindBuffer(target, buffer);
+ if (values !== undefined) {
+ var data = new (type || Float32Array)(values);
+ this.GL.bufferData(target, data, usage || this.GL.STATIC_DRAW);
+ }
+ };
+
+ ///////////////////////////////
+ //// UTILITY FUNCTIONS
+ //////////////////////////////
+ _main.default.RendererGL.prototype._arraysEqual = function(a, b) {
+ var aLength = a.length;
+ if (aLength !== b.length) return false;
+ for (var i = 0; i < aLength; i++) {
+ if (a[i] !== b[i]) return false;
+ }
+ return true;
+ };
+
+ _main.default.RendererGL.prototype._isTypedArray = function(arr) {
+ var res = false;
+ res = arr instanceof Float32Array;
+ res = arr instanceof Float64Array;
+ res = arr instanceof Int16Array;
+ res = arr instanceof Uint16Array;
+ res = arr instanceof Uint32Array;
+ return res;
+ };
+ /**
+ * turn a two dimensional array into one dimensional array
+ * @private
+ * @param {Array} arr 2-dimensional array
+ * @return {Array} 1-dimensional array
+ * [[1, 2, 3],[4, 5, 6]] -> [1, 2, 3, 4, 5, 6]
+ */
+ _main.default.RendererGL.prototype._flatten = function(arr) {
+ //when empty, return empty
+ if (arr.length === 0) {
+ return [];
+ } else if (arr.length > 20000) {
+ //big models , load slower to avoid stack overflow
+ //faster non-recursive flatten via axelduch
+ //stackoverflow.com/questions/27266550/how-to-flatten-nested-array-in-javascript
+ var _toString = Object.prototype.toString;
+ var arrayTypeStr = '[object Array]';
+ var result = [];
+ var nodes = arr.slice();
+ var node;
+ node = nodes.pop();
+ do {
+ if (_toString.call(node) === arrayTypeStr) {
+ nodes.push.apply(nodes, _toConsumableArray(node));
+ } else {
+ result.push(node);
+ }
+ } while (nodes.length && (node = nodes.pop()) !== undefined);
+ result.reverse(); // we reverse result to restore the original order
+ return result;
+ } else {
+ var _ref;
+ //otherwise if model within limits for browser
+ //use faster recursive loading
+ return (_ref = []).concat.apply(_ref, _toConsumableArray(arr));
+ }
+ };
+
+ /**
+ * turn a p5.Vector Array into a one dimensional number array
+ * @private
+ * @param {p5.Vector[]} arr an array of p5.Vector
+ * @return {Number[]} a one dimensional array of numbers
+ * [p5.Vector(1, 2, 3), p5.Vector(4, 5, 6)] ->
+ * [1, 2, 3, 4, 5, 6]
+ */
+ _main.default.RendererGL.prototype._vToNArray = function(arr) {
+ var ret = [];
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+ try {
+ for (
+ var _iterator2 = arr[Symbol.iterator](), _step2;
+ !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
+ _iteratorNormalCompletion2 = true
+ ) {
+ var item = _step2.value;
+ ret.push(item.x, item.y, item.z);
+ }
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+
+ return ret;
+ };
+
+ /**
+ * ensures that p5 is using a 3d renderer. throws an error if not.
+ */
+ _main.default.prototype._assert3d = function(name) {
+ if (!this._renderer.isP3D)
+ throw new Error(
+ ''.concat(
+ name,
+ "() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information."
+ )
+ );
+ };
+
+ // function to initialize GLU Tesselator
+
+ _main.default.RendererGL.prototype._initTessy = function initTesselator() {
+ // function called for each vertex of tesselator output
+ function vertexCallback(data, polyVertArray) {
+ polyVertArray[polyVertArray.length] = data[0];
+ polyVertArray[polyVertArray.length] = data[1];
+ polyVertArray[polyVertArray.length] = data[2];
+ }
+
+ function begincallback(type) {
+ if (type !== _libtess.default.primitiveType.GL_TRIANGLES) {
+ console.log('expected TRIANGLES but got type: '.concat(type));
+ }
+ }
+
+ function errorcallback(errno) {
+ console.log('error callback');
+ console.log('error number: '.concat(errno));
+ }
+ // callback for when segments intersect and must be split
+ function combinecallback(coords, data, weight) {
+ return [coords[0], coords[1], coords[2]];
+ }
+
+ function edgeCallback(flag) {
+ // don't really care about the flag, but need no-strip/no-fan behavior
+ }
+
+ var tessy = new _libtess.default.GluTesselator();
+ tessy.gluTessCallback(
+ _libtess.default.gluEnum.GLU_TESS_VERTEX_DATA,
+ vertexCallback
+ );
+ tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_BEGIN, begincallback);
+ tessy.gluTessCallback(_libtess.default.gluEnum.GLU_TESS_ERROR, errorcallback);
+ tessy.gluTessCallback(
+ _libtess.default.gluEnum.GLU_TESS_COMBINE,
+ combinecallback
+ );
+ tessy.gluTessCallback(
+ _libtess.default.gluEnum.GLU_TESS_EDGE_FLAG,
+ edgeCallback
+ );
+
+ return tessy;
+ };
+
+ _main.default.RendererGL.prototype._triangulate = function(contours) {
+ // libtess will take 3d verts and flatten to a plane for tesselation
+ // since only doing 2d tesselation here, provide z=1 normal to skip
+ // iterating over verts only to get the same answer.
+ // comment out to test normal-generation code
+ this._tessy.gluTessNormal(0, 0, 1);
+
+ var triangleVerts = [];
+ this._tessy.gluTessBeginPolygon(triangleVerts);
+
+ for (var i = 0; i < contours.length; i++) {
+ this._tessy.gluTessBeginContour();
+ var contour = contours[i];
+ for (var j = 0; j < contour.length; j += 3) {
+ var coords = [contour[j], contour[j + 1], contour[j + 2]];
+ this._tessy.gluTessVertex(coords, coords);
+ }
+ this._tessy.gluTessEndContour();
+ }
+
+ // finish polygon
+ this._tessy.gluTessEndPolygon();
+
+ return triangleVerts;
+ };
+
+ // function to calculate BezierVertex Coefficients
+ _main.default.RendererGL.prototype._bezierCoefficients = function(t) {
+ var t2 = t * t;
+ var t3 = t2 * t;
+ var mt = 1 - t;
+ var mt2 = mt * mt;
+ var mt3 = mt2 * mt;
+ return [mt3, 3 * mt2 * t, 3 * mt * t2, t3];
+ };
+
+ // function to calculate QuadraticVertex Coefficients
+ _main.default.RendererGL.prototype._quadraticCoefficients = function(t) {
+ var t2 = t * t;
+ var mt = 1 - t;
+ var mt2 = mt * mt;
+ return [mt2, 2 * mt * t, t2];
+ };
+
+ // function to convert Bezier coordinates to Catmull Rom Splines
+ _main.default.RendererGL.prototype._bezierToCatmull = function(w) {
+ var p1 = w[1];
+ var p2 = w[1] + (w[2] - w[0]) / this._curveTightness;
+ var p3 = w[2] - (w[3] - w[1]) / this._curveTightness;
+ var p4 = w[2];
+ var p = [p1, p2, p3, p4];
+ return p;
+ };
+ var _default = _main.default.RendererGL;
+ exports.default = _default;
+ },
+ {
+ '../core/constants': 272,
+ '../core/main': 283,
+ '../core/p5.Renderer': 286,
+ './p5.Camera': 331,
+ './p5.Matrix': 333,
+ './p5.Shader': 338,
+ 'core-js/modules/es.array.concat': 166,
+ 'core-js/modules/es.array.fill': 168,
+ 'core-js/modules/es.array.filter': 169,
+ 'core-js/modules/es.array.from': 171,
+ 'core-js/modules/es.array.includes': 172,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.array.slice': 178,
+ 'core-js/modules/es.object.assign': 188,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.regexp.to-string': 197,
+ 'core-js/modules/es.string.includes': 200,
+ 'core-js/modules/es.string.iterator': 201,
+ 'core-js/modules/es.symbol': 211,
+ 'core-js/modules/es.symbol.description': 209,
+ 'core-js/modules/es.symbol.iterator': 210,
+ 'core-js/modules/es.typed-array.copy-within': 212,
+ 'core-js/modules/es.typed-array.every': 213,
+ 'core-js/modules/es.typed-array.fill': 214,
+ 'core-js/modules/es.typed-array.filter': 215,
+ 'core-js/modules/es.typed-array.find': 217,
+ 'core-js/modules/es.typed-array.find-index': 216,
+ 'core-js/modules/es.typed-array.float32-array': 218,
+ 'core-js/modules/es.typed-array.float64-array': 219,
+ 'core-js/modules/es.typed-array.for-each': 220,
+ 'core-js/modules/es.typed-array.includes': 221,
+ 'core-js/modules/es.typed-array.index-of': 222,
+ 'core-js/modules/es.typed-array.int16-array': 223,
+ 'core-js/modules/es.typed-array.iterator': 225,
+ 'core-js/modules/es.typed-array.join': 226,
+ 'core-js/modules/es.typed-array.last-index-of': 227,
+ 'core-js/modules/es.typed-array.map': 228,
+ 'core-js/modules/es.typed-array.reduce': 230,
+ 'core-js/modules/es.typed-array.reduce-right': 229,
+ 'core-js/modules/es.typed-array.reverse': 231,
+ 'core-js/modules/es.typed-array.set': 232,
+ 'core-js/modules/es.typed-array.slice': 233,
+ 'core-js/modules/es.typed-array.some': 234,
+ 'core-js/modules/es.typed-array.sort': 235,
+ 'core-js/modules/es.typed-array.subarray': 236,
+ 'core-js/modules/es.typed-array.to-locale-string': 237,
+ 'core-js/modules/es.typed-array.to-string': 238,
+ 'core-js/modules/es.typed-array.uint16-array': 239,
+ 'core-js/modules/es.typed-array.uint32-array': 240,
+ 'core-js/modules/es.typed-array.uint8-array': 241,
+ 'core-js/modules/web.dom-collections.iterator': 244,
+ libtess: 256,
+ path: 259
+ }
+ ],
+ 338: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ _dereq_('core-js/modules/es.symbol');
+ _dereq_('core-js/modules/es.symbol.description');
+ _dereq_('core-js/modules/es.symbol.iterator');
+ _dereq_('core-js/modules/es.array.index-of');
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.array.slice');
+ _dereq_('core-js/modules/es.function.name');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.string.iterator');
+ _dereq_('core-js/modules/web.dom-collections.iterator');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+ /**
+ * This module defines the p5.Shader class
+ * @module Lights, Camera
+ * @submodule Material
+ * @for p5
+ * @requires core
+ */ /**
+ * Shader class for WEBGL Mode
+ * @class p5.Shader
+ * @constructor
+ * @param {p5.RendererGL} renderer an instance of p5.RendererGL that
+ * will provide the GL context for this new p5.Shader
+ * @param {String} vertSrc source code for the vertex shader (as a string)
+ * @param {String} fragSrc source code for the fragment shader (as a string)
+ */ _main.default.Shader = function(renderer, vertSrc, fragSrc) {
+ // TODO: adapt this to not take ids, but rather,
+ // to take the source for a vertex and fragment shader
+ // to enable custom shaders at some later date
+ this._renderer = renderer;
+ this._vertSrc = vertSrc;
+ this._fragSrc = fragSrc;
+ this._vertShader = -1;
+ this._fragShader = -1;
+ this._glProgram = 0;
+ this._loadedAttributes = false;
+ this.attributes = {};
+ this._loadedUniforms = false;
+ this.uniforms = {};
+ this._bound = false;
+ this.samplers = [];
+ };
+
+ /**
+ * Creates, compiles, and links the shader based on its
+ * sources for the vertex and fragment shaders (provided
+ * to the constructor). Populates known attributes and
+ * uniforms from the shader.
+ * @method init
+ * @chainable
+ * @private
+ */
+ _main.default.Shader.prototype.init = function() {
+ if (this._glProgram === 0 /* or context is stale? */) {
+ var gl = this._renderer.GL;
+
+ // @todo: once custom shading is allowed,
+ // friendly error messages should be used here to share
+ // compiler and linker errors.
+
+ //set up the shader by
+ // 1. creating and getting a gl id for the shader program,
+ // 2. compliling its vertex & fragment sources,
+ // 3. linking the vertex and fragment shaders
+ this._vertShader = gl.createShader(gl.VERTEX_SHADER);
+ //load in our default vertex shader
+ gl.shaderSource(this._vertShader, this._vertSrc);
+ gl.compileShader(this._vertShader);
+ // if our vertex shader failed compilation?
+ if (!gl.getShaderParameter(this._vertShader, gl.COMPILE_STATUS)) {
+ console.error(
+ 'Yikes! An error occurred compiling the vertex shader:'.concat(
+ gl.getShaderInfoLog(this._vertShader)
+ )
+ );
+
+ return null;
+ }
+
+ this._fragShader = gl.createShader(gl.FRAGMENT_SHADER);
+ //load in our material frag shader
+ gl.shaderSource(this._fragShader, this._fragSrc);
+ gl.compileShader(this._fragShader);
+ // if our frag shader failed compilation?
+ if (!gl.getShaderParameter(this._fragShader, gl.COMPILE_STATUS)) {
+ console.error(
+ 'Darn! An error occurred compiling the fragment shader:'.concat(
+ gl.getShaderInfoLog(this._fragShader)
+ )
+ );
+
+ return null;
+ }
+
+ this._glProgram = gl.createProgram();
+ gl.attachShader(this._glProgram, this._vertShader);
+ gl.attachShader(this._glProgram, this._fragShader);
+ gl.linkProgram(this._glProgram);
+ if (!gl.getProgramParameter(this._glProgram, gl.LINK_STATUS)) {
+ console.error(
+ 'Snap! Error linking shader program: '.concat(
+ gl.getProgramInfoLog(this._glProgram)
+ )
+ );
+ }
+
+ this._loadAttributes();
+ this._loadUniforms();
+ }
+ return this;
+ };
+
+ /**
+ * Queries the active attributes for this shader and loads
+ * their names and locations into the attributes array.
+ * @method _loadAttributes
+ * @private
+ */
+ _main.default.Shader.prototype._loadAttributes = function() {
+ if (this._loadedAttributes) {
+ return;
+ }
+
+ this.attributes = {};
+
+ var gl = this._renderer.GL;
+
+ var numAttributes = gl.getProgramParameter(
+ this._glProgram,
+ gl.ACTIVE_ATTRIBUTES
+ );
+
+ for (var i = 0; i < numAttributes; ++i) {
+ var attributeInfo = gl.getActiveAttrib(this._glProgram, i);
+ var name = attributeInfo.name;
+ var location = gl.getAttribLocation(this._glProgram, name);
+ var attribute = {};
+ attribute.name = name;
+ attribute.location = location;
+ attribute.index = i;
+ attribute.type = attributeInfo.type;
+ attribute.size = attributeInfo.size;
+ this.attributes[name] = attribute;
+ }
+
+ this._loadedAttributes = true;
+ };
+
+ /**
+ * Queries the active uniforms for this shader and loads
+ * their names and locations into the uniforms array.
+ * @method _loadUniforms
+ * @private
+ */
+ _main.default.Shader.prototype._loadUniforms = function() {
+ if (this._loadedUniforms) {
+ return;
+ }
+
+ var gl = this._renderer.GL;
+
+ // Inspect shader and cache uniform info
+ var numUniforms = gl.getProgramParameter(this._glProgram, gl.ACTIVE_UNIFORMS);
+
+ var samplerIndex = 0;
+ for (var i = 0; i < numUniforms; ++i) {
+ var uniformInfo = gl.getActiveUniform(this._glProgram, i);
+ var uniform = {};
+ uniform.location = gl.getUniformLocation(this._glProgram, uniformInfo.name);
+ uniform.size = uniformInfo.size;
+ var uniformName = uniformInfo.name;
+ //uniforms thats are arrays have their name returned as
+ //someUniform[0] which is a bit silly so we trim it
+ //off here. The size property tells us that its an array
+ //so we dont lose any information by doing this
+ if (uniformInfo.size > 1) {
+ uniformName = uniformName.substring(0, uniformName.indexOf('[0]'));
+ }
+ uniform.name = uniformName;
+ uniform.type = uniformInfo.type;
+ uniform._cachedData = undefined;
+ if (uniform.type === gl.SAMPLER_2D) {
+ uniform.samplerIndex = samplerIndex;
+ samplerIndex++;
+ this.samplers.push(uniform);
+ }
+ uniform.isArray =
+ uniform.type === gl.FLOAT_MAT3 ||
+ uniform.type === gl.FLOAT_MAT4 ||
+ uniform.type === gl.FLOAT_VEC2 ||
+ uniform.type === gl.FLOAT_VEC3 ||
+ uniform.type === gl.FLOAT_VEC4 ||
+ uniform.type === gl.INT_VEC2 ||
+ uniform.type === gl.INT_VEC3 ||
+ uniform.type === gl.INT_VEC4;
+
+ this.uniforms[uniformName] = uniform;
+ }
+ this._loadedUniforms = true;
+ };
+
+ _main.default.Shader.prototype.compile = function() {
+ // TODO
+ };
+
+ /**
+ * initializes (if needed) and binds the shader program.
+ * @method bindShader
+ * @private
+ */
+ _main.default.Shader.prototype.bindShader = function() {
+ this.init();
+ if (!this._bound) {
+ this.useProgram();
+ this._bound = true;
+
+ this._setMatrixUniforms();
+
+ this.setUniform('uViewport', this._renderer._viewport);
+ }
+ };
+
+ /**
+ * @method unbindShader
+ * @chainable
+ * @private
+ */
+ _main.default.Shader.prototype.unbindShader = function() {
+ if (this._bound) {
+ this.unbindTextures();
+ //this._renderer.GL.useProgram(0); ??
+ this._bound = false;
+ }
+ return this;
+ };
+
+ _main.default.Shader.prototype.bindTextures = function() {
+ var gl = this._renderer.GL;
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+ try {
+ for (
+ var _iterator = this.samplers[Symbol.iterator](), _step;
+ !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
+ _iteratorNormalCompletion = true
+ ) {
+ var uniform = _step.value;
+ var tex = uniform.texture;
+ if (tex === undefined) {
+ // user hasn't yet supplied a texture for this slot.
+ // (or there may not be one--maybe just lighting),
+ // so we supply a default texture instead.
+ tex = this._renderer._getEmptyTexture();
+ }
+ gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
+ tex.bindTexture();
+ tex.update();
+ gl.uniform1i(uniform.location, uniform.samplerIndex);
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+ };
+
+ _main.default.Shader.prototype.updateTextures = function() {
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+ try {
+ for (
+ var _iterator2 = this.samplers[Symbol.iterator](), _step2;
+ !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
+ _iteratorNormalCompletion2 = true
+ ) {
+ var uniform = _step2.value;
+ var tex = uniform.texture;
+ if (tex) {
+ tex.update();
+ }
+ }
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+ };
+
+ _main.default.Shader.prototype.unbindTextures = function() {
+ // TODO: migrate stuff from material.js here
+ // - OR - have material.js define this function
+ };
+
+ _main.default.Shader.prototype._setMatrixUniforms = function() {
+ this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4);
+ if (this.isStrokeShader()) {
+ if (this._renderer._curCamera.cameraType === 'default') {
+ // strokes scale up as they approach camera, default
+ this.setUniform('uPerspective', 1);
+ } else {
+ // strokes have uniform scale regardless of distance from camera
+ this.setUniform('uPerspective', 0);
+ }
+ }
+ this.setUniform('uModelViewMatrix', this._renderer.uMVMatrix.mat4);
+ this.setUniform('uViewMatrix', this._renderer._curCamera.cameraMatrix.mat4);
+ if (this.uniforms.uNormalMatrix) {
+ this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix);
+ this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3);
+ }
+ };
+
+ /**
+ * @method useProgram
+ * @chainable
+ * @private
+ */
+ _main.default.Shader.prototype.useProgram = function() {
+ var gl = this._renderer.GL;
+ if (this._renderer._curShader !== this) {
+ gl.useProgram(this._glProgram);
+ this._renderer._curShader = this;
+ }
+ return this;
+ };
+
+ /**
+ * Wrapper around gl.uniform functions.
+ * As we store uniform info in the shader we can use that
+ * to do type checking on the supplied data and call
+ * the appropriate function.
+ * @method setUniform
+ * @chainable
+ * @param {String} uniformName the name of the uniform in the
+ * shader program
+ * @param {Object|Number|Boolean|Number[]} data the data to be associated
+ * with that uniform; type varies (could be a single numerical value, array,
+ * matrix, or texture / sampler reference)
+ *
+ * @example
+ *
+ *
+ * // Click within the image to toggle the value of uniforms
+ * // Note: for an alternative approach to the same example,
+ * // involving toggling between shaders please refer to:
+ * // https://p5js.org/reference/#/p5/shader
+ *
+ * let grad;
+ * let showRedGreen = false;
+ *
+ * function preload() {
+ * // note that we are using two instances
+ * // of the same vertex and fragment shaders
+ * grad = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * shader(grad);
+ * noStroke();
+ * }
+ *
+ * function draw() {
+ * // update the offset values for each scenario,
+ * // moving the "grad" shader in either vertical or
+ * // horizontal direction each with differing colors
+ *
+ * if (showRedGreen === true) {
+ * grad.setUniform('colorCenter', [1, 0, 0]);
+ * grad.setUniform('colorBackground', [0, 1, 0]);
+ * grad.setUniform('offset', [sin(millis() / 2000), 1]);
+ * } else {
+ * grad.setUniform('colorCenter', [1, 0.5, 0]);
+ * grad.setUniform('colorBackground', [0.226, 0, 0.615]);
+ * grad.setUniform('offset', [0, sin(millis() / 2000) + 1]);
+ * }
+ * quad(-1, -1, 1, -1, 1, 1, -1, 1);
+ * }
+ *
+ * function mouseClicked() {
+ * showRedGreen = !showRedGreen;
+ * }
+ *
+ *
+ *
+ * @alt
+ * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.
+ */
+ _main.default.Shader.prototype.setUniform = function(uniformName, data) {
+ var uniform = this.uniforms[uniformName];
+ if (!uniform) {
+ return;
+ }
+ var gl = this._renderer.GL;
+
+ if (uniform.isArray) {
+ if (
+ uniform._cachedData &&
+ this._renderer._arraysEqual(uniform._cachedData, data)
+ ) {
+ return;
+ } else {
+ uniform._cachedData = data.slice(0);
+ }
+ } else if (uniform._cachedData && uniform._cachedData === data) {
+ return;
+ } else {
+ uniform._cachedData = data;
+ }
+
+ var location = uniform.location;
+
+ this.useProgram();
+
+ switch (uniform.type) {
+ case gl.BOOL:
+ if (data === true) {
+ gl.uniform1i(location, 1);
+ } else {
+ gl.uniform1i(location, 0);
+ }
+ break;
+ case gl.INT:
+ if (uniform.size > 1) {
+ data.length && gl.uniform1iv(location, data);
+ } else {
+ gl.uniform1i(location, data);
+ }
+ break;
+ case gl.FLOAT:
+ if (uniform.size > 1) {
+ data.length && gl.uniform1fv(location, data);
+ } else {
+ gl.uniform1f(location, data);
+ }
+ break;
+ case gl.FLOAT_MAT3:
+ gl.uniformMatrix3fv(location, false, data);
+ break;
+ case gl.FLOAT_MAT4:
+ gl.uniformMatrix4fv(location, false, data);
+ break;
+ case gl.FLOAT_VEC2:
+ if (uniform.size > 1) {
+ data.length && gl.uniform2fv(location, data);
+ } else {
+ gl.uniform2f(location, data[0], data[1]);
+ }
+ break;
+ case gl.FLOAT_VEC3:
+ if (uniform.size > 1) {
+ data.length && gl.uniform3fv(location, data);
+ } else {
+ gl.uniform3f(location, data[0], data[1], data[2]);
+ }
+ break;
+ case gl.FLOAT_VEC4:
+ if (uniform.size > 1) {
+ data.length && gl.uniform4fv(location, data);
+ } else {
+ gl.uniform4f(location, data[0], data[1], data[2], data[3]);
+ }
+ break;
+ case gl.INT_VEC2:
+ if (uniform.size > 1) {
+ data.length && gl.uniform2iv(location, data);
+ } else {
+ gl.uniform2i(location, data[0], data[1]);
+ }
+ break;
+ case gl.INT_VEC3:
+ if (uniform.size > 1) {
+ data.length && gl.uniform3iv(location, data);
+ } else {
+ gl.uniform3i(location, data[0], data[1], data[2]);
+ }
+ break;
+ case gl.INT_VEC4:
+ if (uniform.size > 1) {
+ data.length && gl.uniform4iv(location, data);
+ } else {
+ gl.uniform4i(location, data[0], data[1], data[2], data[3]);
+ }
+ break;
+ case gl.SAMPLER_2D:
+ gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
+ uniform.texture = this._renderer.getTexture(data);
+ gl.uniform1i(uniform.location, uniform.samplerIndex);
+ break;
+ //@todo complete all types
+ }
+ return this;
+ };
+
+ /* NONE OF THIS IS FAST OR EFFICIENT BUT BEAR WITH ME
+ *
+ * these shader "type" query methods are used by various
+ * facilities of the renderer to determine if changing
+ * the shader type for the required action (for example,
+ * do we need to load the default lighting shader if the
+ * current shader cannot handle lighting?)
+ *
+ **/
+
+ _main.default.Shader.prototype.isLightShader = function() {
+ return (
+ this.attributes.aNormal !== undefined ||
+ this.uniforms.uUseLighting !== undefined ||
+ this.uniforms.uAmbientLightCount !== undefined ||
+ this.uniforms.uDirectionalLightCount !== undefined ||
+ this.uniforms.uPointLightCount !== undefined ||
+ this.uniforms.uAmbientColor !== undefined ||
+ this.uniforms.uDirectionalDiffuseColors !== undefined ||
+ this.uniforms.uDirectionalSpecularColors !== undefined ||
+ this.uniforms.uPointLightLocation !== undefined ||
+ this.uniforms.uPointLightDiffuseColors !== undefined ||
+ this.uniforms.uPointLightSpecularColors !== undefined ||
+ this.uniforms.uLightingDirection !== undefined ||
+ this.uniforms.uSpecular !== undefined
+ );
+ };
+
+ _main.default.Shader.prototype.isNormalShader = function() {
+ return this.attributes.aNormal !== undefined;
+ };
+
+ _main.default.Shader.prototype.isTextureShader = function() {
+ return this.samplerIndex > 0;
+ };
+
+ _main.default.Shader.prototype.isColorShader = function() {
+ return (
+ this.attributes.aVertexColor !== undefined ||
+ this.uniforms.uMaterialColor !== undefined
+ );
+ };
+
+ _main.default.Shader.prototype.isTexLightShader = function() {
+ return this.isLightShader() && this.isTextureShader();
+ };
+
+ _main.default.Shader.prototype.isStrokeShader = function() {
+ return this.uniforms.uStrokeWeight !== undefined;
+ };
+
+ /**
+ * @method enableAttrib
+ * @chainable
+ * @private
+ */
+ _main.default.Shader.prototype.enableAttrib = function(
+ attr,
+ size,
+ type,
+ normalized,
+ stride,
+ offset
+ ) {
+ if (attr) {
+ if (
+ typeof IS_MINIFIED === 'undefined' &&
+ this.attributes[attr.name] !== attr
+ ) {
+ console.warn(
+ 'The attribute "'.concat(
+ attr.name,
+ '"passed to enableAttrib does not belong to this shader.'
+ )
+ );
+ }
+ var loc = attr.location;
+ if (loc !== -1) {
+ var gl = this._renderer.GL;
+ if (!attr.enabled) {
+ gl.enableVertexAttribArray(loc);
+ attr.enabled = true;
+ }
+ this._renderer.GL.vertexAttribPointer(
+ loc,
+ size,
+ type || gl.FLOAT,
+ normalized || false,
+ stride || 0,
+ offset || 0
+ );
+ }
+ }
+ return this;
+ };
+ var _default = _main.default.Shader;
+ exports.default = _default;
+ },
+ {
+ '../core/main': 283,
+ 'core-js/modules/es.array.index-of': 173,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.array.slice': 178,
+ 'core-js/modules/es.function.name': 181,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.string.iterator': 201,
+ 'core-js/modules/es.symbol': 211,
+ 'core-js/modules/es.symbol.description': 209,
+ 'core-js/modules/es.symbol.iterator': 210,
+ 'core-js/modules/web.dom-collections.iterator': 244
+ }
+ ],
+ 339: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ function _typeof(obj) {
+ if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
+ _typeof = function _typeof(obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function _typeof(obj) {
+ return obj &&
+ typeof Symbol === 'function' &&
+ obj.constructor === Symbol &&
+ obj !== Symbol.prototype
+ ? 'symbol'
+ : typeof obj;
+ };
+ }
+ return _typeof(obj);
+ }
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.typed-array.uint8-array');
+ _dereq_('core-js/modules/es.typed-array.copy-within');
+ _dereq_('core-js/modules/es.typed-array.every');
+ _dereq_('core-js/modules/es.typed-array.fill');
+ _dereq_('core-js/modules/es.typed-array.filter');
+ _dereq_('core-js/modules/es.typed-array.find');
+ _dereq_('core-js/modules/es.typed-array.find-index');
+ _dereq_('core-js/modules/es.typed-array.for-each');
+ _dereq_('core-js/modules/es.typed-array.includes');
+ _dereq_('core-js/modules/es.typed-array.index-of');
+ _dereq_('core-js/modules/es.typed-array.iterator');
+ _dereq_('core-js/modules/es.typed-array.join');
+ _dereq_('core-js/modules/es.typed-array.last-index-of');
+ _dereq_('core-js/modules/es.typed-array.map');
+ _dereq_('core-js/modules/es.typed-array.reduce');
+ _dereq_('core-js/modules/es.typed-array.reduce-right');
+ _dereq_('core-js/modules/es.typed-array.reverse');
+ _dereq_('core-js/modules/es.typed-array.set');
+ _dereq_('core-js/modules/es.typed-array.slice');
+ _dereq_('core-js/modules/es.typed-array.some');
+ _dereq_('core-js/modules/es.typed-array.sort');
+ _dereq_('core-js/modules/es.typed-array.subarray');
+ _dereq_('core-js/modules/es.typed-array.to-locale-string');
+ _dereq_('core-js/modules/es.typed-array.to-string');
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.default = void 0;
+
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ var constants = _interopRequireWildcard(_dereq_('../core/constants'));
+ function _getRequireWildcardCache() {
+ if (typeof WeakMap !== 'function') return null;
+ var cache = new WeakMap();
+ _getRequireWildcardCache = function _getRequireWildcardCache() {
+ return cache;
+ };
+ return cache;
+ }
+ function _interopRequireWildcard(obj) {
+ if (obj && obj.__esModule) {
+ return obj;
+ }
+ if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
+ return { default: obj };
+ }
+ var cache = _getRequireWildcardCache();
+ if (cache && cache.has(obj)) {
+ return cache.get(obj);
+ }
+ var newObj = {};
+ var hasPropertyDescriptor =
+ Object.defineProperty && Object.getOwnPropertyDescriptor;
+ for (var key in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
+ var desc = hasPropertyDescriptor
+ ? Object.getOwnPropertyDescriptor(obj, key)
+ : null;
+ if (desc && (desc.get || desc.set)) {
+ Object.defineProperty(newObj, key, desc);
+ } else {
+ newObj[key] = obj[key];
+ }
+ }
+ }
+ newObj.default = obj;
+ if (cache) {
+ cache.set(obj, newObj);
+ }
+ return newObj;
+ }
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+ /**
+ * This module defines the p5.Texture class
+ * @module Lights, Camera
+ * @submodule Material
+ * @for p5
+ * @requires core
+ */ /**
+ * Texture class for WEBGL Mode
+ * @private
+ * @class p5.Texture
+ * @param {p5.RendererGL} renderer an instance of p5.RendererGL that
+ * will provide the GL context for this new p5.Texture
+ * @param {p5.Image|p5.Graphics|p5.Element|p5.MediaElement|ImageData} [obj] the
+ * object containing the image data to store in the texture.
+ */ _main.default.Texture = function(renderer, obj) {
+ this._renderer = renderer;
+ var gl = this._renderer.GL;
+
+ this.src = obj;
+ this.glTex = undefined;
+ this.glTarget = gl.TEXTURE_2D;
+ this.glFormat = gl.RGBA;
+ this.mipmaps = false;
+ this.glMinFilter = gl.LINEAR;
+ this.glMagFilter = gl.LINEAR;
+ this.glWrapS = gl.CLAMP_TO_EDGE;
+ this.glWrapT = gl.CLAMP_TO_EDGE;
+
+ // used to determine if this texture might need constant updating
+ // because it is a video or gif.
+ this.isSrcMediaElement =
+ typeof _main.default.MediaElement !== 'undefined' &&
+ obj instanceof _main.default.MediaElement;
+ this._videoPrevUpdateTime = 0;
+ this.isSrcHTMLElement =
+ typeof _main.default.Element !== 'undefined' &&
+ obj instanceof _main.default.Element &&
+ !(obj instanceof _main.default.Graphics);
+ this.isSrcP5Image = obj instanceof _main.default.Image;
+ this.isSrcP5Graphics = obj instanceof _main.default.Graphics;
+ this.isImageData = typeof ImageData !== 'undefined' && obj instanceof ImageData;
+
+ var textureData = this._getTextureDataFromSource();
+ this.width = textureData.width;
+ this.height = textureData.height;
+
+ this.init(textureData);
+ return this;
+ };
+
+ _main.default.Texture.prototype._getTextureDataFromSource = function() {
+ var textureData;
+ if (this.isSrcP5Image) {
+ // param is a p5.Image
+ textureData = this.src.canvas;
+ } else if (
+ this.isSrcMediaElement ||
+ this.isSrcP5Graphics ||
+ this.isSrcHTMLElement
+ ) {
+ // if param is a video HTML element
+ textureData = this.src.elt;
+ } else if (this.isImageData) {
+ textureData = this.src;
+ }
+ return textureData;
+ };
+
+ /**
+ * Initializes common texture parameters, creates a gl texture,
+ * tries to upload the texture for the first time if data is
+ * already available.
+ * @private
+ * @method init
+ */
+ _main.default.Texture.prototype.init = function(data) {
+ var gl = this._renderer.GL;
+ this.glTex = gl.createTexture();
+
+ this.glWrapS = this._renderer.textureWrapX;
+ this.glWrapT = this._renderer.textureWrapY;
+
+ this.setWrapMode(this.glWrapS, this.glWrapT);
+ this.bindTexture();
+
+ //gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
+
+ if (
+ this.width === 0 ||
+ this.height === 0 ||
+ (this.isSrcMediaElement && !this.src.loadedmetadata)
+ ) {
+ // assign a 1x1 empty texture initially, because data is not yet ready,
+ // so that no errors occur in gl console!
+ var tmpdata = new Uint8Array([1, 1, 1, 1]);
+ gl.texImage2D(
+ this.glTarget,
+ 0,
+ gl.RGBA,
+ 1,
+ 1,
+ 0,
+ this.glFormat,
+ gl.UNSIGNED_BYTE,
+ tmpdata
+ );
+ } else {
+ // data is ready: just push the texture!
+ gl.texImage2D(
+ this.glTarget,
+ 0,
+ this.glFormat,
+ this.glFormat,
+ gl.UNSIGNED_BYTE,
+ data
+ );
+ }
+ };
+
+ /**
+ * Checks if the source data for this texture has changed (if it's
+ * easy to do so) and reuploads the texture if necessary. If it's not
+ * possible or to expensive to do a calculation to determine wheter or
+ * not the data has occurred, this method simply re-uploads the texture.
+ * @method update
+ */
+ _main.default.Texture.prototype.update = function() {
+ var data = this.src;
+ if (data.width === 0 || data.height === 0) {
+ return false; // nothing to do!
+ }
+
+ var textureData = this._getTextureDataFromSource();
+ var updated = false;
+
+ var gl = this._renderer.GL;
+ // pull texture from data, make sure width & height are appropriate
+ if (textureData.width !== this.width || textureData.height !== this.height) {
+ updated = true;
+
+ // make sure that if the width and height of this.src have changed
+ // for some reason, we update our metadata and upload the texture again
+ this.width = textureData.width;
+ this.height = textureData.height;
+
+ if (this.isSrcP5Image) {
+ data.setModified(false);
+ } else if (this.isSrcMediaElement || this.isSrcHTMLElement) {
+ // on the first frame the metadata comes in, the size will be changed
+ // from 0 to actual size, but pixels may not be available.
+ // flag for update in a future frame.
+ // if we don't do this, a paused video, for example, may not
+ // send the first frame to texture memory.
+ data.setModified(true);
+ }
+ } else if (this.isSrcP5Image) {
+ // for an image, we only update if the modified field has been set,
+ // for example, by a call to p5.Image.set
+ if (data.isModified()) {
+ updated = true;
+ data.setModified(false);
+ }
+ } else if (this.isSrcMediaElement) {
+ // for a media element (video), we'll check if the current time in
+ // the video frame matches the last time. if it doesn't match, the
+ // video has advanced or otherwise been taken to a new frame,
+ // and we need to upload it.
+ if (data.isModified()) {
+ // p5.MediaElement may have also had set/updatePixels, etc. called
+ // on it and should be updated, or may have been set for the first
+ // time!
+ updated = true;
+ data.setModified(false);
+ } else if (data.loadedmetadata) {
+ // if the meta data has been loaded, we can ask the video
+ // what it's current position (in time) is.
+ if (this._videoPrevUpdateTime !== data.time()) {
+ // update the texture in gpu mem only if the current
+ // video timestamp does not match the timestamp of the last
+ // time we uploaded this texture (and update the time we
+ // last uploaded, too)
+ this._videoPrevUpdateTime = data.time();
+ updated = true;
+ }
+ }
+ } else if (this.isImageData) {
+ if (data._dirty) {
+ data._dirty = false;
+ updated = true;
+ }
+ } else {
+ /* data instanceof p5.Graphics, probably */
+ // there is not enough information to tell if the texture can be
+ // conditionally updated; so to be safe, we just go ahead and upload it.
+ updated = true;
+ }
+
+ if (updated) {
+ this.bindTexture();
+ gl.texImage2D(
+ this.glTarget,
+ 0,
+ this.glFormat,
+ this.glFormat,
+ gl.UNSIGNED_BYTE,
+ textureData
+ );
+ }
+
+ return updated;
+ };
+
+ /**
+ * Binds the texture to the appropriate GL target.
+ * @method bindTexture
+ */
+ _main.default.Texture.prototype.bindTexture = function() {
+ // bind texture using gl context + glTarget and
+ // generated gl texture object
+ var gl = this._renderer.GL;
+ gl.bindTexture(this.glTarget, this.glTex);
+
+ return this;
+ };
+
+ /**
+ * Unbinds the texture from the appropriate GL target.
+ * @method unbindTexture
+ */
+ _main.default.Texture.prototype.unbindTexture = function() {
+ // unbind per above, disable texturing on glTarget
+ var gl = this._renderer.GL;
+ gl.bindTexture(this.glTarget, null);
+ };
+
+ /**
+ * Sets how a texture is be interpolated when upscaled or downscaled.
+ * Nearest filtering uses nearest neighbor scaling when interpolating
+ * Linear filtering uses WebGL's linear scaling when interpolating
+ * @method setInterpolation
+ * @param {String} downScale Specifies the texture filtering when
+ * textures are shrunk. Options are LINEAR or NEAREST
+ * @param {String} upScale Specifies the texture filtering when
+ * textures are magnified. Options are LINEAR or NEAREST
+ * @todo implement mipmapping filters
+ */
+ _main.default.Texture.prototype.setInterpolation = function(downScale, upScale) {
+ var gl = this._renderer.GL;
+
+ if (downScale === constants.NEAREST) {
+ this.glMinFilter = gl.NEAREST;
+ } else {
+ this.glMinFilter = gl.LINEAR;
+ }
+
+ if (upScale === constants.NEAREST) {
+ this.glMagFilter = gl.NEAREST;
+ } else {
+ this.glMagFilter = gl.LINEAR;
+ }
+
+ this.bindTexture();
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter);
+ this.unbindTexture();
+ };
+
+ /**
+ * Sets the texture wrapping mode. This controls how textures behave
+ * when their uv's go outside of the 0 - 1 range. There are three options:
+ * CLAMP, REPEAT, and MIRROR. REPEAT & MIRROR are only available if the texture
+ * is a power of two size (128, 256, 512, 1024, etc.).
+ * @method setWrapMode
+ * @param {String} wrapX Controls the horizontal texture wrapping behavior
+ * @param {String} wrapY Controls the vertical texture wrapping behavior
+ */
+ _main.default.Texture.prototype.setWrapMode = function(wrapX, wrapY) {
+ var gl = this._renderer.GL;
+
+ // for webgl 1 we need to check if the texture is power of two
+ // if it isn't we will set the wrap mode to CLAMP
+ // webgl2 will support npot REPEAT and MIRROR but we don't check for it yet
+ var isPowerOfTwo = function isPowerOfTwo(x) {
+ return (x & (x - 1)) === 0;
+ };
+
+ var widthPowerOfTwo = isPowerOfTwo(this.width);
+ var heightPowerOfTwo = isPowerOfTwo(this.height);
+
+ if (wrapX === constants.REPEAT) {
+ if (widthPowerOfTwo && heightPowerOfTwo) {
+ this.glWrapS = gl.REPEAT;
+ } else {
+ console.warn(
+ 'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'
+ );
+
+ this.glWrapS = gl.CLAMP_TO_EDGE;
+ }
+ } else if (wrapX === constants.MIRROR) {
+ if (widthPowerOfTwo && heightPowerOfTwo) {
+ this.glWrapS = gl.MIRRORED_REPEAT;
+ } else {
+ console.warn(
+ 'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'
+ );
+
+ this.glWrapS = gl.CLAMP_TO_EDGE;
+ }
+ } else {
+ // falling back to default if didn't get a proper mode
+ this.glWrapS = gl.CLAMP_TO_EDGE;
+ }
+
+ if (wrapY === constants.REPEAT) {
+ if (widthPowerOfTwo && heightPowerOfTwo) {
+ this.glWrapT = gl.REPEAT;
+ } else {
+ console.warn(
+ 'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead'
+ );
+
+ this.glWrapT = gl.CLAMP_TO_EDGE;
+ }
+ } else if (wrapY === constants.MIRROR) {
+ if (widthPowerOfTwo && heightPowerOfTwo) {
+ this.glWrapT = gl.MIRRORED_REPEAT;
+ } else {
+ console.warn(
+ 'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead'
+ );
+
+ this.glWrapT = gl.CLAMP_TO_EDGE;
+ }
+ } else {
+ // falling back to default if didn't get a proper mode
+ this.glWrapT = gl.CLAMP_TO_EDGE;
+ }
+
+ this.bindTexture();
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.glWrapS);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.glWrapT);
+ this.unbindTexture();
+ };
+ var _default = _main.default.Texture;
+ exports.default = _default;
+ },
+ {
+ '../core/constants': 272,
+ '../core/main': 283,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.typed-array.copy-within': 212,
+ 'core-js/modules/es.typed-array.every': 213,
+ 'core-js/modules/es.typed-array.fill': 214,
+ 'core-js/modules/es.typed-array.filter': 215,
+ 'core-js/modules/es.typed-array.find': 217,
+ 'core-js/modules/es.typed-array.find-index': 216,
+ 'core-js/modules/es.typed-array.for-each': 220,
+ 'core-js/modules/es.typed-array.includes': 221,
+ 'core-js/modules/es.typed-array.index-of': 222,
+ 'core-js/modules/es.typed-array.iterator': 225,
+ 'core-js/modules/es.typed-array.join': 226,
+ 'core-js/modules/es.typed-array.last-index-of': 227,
+ 'core-js/modules/es.typed-array.map': 228,
+ 'core-js/modules/es.typed-array.reduce': 230,
+ 'core-js/modules/es.typed-array.reduce-right': 229,
+ 'core-js/modules/es.typed-array.reverse': 231,
+ 'core-js/modules/es.typed-array.set': 232,
+ 'core-js/modules/es.typed-array.slice': 233,
+ 'core-js/modules/es.typed-array.some': 234,
+ 'core-js/modules/es.typed-array.sort': 235,
+ 'core-js/modules/es.typed-array.subarray': 236,
+ 'core-js/modules/es.typed-array.to-locale-string': 237,
+ 'core-js/modules/es.typed-array.to-string': 238,
+ 'core-js/modules/es.typed-array.uint8-array': 241
+ }
+ ],
+ 340: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ function _typeof(obj) {
+ if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
+ _typeof = function _typeof(obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function _typeof(obj) {
+ return obj &&
+ typeof Symbol === 'function' &&
+ obj.constructor === Symbol &&
+ obj !== Symbol.prototype
+ ? 'symbol'
+ : typeof obj;
+ };
+ }
+ return _typeof(obj);
+ }
+ _dereq_('core-js/modules/es.symbol');
+ _dereq_('core-js/modules/es.symbol.description');
+ _dereq_('core-js/modules/es.symbol.iterator');
+ _dereq_('core-js/modules/es.array.iterator');
+ _dereq_('core-js/modules/es.object.to-string');
+ _dereq_('core-js/modules/es.regexp.exec');
+ _dereq_('core-js/modules/es.string.iterator');
+ _dereq_('core-js/modules/es.string.split');
+ _dereq_('core-js/modules/es.string.sub');
+ _dereq_('core-js/modules/web.dom-collections.iterator');
+ var _main = _interopRequireDefault(_dereq_('../core/main'));
+ var constants = _interopRequireWildcard(_dereq_('../core/constants'));
+ _dereq_('./p5.Shader');
+ _dereq_('./p5.RendererGL.Retained');
+ function _getRequireWildcardCache() {
+ if (typeof WeakMap !== 'function') return null;
+ var cache = new WeakMap();
+ _getRequireWildcardCache = function _getRequireWildcardCache() {
+ return cache;
+ };
+ return cache;
+ }
+ function _interopRequireWildcard(obj) {
+ if (obj && obj.__esModule) {
+ return obj;
+ }
+ if (obj === null || (_typeof(obj) !== 'object' && typeof obj !== 'function')) {
+ return { default: obj };
+ }
+ var cache = _getRequireWildcardCache();
+ if (cache && cache.has(obj)) {
+ return cache.get(obj);
+ }
+ var newObj = {};
+ var hasPropertyDescriptor =
+ Object.defineProperty && Object.getOwnPropertyDescriptor;
+ for (var key in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
+ var desc = hasPropertyDescriptor
+ ? Object.getOwnPropertyDescriptor(obj, key)
+ : null;
+ if (desc && (desc.get || desc.set)) {
+ Object.defineProperty(newObj, key, desc);
+ } else {
+ newObj[key] = obj[key];
+ }
+ }
+ }
+ newObj.default = obj;
+ if (cache) {
+ cache.set(obj, newObj);
+ }
+ return newObj;
+ }
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+
+ // Text/Typography
+ // @TODO:
+ _main.default.RendererGL.prototype._applyTextProperties = function() {
+ //@TODO finish implementation
+ //console.error('text commands not yet implemented in webgl');
+ };
+
+ _main.default.RendererGL.prototype.textWidth = function(s) {
+ if (this._isOpenType()) {
+ return this._textFont._textWidth(s, this._textSize);
+ }
+
+ return 0; // TODO: error
+ };
+
+ // rendering constants
+
+ // the number of rows/columns dividing each glyph
+ var charGridWidth = 9;
+ var charGridHeight = charGridWidth;
+
+ // size of the image holding the bezier stroke info
+ var strokeImageWidth = 64;
+ var strokeImageHeight = 64;
+
+ // size of the image holding the stroke indices for each row/col
+ var gridImageWidth = 64;
+ var gridImageHeight = 64;
+
+ // size of the image holding the offset/length of each row/col stripe
+ var cellImageWidth = 64;
+ var cellImageHeight = 64;
+
+ /**
+ * @private
+ * @class ImageInfos
+ * @param {Integer} width
+ * @param {Integer} height
+ *
+ * the ImageInfos class holds a list of ImageDatas of a given size.
+ */
+ function ImageInfos(width, height) {
+ this.width = width;
+ this.height = height;
+ this.infos = []; // the list of images
+
+ /**
+ *
+ * @method findImage
+ * @param {Integer} space
+ * @return {Object} contains the ImageData, and pixel index into that
+ * ImageData where the free space was allocated.
+ *
+ * finds free space of a given size in the ImageData list
+ */
+ this.findImage = function(space) {
+ var imageSize = this.width * this.height;
+ if (space > imageSize) throw new Error('font is too complex to render in 3D');
+
+ // search through the list of images, looking for one with
+ // anough unused space.
+ var imageInfo, imageData;
+ for (var ii = this.infos.length - 1; ii >= 0; --ii) {
+ var imageInfoTest = this.infos[ii];
+ if (imageInfoTest.index + space < imageSize) {
+ // found one
+ imageInfo = imageInfoTest;
+ imageData = imageInfoTest.imageData;
+ break;
+ }
+ }
+
+ if (!imageInfo) {
+ try {
+ // create a new image
+ imageData = new ImageData(this.width, this.height);
+ } catch (err) {
+ // for browsers that don't support ImageData constructors (ie IE11)
+ // create an ImageData using the old method
+ var canvas = document.getElementsByTagName('canvas')[0];
+ var created = !canvas;
+ if (!canvas) {
+ // create a temporary canvas
+ canvas = document.createElement('canvas');
+ canvas.style.display = 'none';
+ document.body.appendChild(canvas);
+ }
+ var ctx = canvas.getContext('2d');
+ if (ctx) {
+ imageData = ctx.createImageData(this.width, this.height);
+ }
+ if (created) {
+ // distroy the temporary canvas, if necessary
+ document.body.removeChild(canvas);
+ }
+ }
+ // construct & dd the new image info
+ imageInfo = { index: 0, imageData: imageData };
+ this.infos.push(imageInfo);
+ }
+
+ var index = imageInfo.index;
+ imageInfo.index += space; // move to the start of the next image
+ imageData._dirty = true;
+ return { imageData: imageData, index: index };
+ };
+ }
+
+ /**
+ * @function setPixel
+ * @param {Object} imageInfo
+ * @param {Number} r
+ * @param {Number} g
+ * @param {Number} b
+ * @param {Number} a
+ *
+ * writes the next pixel into an indexed ImageData
+ */
+ function setPixel(imageInfo, r, g, b, a) {
+ var imageData = imageInfo.imageData;
+ var pixels = imageData.data;
+ var index = imageInfo.index++ * 4;
+ pixels[index++] = r;
+ pixels[index++] = g;
+ pixels[index++] = b;
+ pixels[index++] = a;
+ }
+
+ var SQRT3 = Math.sqrt(3);
+
+ /**
+ * @private
+ * @class FontInfo
+ * @param {Object} font an opentype.js font object
+ *
+ * contains cached images and glyph information for an opentype font
+ */
+ var FontInfo = function FontInfo(font) {
+ this.font = font;
+ // the bezier curve coordinates
+ this.strokeImageInfos = new ImageInfos(strokeImageWidth, strokeImageHeight);
+ // lists of curve indices for each row/column slice
+ this.colDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight);
+ this.rowDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight);
+ // the offset & length of each row/col slice in the glyph
+ this.colCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight);
+ this.rowCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight);
+
+ // the cached information for each glyph
+ this.glyphInfos = {};
+
+ /**
+ * @method getGlyphInfo
+ * @param {Glyph} glyph the x positions of points in the curve
+ * @returns {Object} the glyphInfo for that glyph
+ *
+ * calculates rendering info for a glyph, including the curve information,
+ * row & column stripes compiled into textures.
+ */
+
+ this.getGlyphInfo = function(glyph) {
+ // check the cache
+ var gi = this.glyphInfos[glyph.index];
+ if (gi) return gi;
+
+ // get the bounding box of the glyph from opentype.js
+ var bb = glyph.getBoundingBox();
+ var xMin = bb.x1;
+ var yMin = bb.y1;
+ var gWidth = bb.x2 - xMin;
+ var gHeight = bb.y2 - yMin;
+ var cmds = glyph.path.commands;
+ // don't bother rendering invisible glyphs
+ if (gWidth === 0 || gHeight === 0 || !cmds.length) {
+ return (this.glyphInfos[glyph.index] = {});
+ }
+
+ var i;
+ var strokes = []; // the strokes in this glyph
+ var rows = []; // the indices of strokes in each row
+ var cols = []; // the indices of strokes in each column
+ for (i = charGridWidth - 1; i >= 0; --i) {
+ cols.push([]);
+ }
+ for (i = charGridHeight - 1; i >= 0; --i) {
+ rows.push([]);
+ }
+
+ /**
+ * @function push
+ * @param {Number[]} xs the x positions of points in the curve
+ * @param {Number[]} ys the y positions of points in the curve
+ * @param {Object} v the curve information
+ *
+ * adds a curve to the rows & columns that it intersects with
+ */
+ function push(xs, ys, v) {
+ var index = strokes.length; // the index of this stroke
+ strokes.push(v); // add this stroke to the list
+
+ /**
+ * @function minMax
+ * @param {Number[]} rg the list of values to compare
+ * @param {Number} min the initial minimum value
+ * @param {Number} max the initial maximum value
+ *
+ * find the minimum & maximum value in a list of values
+ */
+ function minMax(rg, min, max) {
+ for (var _i = rg.length; _i-- > 0; ) {
+ var _v = rg[_i];
+ if (min > _v) min = _v;
+ if (max < _v) max = _v;
+ }
+ return { min: min, max: max };
+ }
+
+ // loop through the rows & columns that the curve intersects
+ // adding the curve to those slices
+ var mmX = minMax(xs, 1, 0);
+ var ixMin = Math.max(Math.floor(mmX.min * charGridWidth), 0);
+ var ixMax = Math.min(Math.ceil(mmX.max * charGridWidth), charGridWidth);
+ for (var iCol = ixMin; iCol < ixMax; ++iCol) {
+ cols[iCol].push(index);
+ }
+
+ var mmY = minMax(ys, 1, 0);
+ var iyMin = Math.max(Math.floor(mmY.min * charGridHeight), 0);
+ var iyMax = Math.min(Math.ceil(mmY.max * charGridHeight), charGridHeight);
+
+ for (var iRow = iyMin; iRow < iyMax; ++iRow) {
+ rows[iRow].push(index);
+ }
+ }
+
+ /**
+ * @function clamp
+ * @param {Number} v the value to clamp
+ * @param {Number} min the minimum value
+ * @param {Number} max the maxmimum value
+ *
+ * clamps a value between a minimum & maximum value
+ */
+ function clamp(v, min, max) {
+ if (v < min) return min;
+ if (v > max) return max;
+ return v;
+ }
+
+ /**
+ * @function byte
+ * @param {Number} v the value to scale
+ *
+ * converts a floating-point number in the range 0-1 to a byte 0-255
+ */
+ function byte(v) {
+ return clamp(255 * v, 0, 255);
+ }
+
+ /**
+ * @private
+ * @class Cubic
+ * @param {Number} p0 the start point of the curve
+ * @param {Number} c0 the first control point
+ * @param {Number} c1 the second control point
+ * @param {Number} p1 the end point
+ *
+ * a cubic curve
+ */
+ function Cubic(p0, c0, c1, p1) {
+ this.p0 = p0;
+ this.c0 = c0;
+ this.c1 = c1;
+ this.p1 = p1;
+
+ /**
+ * @method toQuadratic
+ * @return {Object} the quadratic approximation
+ *
+ * converts the cubic to a quadtratic approximation by
+ * picking an appropriate quadratic control point
+ */
+ this.toQuadratic = function() {
+ return {
+ x: this.p0.x,
+ y: this.p0.y,
+ x1: this.p1.x,
+ y1: this.p1.y,
+ cx: ((this.c0.x + this.c1.x) * 3 - (this.p0.x + this.p1.x)) / 4,
+ cy: ((this.c0.y + this.c1.y) * 3 - (this.p0.y + this.p1.y)) / 4
+ };
+ };
+
+ /**
+ * @method quadError
+ * @return {Number} the error
+ *
+ * calculates the magnitude of error of this curve's
+ * quadratic approximation.
+ */
+ this.quadError = function() {
+ return (
+ _main.default.Vector.sub(
+ _main.default.Vector.sub(this.p1, this.p0),
+ _main.default.Vector.mult(
+ _main.default.Vector.sub(this.c1, this.c0),
+ 3
+ )
+ ).mag() / 2
+ );
+ };
+
+ /**
+ * @method split
+ * @param {Number} t the value (0-1) at which to split
+ * @return {Cubic} the second part of the curve
+ *
+ * splits the cubic into two parts at a point 't' along the curve.
+ * this cubic keeps its start point and its end point becomes the
+ * point at 't'. the 'end half is returned.
+ */
+ this.split = function(t) {
+ var m1 = _main.default.Vector.lerp(this.p0, this.c0, t);
+ var m2 = _main.default.Vector.lerp(this.c0, this.c1, t);
+ var mm1 = _main.default.Vector.lerp(m1, m2, t);
+
+ this.c1 = _main.default.Vector.lerp(this.c1, this.p1, t);
+ this.c0 = _main.default.Vector.lerp(m2, this.c1, t);
+ var pt = _main.default.Vector.lerp(mm1, this.c0, t);
+ var part1 = new Cubic(this.p0, m1, mm1, pt);
+ this.p0 = pt;
+ return part1;
+ };
+
+ /**
+ * @method splitInflections
+ * @return {Cubic[]} the non-inflecting pieces of this cubic
+ *
+ * returns an array containing 0, 1 or 2 cubics split resulting
+ * from splitting this cubic at its inflection points.
+ * this cubic is (potentially) altered and returned in the list.
+ */
+ this.splitInflections = function() {
+ var a = _main.default.Vector.sub(this.c0, this.p0);
+ var b = _main.default.Vector.sub(
+ _main.default.Vector.sub(this.c1, this.c0),
+ a
+ );
+ var c = _main.default.Vector.sub(
+ _main.default.Vector.sub(_main.default.Vector.sub(this.p1, this.c1), a),
+ _main.default.Vector.mult(b, 2)
+ );
+
+ var cubics = [];
+
+ // find the derivative coefficients
+ var A = b.x * c.y - b.y * c.x;
+ if (A !== 0) {
+ var B = a.x * c.y - a.y * c.x;
+ var C = a.x * b.y - a.y * b.x;
+ var disc = B * B - 4 * A * C;
+ if (disc >= 0) {
+ if (A < 0) {
+ A = -A;
+ B = -B;
+ C = -C;
+ }
+
+ var Q = Math.sqrt(disc);
+ var t0 = (-B - Q) / (2 * A); // the first inflection point
+ var t1 = (-B + Q) / (2 * A); // the second inflection point
+
+ // test if the first inflection point lies on the curve
+ if (t0 > 0 && t0 < 1) {
+ // split at the first inflection point
+ cubics.push(this.split(t0));
+ // scale t2 into the second part
+ t1 = 1 - (1 - t1) / (1 - t0);
+ }
+
+ // test if the second inflection point lies on the curve
+ if (t1 > 0 && t1 < 1) {
+ // split at the second inflection point
+ cubics.push(this.split(t1));
+ }
+ }
+ }
+
+ cubics.push(this);
+ return cubics;
+ };
+ }
+
+ /**
+ * @function cubicToQuadratics
+ * @param {Number} x0
+ * @param {Number} y0
+ * @param {Number} cx0
+ * @param {Number} cy0
+ * @param {Number} cx1
+ * @param {Number} cy1
+ * @param {Number} x1
+ * @param {Number} y1
+ * @returns {Cubic[]} an array of cubics whose quadratic approximations
+ * closely match the civen cubic.
+ *
+ * converts a cubic curve to a list of quadratics.
+ */
+ function cubicToQuadratics(x0, y0, cx0, cy0, cx1, cy1, x1, y1) {
+ // create the Cubic object and split it at its inflections
+ var cubics = new Cubic(
+ new _main.default.Vector(x0, y0),
+ new _main.default.Vector(cx0, cy0),
+ new _main.default.Vector(cx1, cy1),
+ new _main.default.Vector(x1, y1)
+ ).splitInflections();
+
+ var qs = []; // the final list of quadratics
+ var precision = 30 / SQRT3;
+
+ // for each of the non-inflected pieces of the original cubic
+ var _iteratorNormalCompletion = true;
+ var _didIteratorError = false;
+ var _iteratorError = undefined;
+ try {
+ for (
+ var _iterator = cubics[Symbol.iterator](), _step;
+ !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
+ _iteratorNormalCompletion = true
+ ) {
+ var cubic = _step.value;
+ // the cubic is iteratively split in 3 pieces:
+ // the first piece is accumulated in 'qs', the result.
+ // the last piece is accumulated in 'tail', temporarily.
+ // the middle piece is repeatedly split again, while necessary.
+ var tail = [];
+
+ var t3 = void 0;
+ for (;;) {
+ // calculate this cubic's precision
+ t3 = precision / cubic.quadError();
+ if (t3 >= 0.5 * 0.5 * 0.5) {
+ break; // not too bad, we're done
+ }
+
+ // find a split point based on the error
+ var t = Math.pow(t3, 1.0 / 3.0);
+ // split the cubic in 3
+ var start = cubic.split(t);
+ var middle = cubic.split(1 - t / (1 - t));
+
+ qs.push(start); // the first part
+ tail.push(cubic); // the last part
+ cubic = middle; // iterate on the middle piece
+ }
+
+ if (t3 < 1) {
+ // a little excess error, split the middle in two
+ qs.push(cubic.split(0.5));
+ }
+ // add the middle piece to the result
+ qs.push(cubic);
+
+ // finally add the tail, reversed, onto the result
+ Array.prototype.push.apply(qs, tail.reverse());
+ }
+ } catch (err) {
+ _didIteratorError = true;
+ _iteratorError = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
+ _iterator.return();
+ }
+ } finally {
+ if (_didIteratorError) {
+ throw _iteratorError;
+ }
+ }
+ }
+
+ return qs;
+ }
+
+ /**
+ * @function pushLine
+ * @param {Number} x0
+ * @param {Number} y0
+ * @param {Number} x1
+ * @param {Number} y1
+ *
+ * add a straight line to the row/col grid of a glyph
+ */
+ function pushLine(x0, y0, x1, y1) {
+ var mx = (x0 + x1) / 2;
+ var my = (y0 + y1) / 2;
+ push([x0, x1], [y0, y1], { x: x0, y: y0, cx: mx, cy: my });
+ }
+
+ /**
+ * @function samePoint
+ * @param {Number} x0
+ * @param {Number} y0
+ * @param {Number} x1
+ * @param {Number} y1
+ * @return {Boolean} true if the two points are sufficiently close
+ *
+ * tests if two points are close enough to be considered the same
+ */
+ function samePoint(x0, y0, x1, y1) {
+ return Math.abs(x1 - x0) < 0.00001 && Math.abs(y1 - y0) < 0.00001;
+ }
+
+ var x0, y0, xs, ys;
+ var _iteratorNormalCompletion2 = true;
+ var _didIteratorError2 = false;
+ var _iteratorError2 = undefined;
+ try {
+ for (
+ var _iterator2 = cmds[Symbol.iterator](), _step2;
+ !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
+ _iteratorNormalCompletion2 = true
+ ) {
+ var cmd = _step2.value;
+ // scale the coordinates to the range 0-1
+ var x1 = (cmd.x - xMin) / gWidth;
+ var y1 = (cmd.y - yMin) / gHeight;
+
+ // don't bother if this point is the same as the last
+ if (samePoint(x0, y0, x1, y1)) continue;
+
+ switch (cmd.type) {
+ case 'M': {
+ // move
+ xs = x1;
+ ys = y1;
+ break;
+ }
+ case 'L': {
+ // line
+ pushLine(x0, y0, x1, y1);
+ break;
+ }
+ case 'Q': {
+ // quadratic
+ var cx = (cmd.x1 - xMin) / gWidth;
+ var cy = (cmd.y1 - yMin) / gHeight;
+ push([x0, x1, cx], [y0, y1, cy], { x: x0, y: y0, cx: cx, cy: cy });
+ break;
+ }
+ case 'Z': {
+ // end
+ if (!samePoint(x0, y0, xs, ys)) {
+ // add an extra line closing the loop, if necessary
+ pushLine(x0, y0, xs, ys);
+ strokes.push({ x: xs, y: ys });
+ } else {
+ strokes.push({ x: x0, y: y0 });
+ }
+ break;
+ }
+ case 'C': {
+ // cubic
+ var cx1 = (cmd.x1 - xMin) / gWidth;
+ var cy1 = (cmd.y1 - yMin) / gHeight;
+ var cx2 = (cmd.x2 - xMin) / gWidth;
+ var cy2 = (cmd.y2 - yMin) / gHeight;
+ var qs = cubicToQuadratics(x0, y0, cx1, cy1, cx2, cy2, x1, y1);
+ for (var iq = 0; iq < qs.length; iq++) {
+ var q = qs[iq].toQuadratic();
+ push([q.x, q.x1, q.cx], [q.y, q.y1, q.cy], q);
+ }
+ break;
+ }
+ default:
+ throw new Error('unknown command type: '.concat(cmd.type));
+ }
+
+ x0 = x1;
+ y0 = y1;
+ }
+
+ // allocate space for the strokes
+ } catch (err) {
+ _didIteratorError2 = true;
+ _iteratorError2 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
+ _iterator2.return();
+ }
+ } finally {
+ if (_didIteratorError2) {
+ throw _iteratorError2;
+ }
+ }
+ }
+ var strokeCount = strokes.length;
+ var strokeImageInfo = this.strokeImageInfos.findImage(strokeCount);
+ var strokeOffset = strokeImageInfo.index;
+
+ // fill the stroke image
+ for (var il = 0; il < strokeCount; ++il) {
+ var s = strokes[il];
+ setPixel(strokeImageInfo, byte(s.x), byte(s.y), byte(s.cx), byte(s.cy));
+ }
+
+ /**
+ * @function layout
+ * @param {Number[][]} dim
+ * @param {ImageInfo[]} dimImageInfos
+ * @param {ImageInfo[]} cellImageInfos
+ * @return {Object}
+ *
+ * lays out the curves in a dimension (row or col) into two
+ * images, one for the indices of the curves themselves, and
+ * one containing the offset and length of those index spans.
+ */
+ function layout(dim, dimImageInfos, cellImageInfos) {
+ var dimLength = dim.length; // the number of slices in this dimension
+ var dimImageInfo = dimImageInfos.findImage(dimLength);
+ var dimOffset = dimImageInfo.index;
+ // calculate the total number of stroke indices in this dimension
+ var totalStrokes = 0;
+ for (var id = 0; id < dimLength; ++id) {
+ totalStrokes += dim[id].length;
+ }
+
+ // allocate space for the stroke indices
+ var cellImageInfo = cellImageInfos.findImage(totalStrokes);
+
+ // for each slice in the glyph
+ for (var _i2 = 0; _i2 < dimLength; ++_i2) {
+ var strokeIndices = dim[_i2];
+ var _strokeCount = strokeIndices.length;
+ var cellLineIndex = cellImageInfo.index;
+
+ // write the offset and count into the glyph slice image
+ setPixel(
+ dimImageInfo,
+ cellLineIndex >> 7,
+ cellLineIndex & 0x7f,
+ _strokeCount >> 7,
+ _strokeCount & 0x7f
+ );
+
+ // for each stroke index in that slice
+ for (var iil = 0; iil < _strokeCount; ++iil) {
+ // write the stroke index into the slice's image
+ var strokeIndex = strokeIndices[iil] + strokeOffset;
+ setPixel(cellImageInfo, strokeIndex >> 7, strokeIndex & 0x7f, 0, 0);
+ }
+ }
+
+ return {
+ cellImageInfo: cellImageInfo,
+ dimOffset: dimOffset,
+ dimImageInfo: dimImageInfo
+ };
+ }
+
+ // initialize the info for this glyph
+ gi = this.glyphInfos[glyph.index] = {
+ glyph: glyph,
+ uGlyphRect: [bb.x1, -bb.y1, bb.x2, -bb.y2],
+ strokeImageInfo: strokeImageInfo,
+ strokes: strokes,
+ colInfo: layout(cols, this.colDimImageInfos, this.colCellImageInfos),
+ rowInfo: layout(rows, this.rowDimImageInfos, this.rowCellImageInfos)
+ };
+
+ gi.uGridOffset = [gi.colInfo.dimOffset, gi.rowInfo.dimOffset];
+ return gi;
+ };
+ };
+
+ _main.default.RendererGL.prototype._renderText = function(p, line, x, y, maxY) {
+ if (!this._textFont || typeof this._textFont === 'string') {
+ console.log(
+ 'WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.'
+ );
+
+ return;
+ }
+ if (y >= maxY || !this._doFill) {
+ return; // don't render lines beyond our maxY position
+ }
+
+ if (!this._isOpenType()) {
+ console.log(
+ 'WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts are supported'
+ );
+
+ return p;
+ }
+
+ p.push(); // fix to #803
+
+ // remember this state, so it can be restored later
+ var doStroke = this._doStroke;
+ var drawMode = this.drawMode;
+
+ this._doStroke = false;
+ this.drawMode = constants.TEXTURE;
+
+ // get the cached FontInfo object
+ var font = this._textFont.font;
+ var fontInfo = this._textFont._fontInfo;
+ if (!fontInfo) {
+ fontInfo = this._textFont._fontInfo = new FontInfo(font);
+ }
+
+ // calculate the alignment and move/scale the view accordingly
+ var pos = this._textFont._handleAlignment(this, line, x, y);
+ var fontSize = this._textSize;
+ var scale = fontSize / font.unitsPerEm;
+ this.translate(pos.x, pos.y, 0);
+ this.scale(scale, scale, 1);
+
+ // initialize the font shader
+ var gl = this.GL;
+ var initializeShader = !this._defaultFontShader;
+ var sh = this._getFontShader();
+ sh.init();
+ sh.bindShader(); // first time around, bind the shader fully
+
+ if (initializeShader) {
+ // these are constants, really. just initialize them one-time.
+ sh.setUniform('uGridImageSize', [gridImageWidth, gridImageHeight]);
+ sh.setUniform('uCellsImageSize', [cellImageWidth, cellImageHeight]);
+ sh.setUniform('uStrokeImageSize', [strokeImageWidth, strokeImageHeight]);
+ sh.setUniform('uGridSize', [charGridWidth, charGridHeight]);
+ }
+ this._applyColorBlend(this.curFillColor);
+
+ var g = this.retainedMode.geometry['glyph'];
+ if (!g) {
+ // create the geometry for rendering a quad
+ var geom = (this._textGeom = new _main.default.Geometry(1, 1, function() {
+ for (var i = 0; i <= 1; i++) {
+ for (var j = 0; j <= 1; j++) {
+ this.vertices.push(new _main.default.Vector(j, i, 0));
+ this.uvs.push(j, i);
+ }
+ }
+ }));
+ geom.computeFaces().computeNormals();
+ g = this.createBuffers('glyph', geom);
+ }
+
+ // bind the shader buffers
+ var _iteratorNormalCompletion3 = true;
+ var _didIteratorError3 = false;
+ var _iteratorError3 = undefined;
+ try {
+ for (
+ var _iterator3 = this.retainedMode.buffers.text[Symbol.iterator](), _step3;
+ !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done);
+ _iteratorNormalCompletion3 = true
+ ) {
+ var buff = _step3.value;
+ buff._prepareBuffer(g, sh);
+ }
+ } catch (err) {
+ _didIteratorError3 = true;
+ _iteratorError3 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
+ _iterator3.return();
+ }
+ } finally {
+ if (_didIteratorError3) {
+ throw _iteratorError3;
+ }
+ }
+ }
+ this._bindBuffer(g.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
+
+ // this will have to do for now...
+ sh.setUniform('uMaterialColor', this.curFillColor);
+
+ try {
+ var dx = 0; // the x position in the line
+ var glyphPrev = null; // the previous glyph, used for kerning
+ // fetch the glyphs in the line of text
+ var glyphs = font.stringToGlyphs(line);
+ var _iteratorNormalCompletion4 = true;
+ var _didIteratorError4 = false;
+ var _iteratorError4 = undefined;
+ try {
+ for (
+ var _iterator4 = glyphs[Symbol.iterator](), _step4;
+ !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done);
+ _iteratorNormalCompletion4 = true
+ ) {
+ var glyph = _step4.value;
+ // kern
+ if (glyphPrev) dx += font.getKerningValue(glyphPrev, glyph);
+
+ var gi = fontInfo.getGlyphInfo(glyph);
+ if (gi.uGlyphRect) {
+ var rowInfo = gi.rowInfo;
+ var colInfo = gi.colInfo;
+ sh.setUniform('uSamplerStrokes', gi.strokeImageInfo.imageData);
+ sh.setUniform('uSamplerRowStrokes', rowInfo.cellImageInfo.imageData);
+ sh.setUniform('uSamplerRows', rowInfo.dimImageInfo.imageData);
+ sh.setUniform('uSamplerColStrokes', colInfo.cellImageInfo.imageData);
+ sh.setUniform('uSamplerCols', colInfo.dimImageInfo.imageData);
+ sh.setUniform('uGridOffset', gi.uGridOffset);
+ sh.setUniform('uGlyphRect', gi.uGlyphRect);
+ sh.setUniform('uGlyphOffset', dx);
+
+ sh.bindTextures(); // afterwards, only textures need updating
+
+ // draw it
+ gl.drawElements(gl.TRIANGLES, 6, this.GL.UNSIGNED_SHORT, 0);
+ }
+ dx += glyph.advanceWidth;
+ glyphPrev = glyph;
+ }
+ } catch (err) {
+ _didIteratorError4 = true;
+ _iteratorError4 = err;
+ } finally {
+ try {
+ if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
+ _iterator4.return();
+ }
+ } finally {
+ if (_didIteratorError4) {
+ throw _iteratorError4;
+ }
+ }
+ }
+ } finally {
+ // clean up
+ sh.unbindShader();
+
+ this._doStroke = doStroke;
+ this.drawMode = drawMode;
+
+ p.pop();
+ }
+
+ return p;
+ };
+ },
+ {
+ '../core/constants': 272,
+ '../core/main': 283,
+ './p5.RendererGL.Retained': 336,
+ './p5.Shader': 338,
+ 'core-js/modules/es.array.iterator': 174,
+ 'core-js/modules/es.object.to-string': 192,
+ 'core-js/modules/es.regexp.exec': 196,
+ 'core-js/modules/es.string.iterator': 201,
+ 'core-js/modules/es.string.split': 206,
+ 'core-js/modules/es.string.sub': 207,
+ 'core-js/modules/es.symbol': 211,
+ 'core-js/modules/es.symbol.description': 209,
+ 'core-js/modules/es.symbol.iterator': 210,
+ 'core-js/modules/web.dom-collections.iterator': 244
+ }
+ ],
+ 341: [
+ function(_dereq_, module, exports) {
+ module.exports = {
+ fes: {
+ autoplay:
+ "The media that tried to play (with '{{src}}') wasn't allowed to by this browser, most likely due to the browser's autoplay policy. Check out {{link}} for more information about why.",
+ checkUserDefinedFns:
+ "It seems that you may have accidentally written {{name}} instead of {{actualName}}.\n\nPlease correct it if it's not intentional.",
+ fileLoadError: {
+ bytes:
+ 'It looks like there was a problem loading your file. {{suggestion}}',
+ font: 'It looks like there was a problem loading your font. {{suggestion}}',
+ gif:
+ 'There was some trouble loading your GIF. Make sure that your GIF is using 87a or 89a encoding.',
+ image:
+ 'It looks like there was a problem loading your image. {{suggestion}}',
+ json:
+ 'It looks like there was a problem loading your JSON file. {{suggestion}}',
+ large:
+ "If your large file isn't fetched successfully, we recommend splitting the file into smaller segments and fetching those.",
+ strings:
+ 'It looks like there was a problem loading your text file. {{suggestion}}',
+ suggestion:
+ 'Try checking if the file path ({{filePath}}) is correct, hosting the file online, or running a local server. (More info at {{link}})',
+ table:
+ 'It looks like there was a problem loading your table file. {{suggestion}}',
+ xml:
+ 'It looks like there was a problem loading your XML file. {{suggestion}}'
+ },
+ friendlyParamError: {
+ type_EMPTY_VAR:
+ '{{func}}() was expecting {{formatType}} for the {{position}} parameter, received an empty variable instead. {{location}}\n\nIf not intentional, this is often a problem with scope: {{link}}',
+ type_TOO_FEW_ARGUMENTS:
+ '{{func}}() was expecting at least {{minParams}} arguments, but received only {{argCount}}. {{location}}',
+ type_TOO_MANY_ARGUMENTS:
+ '{{func}}() was expecting no more than {{maxParams}} arguments, but received {{argCount}}. {{location}}',
+ type_WRONG_TYPE:
+ '{{func}}() was expecting {{formatType}} for the {{position}} parameter, received {{argType}} instead. {{location}}'
+ },
+ globalErrors: {
+ reference: {
+ notDefined:
+ 'There\'s an error due to "{{symbol}}" not being defined in the current scope {{location}}.\n\nIf you have defined it in your code, you should check its scope, spelling, and letter-casing (JavaScript is case-sensitive). For more:\n{{url1}}\n{{url2}}'
+ },
+ stackSubseq:
+ '▶️ Called from line {{line}} in "{{func}}" in {{file}} ({{location}})\n\n',
+ stackTop:
+ '▶️ Error at line {{line}} in "{{func}}" in {{file}} ({{location}})\n\n',
+ syntax: {
+ invalidToken:
+ "There's a syntax error due to a symbol that JavaScript doesn't recognize or didn't expect at it's place.\nFor more: {{url}}",
+ unexpectedToken:
+ "There's a syntax error due to a symbol that wasn't expected at it's place.\nUsually this is due to a typo. Check the line number in the error below for anything missing/extra.\nFor more: {{url}}"
+ },
+ type: {
+ notfunc:
+ 'There\'s an error as "{{symbol}}" could not be called as a function {{location}}.\nCheck the spelling, letter-casing (Javacript is case-sensitive) and its type.\nFor more: {{url}}',
+ notfuncObj:
+ 'There\'s an error as "{{symbol}}" could not be called as a function {{location}}.\nVerify whether "{{obj}}" has "{{symbol}}" in it and check the spelling, letter-casing (Javacript is case-sensitive) and its type.\nFor more: {{url}}'
+ }
+ },
+ libraryError:
+ 'An error with message "{{error}}" occured inside the p5js library when {{func}} was called {{location}}\n\nIf not stated otherwise, it might be an issue with the arguments passed to {{func}}.',
+ location: '(on line {{line}} in {{file}} [{{location}}])',
+ misspelling:
+ 'It seems that you may have accidentally written "{{name}}" instead of "{{actualName}}" {{location}}.\n\nPlease correct it to {{actualName}} if you wish to use the {{type}} from p5.js',
+ misspelling_plural:
+ 'It seems that you may have accidentally written "{{name}}" {{location}}.\n\nYou may have meant one of the following:\n{{suggestions}}',
+ misusedTopLevel:
+ "Did you just try to use p5.js's {{symbolName}} {{symbolType}}? If so, you may want to move it into your sketch's setup() function.\n\nFor more details, see: {{link}}",
+ positions: {
+ p_1: 'first',
+ p_10: 'tenth',
+ p_11: 'eleventh',
+ p_12: 'twelfth',
+ p_2: 'second',
+ p_3: 'third',
+ p_4: 'fourth',
+ p_5: 'fifth',
+ p_6: 'sixth',
+ p_7: 'seventh',
+ p_8: 'eighth',
+ p_9: 'ninth'
+ },
+ pre: '\n🌸 p5.js says: {{message}}',
+ welcome:
+ 'Welcome! This is your friendly debugger. To turn me off, switch to using p5.min.js.',
+ wrongPreload:
+ 'An error with message "{{error}}" occured inside the p5js library when "{{func}}" was called {{location}}.\n\nIf not stated otherwise, it might be due to "{{func}}" being called from preload. Nothing besides load calls (loadImage, loadJSON, loadFont, loadStrings, etc.) should be inside the preload function.'
+ }
+ };
+ },
+ {}
+ ],
+ 342: [
+ function(_dereq_, module, exports) {
+ 'use strict';
+ Object.defineProperty(exports, '__esModule', { value: true });
+ exports.languages = exports.default = void 0;
+ var _translation = _interopRequireDefault(_dereq_('./en/translation'));
+ function _interopRequireDefault(obj) {
+ return obj && obj.__esModule ? obj : { default: obj };
+ }
+
+ // Only one language is imported above. This is intentional as other languages
+ // will be hosted online and then downloaded whenever needed
+
+ /**
+ * Here, we define a default/fallback language which we can use without internet.
+ * You won't have to change this when adding a new language.
+ *
+ * `translation` is the namespace we are using for our initial set of strings
+ */ var _default = {
+ en: {
+ translation: _translation.default
+ }
+ };
+
+ /**
+ * This is a list of languages that we have added so far.
+ * If you have just added a new language (yay!), add its key to the list below
+ * (`en` is english, `es` es español). Also add its export to
+ * dev.js, which is another file in this folder.
+ */ exports.default = _default;
+ var languages = ['en', 'es'];
+ exports.languages = languages;
+ },
+ { './en/translation': 341 }
+ ]
+ },
+ {},
+ [267]
+ )(267);
+});
diff --git a/polytree.coffee b/polytree.coffee
new file mode 100644
index 0000000..8556dba
--- /dev/null
+++ b/polytree.coffee
@@ -0,0 +1,15 @@
+# PolyTree, intended to be loaded as a module
+
+import {p5, p5loaded} from './lib/loadp5.js'
+
+sketch = (p) ->
+ p.setup = =>
+ p.createCanvas window.innerWidth, 575, p.WEBGL
+ p.background 224
+ p.ellipse 0, 0, 100, 50
+ p.ellipse p.width/4, -p.height/4, 50, 100
+
+show = () ->
+ P5 = new p5 sketch
+
+p5loaded.then show