/*! p5.js v0.5.16 October 11, 2017 */ !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.p5=a()}}(function(){var a;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g
Internally we store an array representing the ideal RGBA values in floating\npoint form, normalized from 0 to 1. From this we calculate the closest\nscreen color (RGBA levels from 0 to 255) and expose this to the renderer.
\nWe also cache normalized, floating point components of the color in various\nrepresentations as they are calculated. This is done to prevent repeating a\nconversion that has already been performed.
\n"},Setting:{name:"Setting",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Color",namespace:"",file:"src/color/setting.js",line:1,requires:["core","constants"]},Shape:{name:"Shape",submodules:{"2D Primitives":1,Curves:1,Vertex:1,"3D Models":1,"3D Primitives":1},elements:{},classes:{},fors:{p5:1},namespaces:{}},"2D Primitives":{name:"2D Primitives",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Shape",namespace:"",file:"src/core/2d_primitives.js",line:1,requires:["core","constants"]},Attributes:{name:"Attributes",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Typography",namespace:"",file:"src/core/attributes.js",line:1,requires:["core","constants"]},Constants:{name:"Constants",submodules:{},elements:{},classes:{},fors:{p5:1},namespaces:{},module:"Constants",file:"src/core/constants.js",line:1},Structure:{name:"Structure",submodules:{},elements:{},classes:{},fors:{p5:1},namespaces:{},module:"Structure",file:"src/core/core.js",line:1,requires:["constants"]},Curves:{name:"Curves",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Shape",namespace:"",file:"src/core/curves.js",line:1,requires:["core"]},Environment:{name:"Environment",submodules:{},elements:{},classes:{},fors:{p5:1},namespaces:{},module:"Environment",file:"src/core/environment.js",line:1,requires:["core","constants"]},DOM:{name:"DOM",submodules:{},elements:{},classes:{"p5.Element":1},fors:{"p5.Element":1},namespaces:{},module:"DOM",file:"src/core/p5.Element.js",line:9,description:'Base class for all elements added to a sketch, including canvas,\ngraphics buffers, and other HTML elements. Methods in blue are\nincluded in the core functionality, methods in brown are added\nwith the p5.dom\nlibrary.\nIt is not called directly, but p5.Element\nobjects are created by calling createCanvas, createGraphics,\nor in the p5.dom library, createDiv, createImg, createInput, etc.
\n'},Rendering:{name:"Rendering",submodules:{},elements:{},classes:{"p5.Graphics":1,"p5.Renderer":1},fors:{p5:1},namespaces:{},module:"Rendering",file:"src/core/p5.Renderer.js",line:10,description:"Thin wrapper around a renderer, to be used for creating a\ngraphics buffer object. Use this class if you need\nto draw into an off-screen graphics buffer. The two parameters define the\nwidth and height in pixels. The fields and methods for this class are\nextensive, but mirror the normal drawing API for p5.
\n"},Transform:{name:"Transform",submodules:{},elements:{},classes:{},fors:{p5:1},namespaces:{},module:"Transform",file:"src/core/transform.js",line:1,requires:["core","constants"]},Vertex:{name:"Vertex",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Shape",namespace:"",file:"src/core/vertex.js",line:1,requires:["core","constants"]},Data:{name:"Data",submodules:{Dictionary:1,"Array Functions":1,"String Functions":1},elements:{},classes:{"p5.TypedDict":1,"p5.StringDict":1,"p5.NumberDict":1},fors:{"p5.TypedDict":1,p5:1},namespaces:{},file:"src/data/p5.TypedDict.js",line:351},Dictionary:{name:"Dictionary",submodules:{},elements:{},classes:{"p5.TypedDict":1,"p5.StringDict":1,"p5.NumberDict":1},fors:{"p5.TypedDict":1},is_submodule:1,namespaces:{},module:"Data",namespace:"",file:"src/data/p5.TypedDict.js",line:351,requires:["core\n\nThis module defines the p5 methods for the p5 Dictionary classes\nthese classes StringDict and NumberDict are for storing and working\nwith key","value pairs"],description:"Base class for all p5.Dictionary types. More specifically\n typed Dictionary objects inherit from this
\n"},Events:{name:"Events",submodules:{Acceleration:1,Keyboard:1,Mouse:1,Touch:1},elements:{},classes:{},fors:{p5:1},namespaces:{}},Acceleration:{name:"Acceleration",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Events",namespace:"",file:"src/events/acceleration.js",line:1,requires:["core"]},Keyboard:{name:"Keyboard",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Events",namespace:"",file:"src/events/keyboard.js",line:1,requires:["core"]},Mouse:{name:"Mouse",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Events",namespace:"",file:"src/events/mouse.js",line:1,requires:["core","constants"]},Touch:{name:"Touch",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Events",namespace:"",file:"src/events/touch.js",line:1,requires:["core"]},Image:{name:"Image",submodules:{Pixels:1},elements:{},classes:{"p5.Image":1},fors:{p5:1},namespaces:{},module:"Image",file:"src/image/p5.Image.js",line:23,requires:["core"],description:"Creates a new p5.Image. A p5.Image is a canvas backed representation of an\nimage.\n
\np5 can display .gif, .jpg and .png images. Images may be displayed\nin 2D and 3D space. Before an image is used, it must be loaded with the\nloadImage() function. The p5.Image class contains fields for the width and\nheight of the image, as well as an array called pixels[] that contains the\nvalues for every pixel in the image.\n
\nThe methods described below allow easy access to the image's pixels and\nalpha channel and simplify the process of compositing.\n
\nBefore using the pixels[] array, be sure to use the loadPixels() method on\nthe image to make sure that the pixel data is properly loaded.
Table objects store data with multiple rows and columns, much\nlike in a traditional spreadsheet. Tables can be generated from\nscratch, dynamically, or using data from an existing file.
\n"},XML:{name:"XML",submodules:{},elements:{},classes:{"p5.XML":1},fors:{},is_submodule:1,namespaces:{},module:"IO",namespace:"",file:"src/io/p5.XML.js",line:11,requires:["core"],description:"XML is a representation of an XML object, able to parse XML code. Use\nloadXML() to load external XML files and create XML objects.
\n"},Math:{name:"Math",submodules:{Calculation:1,Noise:1,Random:1,Trigonometry:1},elements:{},classes:{"p5.Vector":1},fors:{p5:1},namespaces:{},module:"Math",file:"src/math/p5.Vector.js",line:13,requires:["core"],description:"A class to describe a two or three dimensional vector, specifically\na Euclidean (also known as geometric) vector. A vector is an entity\nthat has both magnitude and direction. The datatype, however, stores\nthe components of the vector (x, y for 2D, and x, y, z for 3D). The magnitude\nand direction can be accessed via the methods mag() and heading().\n
\nIn many of the p5.js examples, you will see p5.Vector used to describe a\nposition, velocity, or acceleration. For example, if you consider a rectangle\nmoving across the screen, at any given instant it has a position (a vector\nthat points from the origin to its location), a velocity (the rate at which\nthe object's position changes per time unit, expressed as a vector), and\nacceleration (the rate at which the object's velocity changes per time\nunit, expressed as a vector).\n
\nSince vectors represent groupings of values, we cannot simply use\ntraditional addition/multiplication/etc. Instead, we'll need to do some\n"vector" math, which is made easy by the methods inside the p5.Vector class.
This module defines the p5.Font class and functions for\ndrawing text to the display canvas.
\n",requires:["core","constants"]},"Array Functions":{name:"Array Functions",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Data",namespace:"",file:"src/utilities/array_functions.js",line:1,requires:["core"]},"String Functions":{name:"String Functions",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Data",namespace:"",file:"src/utilities/string_functions.js",line:1,requires:["core"]},"Time & Date":{name:"Time & Date",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"IO",namespace:"",file:"src/utilities/time_date.js",line:1,requires:["core"]},"Lights, Camera":{name:"Lights, Camera",submodules:{Camera:1,Lights:1,Material:1,Shaders:1},elements:{},classes:{"p5.Geometry":1,"p5.RendererGL":1,"p5.Shader":1,"p5.Texture":1},fors:{p5:1},namespaces:{},file:"src/webgl/p5.Texture.js",line:11},Camera:{name:"Camera",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Lights, Camera",namespace:"",file:"src/webgl/camera.js",line:1,requires:["core"]},Lights:{name:"Lights",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Lights, Camera",namespace:"",file:"src/webgl/light.js",line:1,requires:["core"]},"3D Models":{name:"3D Models",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Shape",namespace:"",file:"src/webgl/loading.js",line:1,requires:["core","p5.Geometry"]},Material:{name:"Material",submodules:{},elements:{},classes:{"p5.Texture":1},fors:{p5:1},is_submodule:1,namespaces:{},module:"Lights, Camera",namespace:"",file:"src/webgl/p5.Texture.js",line:11,requires:["core"],description:"This module defines the p5.Texture class
\n"},Shaders:{name:"Shaders",submodules:{},elements:{},classes:{"p5.Shader":1},fors:{p5:1},is_submodule:1,namespaces:{},module:"Lights, Camera",namespace:"",file:"src/webgl/p5.Shader.js",line:11,description:"This module defines the p5.Shader class
\n",requires:["core"]},"3D Primitives":{name:"3D Primitives",submodules:{},elements:{},classes:{},fors:{p5:1},is_submodule:1,namespaces:{},module:"Shape",namespace:"",file:"src/webgl/primitives.js",line:1,requires:["core","p5.Geometry"]},"p5.dom":{name:"p5.dom",submodules:{},elements:{},classes:{"p5.dom":1,"p5.MediaElement":1,"p5.File":1},fors:{"p5.dom":1,"p5.Element":1},namespaces:{},module:"p5.dom",file:"lib/addons/p5.dom.js",line:2482,description:'The web is much more than just canvas and p5.dom makes it easy to interact\nwith other HTML5 objects, including text, hyperlink, image, input, video,\naudio, and webcam.
\nThere is a set of creation methods, DOM manipulation methods, and\nan extended p5.Element that supports a range of HTML elements. See the\n\nbeyond the canvas tutorial for a full overview of how this addon works.
\nMethods and properties shown in black are part of the p5.js core, items in\nblue are part of the p5.dom library. You will need to include an extra file\nin order to access the blue functions. See the\nusing a library\nsection for information on how to include this library. p5.dom comes with\np5 complete or you can download the single file\n\nhere.
\nSee tutorial: beyond the canvas\nfor more info on how to use this libary.
\n',tag:"main",itemtype:"main"},"p5.sound":{name:"p5.sound",submodules:{},elements:{},classes:{p5:1,"p5.sound":1,"p5.SoundFile":1,"p5.Amplitude":1,"p5.FFT":1,"p5.Signal":1,"p5.Oscillator":1,"p5.SinOsc":1,"p5.TriOsc":1,"p5.SawOsc":1,"p5.SqrOsc":1,"p5.Env":1,"p5.Pulse":1,"p5.Noise":1,"p5.AudioIn":1,"p5.Effect":1,"p5.Filter":1,"p5.LowPass":1,"p5.HighPass":1,BandPass:1,"p5.Delay":1,"p5.Reverb":1,"p5.Convolver":1,"p5.Phrase":1,"p5.Part":1,"p5.Score":1,"p5.Compressor":1,"p5.SoundRecorder":1,"p5.PeakDetect":1,"p5.Gain":1,"p5.Distortion":1},fors:{"p5.sound":1},namespaces:{},module:"p5.sound",file:"lib/addons/p5.sound.js",line:10410,description:'p5.sound extends p5 with Web Audio functionality including audio input,\nplayback, analysis and synthesis.\n
\np5.SoundFile: Load and play sound files.
\np5.Amplitude: Get the current volume of a sound.
\np5.AudioIn: Get sound from an input source, typically\n a computer microphone.
\np5.FFT: Analyze the frequency of sound. Returns\n results from the frequency spectrum or time domain (waveform).
\np5.Oscillator: Generate Sine,\n Triangle, Square and Sawtooth waveforms. Base class of\n p5.Noise and p5.Pulse.\n
\np5.Env: An Envelope is a series\n of fades over time. Often used to control an object's\n output gain level as an "ADSR Envelope" (Attack, Decay,\n Sustain, Release). Can also modulate other parameters.
\np5.Delay: A delay effect with\n parameters for feedback, delayTime, and lowpass filter.
\np5.Filter: Filter the frequency range of a\n sound.\n
\np5.Reverb: Add reverb to a sound by specifying\n duration and decay.
\np5.Convolver: Extends\np5.Reverb to simulate the sound of real\n physical spaces through convolution.
\np5.SoundRecorder: Record sound for playback\n / save the .wav file.\np5.Phrase, p5.Part and\np5.Score: Compose musical sequences.\n
\np5.sound is on GitHub.\nDownload the latest version\nhere.
Each color stores the color mode and level maxes that applied at the\ntime of its construction. These are used to interpret the input arguments\n(at construction and later for that instance of color) and to format the\noutput e.g. when saturation() is requested.
\nInternally we store an array representing the ideal RGBA values in floating\npoint form, normalized from 0 to 1. From this we calculate the closest\nscreen color (RGBA levels from 0 to 255) and expose this to the renderer.
\nWe also cache normalized, floating point components of the color in various\nrepresentations as they are calculated. This is done to prevent repeating a\nconversion that has already been performed.
\n",is_constructor:1},"p5.Element":{name:"p5.Element",shortname:"p5.Element",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"DOM",submodule:"DOM",namespace:"",file:"src/core/p5.Element.js",line:9,description:'Base class for all elements added to a sketch, including canvas,\ngraphics buffers, and other HTML elements. Methods in blue are\nincluded in the core functionality, methods in brown are added\nwith the p5.dom\nlibrary.\nIt is not called directly, but p5.Element\nobjects are created by calling createCanvas, createGraphics,\nor in the p5.dom library, createDiv, createImg, createInput, etc.
\n',is_constructor:1,params:[{name:"elt",description:"DOM node that is wrapped
\n",type:"String"},{name:"pInst",description:"pointer to p5 instance
\n",type:"P5",optional:!0}]},"p5.Graphics":{name:"p5.Graphics",shortname:"p5.Graphics",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Rendering",submodule:"Rendering",namespace:"",file:"src/core/p5.Graphics.js",line:10,description:"Thin wrapper around a renderer, to be used for creating a\ngraphics buffer object. Use this class if you need\nto draw into an off-screen graphics buffer. The two parameters define the\nwidth and height in pixels. The fields and methods for this class are\nextensive, but mirror the normal drawing API for p5.
\n",is_constructor:1,extends:"p5.Element",params:[{name:"w",description:"width
\n",type:"Number"},{name:"h",description:"height
\n",type:"Number"},{name:"renderer",description:"the renderer to use, either P2D or WEBGL
\n",type:"Constant"},{name:"pInst",description:"pointer to p5 instance
\n",type:"P5",optional:!0}]},"p5.Renderer":{name:"p5.Renderer",shortname:"p5.Renderer",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Rendering",submodule:"Rendering",namespace:"",file:"src/core/p5.Renderer.js",line:10,description:"Main graphics and rendering context, as well as the base API\nimplementation for p5.js "core". To be used as the superclass for\nRenderer2D and Renderer3D classes, respecitvely.
\n",is_constructor:1,extends:"p5.Element",params:[{name:"elt",description:"DOM node that is wrapped
\n",type:"String"},{name:"pInst",description:"pointer to p5 instance
\n",type:"P5",optional:!0},{name:"isMainCanvas",description:"whether we're using it as main canvas
\n",type:"Boolean",optional:!0}]},"p5.TypedDict":{name:"p5.TypedDict",shortname:"p5.TypedDict",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Data",submodule:"Dictionary",namespace:"",file:"src/data/p5.TypedDict.js",line:48,description:"Base class for all p5.Dictionary types. More specifically\n typed Dictionary objects inherit from this
\n",is_constructor:1},"p5.StringDict":{name:"p5.StringDict",shortname:"p5.StringDict",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Data",submodule:"Dictionary",namespace:"",file:"src/data/p5.TypedDict.js",line:330,description:"A Dictionary class for Strings.
\n",is_constructor:1,extends:"p5.TypedDict"},"p5.NumberDict":{name:"p5.NumberDict",shortname:"p5.NumberDict",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Data",submodule:"Dictionary",namespace:"",file:"src/data/p5.TypedDict.js",line:351,description:"A simple Dictionary class for Numbers.
\n",is_constructor:1,extends:"p5.TypedDict"},"p5.Image":{name:"p5.Image",shortname:"p5.Image",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Image",submodule:"Image",namespace:"",file:"src/image/p5.Image.js",line:23, description:"Creates a new p5.Image. A p5.Image is a canvas backed representation of an\nimage.\n
\np5 can display .gif, .jpg and .png images. Images may be displayed\nin 2D and 3D space. Before an image is used, it must be loaded with the\nloadImage() function. The p5.Image class contains fields for the width and\nheight of the image, as well as an array called pixels[] that contains the\nvalues for every pixel in the image.\n
\nThe methods described below allow easy access to the image's pixels and\nalpha channel and simplify the process of compositing.\n
\nBefore using the pixels[] array, be sure to use the loadPixels() method on\nthe image to make sure that the pixel data is properly loaded.
Table objects store data with multiple rows and columns, much\nlike in a traditional spreadsheet. Tables can be generated from\nscratch, dynamically, or using data from an existing file.
\n",is_constructor:1,params:[{name:"rows",description:"An array of p5.TableRow objects
\n",type:"p5.TableRow[]",optional:!0}]},"p5.TableRow":{name:"p5.TableRow",shortname:"p5.TableRow",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"IO",submodule:"Table",namespace:"",file:"src/io/p5.TableRow.js",line:11,description:"A TableRow object represents a single row of data values,\nstored in columns, from a table.
\nA Table Row contains both an ordered array, and an unordered\nJSON object.
\n",is_constructor:1,params:[{name:"str",description:"optional: populate the row with a\n string of values, separated by the\n separator
\n",type:"String",optional:!0},{name:"separator",description:"comma separated values (csv) by default
\n",type:"String",optional:!0}]},"p5.XML":{name:"p5.XML",shortname:"p5.XML",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"IO",submodule:"XML",namespace:"",file:"src/io/p5.XML.js",line:11,description:"XML is a representation of an XML object, able to parse XML code. Use\nloadXML() to load external XML files and create XML objects.
\n",is_constructor:1,example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var children = xml.getChildren("animal");\n\n for (var i = 0; i < children.length; i++) {\n var id = children[i].getNum("id");\n var coloring = children[i].getString("species");\n var name = children[i].getContent();\n print(id + ", " + coloring + ", " + name);\n }\n}\n\n// Sketch prints:\n// 0, Capra hircus, Goat\n// 1, Panthera pardus, Leopard\n// 2, Equus zebra, Zebra\n
A class to describe a two or three dimensional vector, specifically\na Euclidean (also known as geometric) vector. A vector is an entity\nthat has both magnitude and direction. The datatype, however, stores\nthe components of the vector (x, y for 2D, and x, y, z for 3D). The magnitude\nand direction can be accessed via the methods mag() and heading().\n
\nIn many of the p5.js examples, you will see p5.Vector used to describe a\nposition, velocity, or acceleration. For example, if you consider a rectangle\nmoving across the screen, at any given instant it has a position (a vector\nthat points from the origin to its location), a velocity (the rate at which\nthe object's position changes per time unit, expressed as a vector), and\nacceleration (the rate at which the object's velocity changes per time\nunit, expressed as a vector).\n
\nSince vectors represent groupings of values, we cannot simply use\ntraditional addition/multiplication/etc. Instead, we'll need to do some\n"vector" math, which is made easy by the methods inside the p5.Vector class.
x component of the vector
\n",type:"Number",optional:!0},{name:"y",description:"y component of the vector
\n",type:"Number",optional:!0},{name:"z",description:"z component of the vector
\n",type:"Number",optional:!0}],example:["\n\nvar v1 = createVector(40, 50);\nvar v2 = createVector(40, 50);\n\nellipse(v1.x, v1.y, 50, 50);\nellipse(v2.x, v2.y, 50, 50);\nv1.add(v2);\nellipse(v1.x, v1.y, 50, 50);\n
\nBase class for font handling
\n",is_constructor:1,params:[{name:"pInst",description:"pointer to p5 instance
\n",type:"P5",optional:!0}]},"p5.Geometry":{name:"p5.Geometry",shortname:"p5.Geometry",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Lights, Camera",namespace:"",file:"src/webgl/p5.Geometry.js",line:6,description:"p5 Geometry class
\n",is_constructor:1,params:[{name:"vertData",description:"callback function or Object\n containing routine(s) for vertex data generation
\n",type:"Function | Object"},{name:"detailX",description:"number of vertices on horizontal surface
\n",type:"Number",optional:!0},{name:"detailY",description:"number of vertices on horizontal surface
\n",type:"Number",optional:!0},{name:"callback",description:"function to call upon object instantiation.
\n",type:"Function",optional:!0}]},"p5.RendererGL":{name:"p5.RendererGL",shortname:"p5.RendererGL",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Lights, Camera",namespace:"",file:"src/webgl/p5.RendererGL.js",line:36,description:"3D graphics class
\n",is_constructor:1,extends:"p5.Renderer",todo:["extend class to include public method for offscreen\nrendering (FBO)."]},"p5.Shader":{name:"p5.Shader",shortname:"p5.Shader",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Lights, Camera",submodule:"Shaders",namespace:"",file:"src/webgl/p5.Shader.js",line:11,description:"Shader class for WEBGL Mode
\n",is_constructor:1,params:[{name:"renderer",description:"an instance of p5.RendererGL that\nwill provide the GL context for this new p5.Shader
\n",type:"p5.RendererGL"},{name:"vertSrc",description:"source code for the vertex shader (as a string)
\n",type:"String"},{name:"fragSrc",description:"source code for the fragment shader (as a string)
\n",type:"String"}]},"p5.Texture":{name:"p5.Texture",shortname:"p5.Texture",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"Lights, Camera",submodule:"Material",namespace:"",file:"src/webgl/p5.Texture.js",line:11,description:"Texture class for WEBGL Mode
\n",is_constructor:1,params:[{name:"renderer",description:"an instance of p5.RendererGL that\nwill provide the GL context for this new p5.Texture
\n",type:"p5.RendererGL"},{name:"obj",description:"the\nobject containing the image data to store in the texture.
\n",type:"p5.Image|p5.Graphics|p5.Element|p5.MediaElement",optional:!0}]},"p5.dom":{name:"p5.dom",shortname:"p5.dom",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.dom",submodule:"p5.dom",namespace:""},"p5.MediaElement":{name:"p5.MediaElement",shortname:"p5.MediaElement",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.dom",submodule:"p5.dom",namespace:"",file:"lib/addons/p5.dom.js",line:1728,description:"Extends p5.Element to handle audio and video. In addition to the methods\nof p5.Element, it also contains methods for controlling media. It is not\ncalled directly, but p5.MediaElements are created by calling createVideo,\ncreateAudio, and createCapture.
\n",is_constructor:1,params:[{name:"elt",description:"DOM node that is wrapped
\n",type:"String"}]},"p5.File":{name:"p5.File",shortname:"p5.File",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.dom",submodule:"p5.dom",namespace:"",file:"lib/addons/p5.dom.js",line:2482,description:"Base class for a file\nUsing this for createFileInput
\n",is_constructor:1,params:[{name:"file",description:"File that is wrapped
\n",type:"File"}]},"p5.sound":{name:"p5.sound",shortname:"p5.sound",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:""},"p5.SoundFile":{name:"p5.SoundFile",shortname:"p5.SoundFile",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:754,description:"SoundFile object with a path to a file.
\n\nThe p5.SoundFile may not be available immediately because\nit loads the file information asynchronously.
\n\nTo do something with the sound as soon as it loads\npass the name of a function as the second parameter.
\n\nOnly one file path is required. However, audio file formats\n(i.e. mp3, ogg, wav and m4a/aac) are not supported by all\nweb browsers. If you want to ensure compatability, instead of a single\nfile path, you may include an Array of filepaths, and the browser will\nchoose a format that works.
",is_constructor:1,params:[{name:"path",description:"path to a sound file (String). Optionally,\n you may include multiple file formats in\n an array. Alternately, accepts an object\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:!0},{name:"errorCallback",description:"Name of a function to call if file fails to\n load. This function will receive an error or\n XMLHttpRequest object with information\n about what went wrong.
\n",type:"Function",optional:!0},{name:"whileLoadingCallback",description:"Name of a function to call while file\n is loading. That function will\n receive progress of the request to\n load the sound file\n (between 0 and 1) as its first\n parameter. This progress\n does not account for the additional\n time needed to decode the audio data.
\n",type:"Function",optional:!0}],example:["\n\n\nfunction preload() {\n soundFormats('mp3', 'ogg');\n mySound = loadSound('assets/doorbell.mp3');\n}\n\nfunction setup() {\n mySound.setVolume(0.1);\n mySound.play();\n}\n\n
Amplitude measures volume between 0.0 and 1.0.\nListens to all p5sound by default, or use setInput()\nto listen to a specific sound source. Accepts an optional\nsmoothing value, which defaults to 0.
\n",is_constructor:1,params:[{name:"smoothing",description:"between 0.0 and .999 to smooth\n amplitude readings (defaults to 0)
\n",type:"Number",optional:!0}],example:["\n\nvar sound, amplitude, cnv;\n\nfunction preload(){\n sound = loadSound('assets/beat.mp3');\n}\nfunction setup() {\n cnv = createCanvas(100,100);\n amplitude = new p5.Amplitude();\n\n // start / stop the sound when canvas is clicked\n cnv.mouseClicked(function() {\n if (sound.isPlaying() ){\n sound.stop();\n } else {\n sound.play();\n }\n });\n}\nfunction draw() {\n background(0);\n fill(255);\n var level = amplitude.getLevel();\n var size = map(level, 0, 1, 0, 200);\n ellipse(width/2, height/2, size, size);\n}\n\n
FFT (Fast Fourier Transform) is an analysis algorithm that\nisolates individual\n\naudio frequencies within a waveform.
\n\nOnce instantiated, a p5.FFT object can return an array based on\ntwo types of analyses:
• FFT.waveform()
computes\namplitude values along the time domain. The array indices correspond\nto samples across a brief moment in time. Each value represents\namplitude of the waveform at that sample of time.
\n• FFT.analyze()
computes amplitude values along the\nfrequency domain. The array indices correspond to frequencies (i.e.\npitches), from the lowest to the highest that humans can hear. Each\nvalue represents amplitude at that slice of the frequency spectrum.\nUse with getEnergy()
to measure amplitude at specific\nfrequencies, or within a range of frequencies.
FFT analyzes a very short snapshot of sound called a sample\nbuffer. It returns an array of amplitude measurements, referred\nto as bins
. The array is 1024 bins long by default.\nYou can change the bin array length, but it must be a power of 2\nbetween 16 and 1024 in order for the FFT algorithm to function\ncorrectly. The actual size of the FFT buffer is twice the\nnumber of bins, so given a standard sample rate, the buffer is\n2048/44100 seconds long.
Smooth results of Freq Spectrum.\n 0.0 < smoothing < 1.0.\n Defaults to 0.8.
\n",type:"Number",optional:!0},{name:"bins",description:"Length of resulting array.\n Must be a power of two between\n 16 and 1024. Defaults to 1024.
\n",type:"Number",optional:!0}],example:["\n\nfunction preload(){\n sound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup(){\n var cnv = createCanvas(100,100);\n cnv.mouseClicked(togglePlay);\n fft = new p5.FFT();\n sound.amp(0.2);\n}\n\nfunction draw(){\n background(0);\n\n var spectrum = fft.analyze();\n noStroke();\n fill(0,255,0); // spectrum is green\n for (var i = 0; i< spectrum.length; i++){\n var x = map(i, 0, spectrum.length, 0, width);\n var h = -height + map(spectrum[i], 0, 255, height, 0);\n rect(x, height, width / spectrum.length, h )\n }\n\n var waveform = fft.waveform();\n noFill();\n beginShape();\n stroke(255,0,0); // waveform is red\n strokeWeight(1);\n for (var i = 0; i< waveform.length; i++){\n var x = map(i, 0, waveform.length, 0, width);\n var y = map( waveform[i], -1, 1, 0, height);\n vertex(x,y);\n }\n endShape();\n\n text('click to play/pause', 4, 10);\n}\n\n// fade sound if mouse is over canvas\nfunction togglePlay() {\n if (sound.isPlaying()) {\n sound.pause();\n } else {\n sound.loop();\n }\n}\n
p5.Signal is a constant audio-rate signal used by p5.Oscillator\nand p5.Envelope for modulation math.
\n\nThis is necessary because Web Audio is processed on a seprate clock.\nFor example, the p5 draw loop runs about 60 times per second. But\nthe audio clock must process samples 44100 times per second. If we\nwant to add a value to each of those samples, we can't do it in the\ndraw loop, but we can do it by adding a constant-rate audio signal.This class mostly functions behind the scenes in p5.sound, and returns\na Tone.Signal from the Tone.js library by Yotam Mann.\nIf you want to work directly with audio signals for modular\nsynthesis, check out\ntone.js.
",is_constructor:1,return:{description:"A Signal object from the Tone.js library",type:"Tone.Signal"},example:["\n\nfunction setup() {\n carrier = new p5.Oscillator('sine');\n carrier.amp(1); // set amplitude\n carrier.freq(220); // set frequency\n carrier.start(); // start oscillating\n\n modulator = new p5.Oscillator('sawtooth');\n modulator.disconnect();\n modulator.amp(1);\n modulator.freq(4);\n modulator.start();\n\n // Modulator's default amplitude range is -1 to 1.\n // Multiply it by -200, so the range is -200 to 200\n // then add 220 so the range is 20 to 420\n carrier.freq( modulator.mult(-200).add(220) );\n}\n
Creates a signal that oscillates between -1.0 and 1.0.\nBy default, the oscillation takes the form of a sinusoidal\nshape ('sine'). Additional types include 'triangle',\n'sawtooth' and 'square'. The frequency defaults to\n440 oscillations per second (440Hz, equal to the pitch of an\n'A' note).
\n\nSet the type of oscillation with setType(), or by instantiating a\nspecific oscillator: p5.SinOsc, p5.TriOsc, p5.SqrOsc, or p5.SawOsc.\n
',is_constructor:1,params:[{name:"freq",description:"frequency defaults to 440Hz
\n",type:"Number",optional:!0},{name:"type",description:"type of oscillator. Options:\n 'sine' (default), 'triangle',\n 'sawtooth', 'square'
\n",type:"String",optional:!0}],example:["\n\nvar osc;\nvar playing = false;\n\nfunction setup() {\n backgroundColor = color(255,0,255);\n textAlign(CENTER);\n\n osc = new p5.Oscillator();\n osc.setType('sine');\n osc.freq(240);\n osc.amp(0);\n osc.start();\n}\n\nfunction draw() {\n background(backgroundColor)\n text('click to play', width/2, height/2);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY < height && mouseY > 0) {\n if (!playing) {\n // ramp amplitude to 0.5 over 0.1 seconds\n osc.amp(0.5, 0.05);\n playing = true;\n backgroundColor = color(0,255,255);\n } else {\n // ramp amplitude to 0 over 0.5 seconds\n osc.amp(0, 0.5);\n playing = false;\n backgroundColor = color(255,0,255);\n }\n }\n}\n
Constructor: new p5.SinOsc()
.\nThis creates a Sine Wave Oscillator and is\nequivalent to new p5.Oscillator('sine')\n
or creating a p5.Oscillator and then calling\nits method setType('sine')
.\nSee p5.Oscillator for methods.
Set the frequency
\n",type:"Number",optional:!0}]},"p5.TriOsc":{name:"p5.TriOsc",shortname:"p5.TriOsc",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:4871,description:"Constructor: new p5.TriOsc()
.\nThis creates a Triangle Wave Oscillator and is\nequivalent to new p5.Oscillator('triangle')\n
or creating a p5.Oscillator and then calling\nits method setType('triangle')
.\nSee p5.Oscillator for methods.
Set the frequency
\n",type:"Number",optional:!0}]},"p5.SawOsc":{name:"p5.SawOsc",shortname:"p5.SawOsc",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:4888,description:"Constructor: new p5.SawOsc()
.\nThis creates a SawTooth Wave Oscillator and is\nequivalent to new p5.Oscillator('sawtooth')\n
or creating a p5.Oscillator and then calling\nits method setType('sawtooth')
.\nSee p5.Oscillator for methods.
Set the frequency
\n",type:"Number",optional:!0}]},"p5.SqrOsc":{name:"p5.SqrOsc",shortname:"p5.SqrOsc",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:4905,description:"Constructor: new p5.SqrOsc()
.\nThis creates a Square Wave Oscillator and is\nequivalent to new p5.Oscillator('square')\n
or creating a p5.Oscillator and then calling\nits method setType('square')
.\nSee p5.Oscillator for methods.
Set the frequency
\n",type:"Number",optional:!0}]},"p5.Env":{name:"p5.Env",shortname:"p5.Env",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:5280,description:'Envelopes are pre-defined amplitude distribution over time.\nTypically, envelopes are used to control the output volume\nof an object, a series of fades referred to as Attack, Decay,\nSustain and Release (\nADSR\n). Envelopes can also control other Web Audio Parameters—for example, a p5.Env can\ncontrol an Oscillator's frequency like this: osc.freq(env)
.
Use setRange
to change the attack/release level.\nUse setADSR
to change attackTime, decayTime, sustainPercent and releaseTime.
Use the play
method to play the entire envelope,\nthe ramp
method for a pingable trigger,\nor triggerAttack
/\ntriggerRelease
to trigger noteOn/noteOff.
\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv(){\n env.play();\n}\n
Creates a Pulse object, an oscillator that implements\nPulse Width Modulation.\nThe pulse is created with two oscillators.\nAccepts a parameter for frequency, and to set the\nwidth between the pulses. See \np5.Oscillator
for a full list of methods.
Frequency in oscillations per second (Hz)
\n",type:"Number",optional:!0},{name:"w",description:"Width between the pulses (0 to 1.0,\n defaults to 0)
\n",type:"Number",optional:!0}],example:["\n\nvar pulse;\nfunction setup() {\n background(0);\n\n // Create and start the pulse wave oscillator\n pulse = new p5.Pulse();\n pulse.amp(0.5);\n pulse.freq(220);\n pulse.start();\n}\n\nfunction draw() {\n var w = map(mouseX, 0, width, 0, 1);\n w = constrain(w, 0, 1);\n pulse.width(w)\n}\n
Noise is a type of oscillator that generates a buffer with random values.
\n",extends:"p5.Oscillator",is_constructor:1,params:[{name:"type",description:"Type of noise can be 'white' (default),\n 'brown' or 'pink'.
\n",type:"String"}]},"p5.AudioIn":{name:"p5.AudioIn",shortname:"p5.AudioIn",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:6439,description:'Get audio from an input, i.e. your computer's microphone.
\n\nTurn the mic on/off with the start() and stop() methods. When the mic\nis on, its volume can be measured with getLevel or by connecting an\nFFT object.
\n\nIf you want to hear the AudioIn, use the .connect() method.\nAudioIn does not connect to p5.sound output by default to prevent\nfeedback.
\n\nNote: This uses the getUserMedia/\nStream API, which is not supported by certain browsers. Access in Chrome browser\nis limited to localhost and https, but access over http may be limited.
',is_constructor:1,params:[{name:"errorCallback",description:"A function to call if there is an error\n accessing the AudioIn. For example,\n Safari and iOS devices do not\n currently allow microphone access.
\n",type:"Function",optional:!0}],example:["\n\nvar mic;\nfunction setup(){\n mic = new p5.AudioIn()\n mic.start();\n}\nfunction draw(){\n background(0);\n micLevel = mic.getLevel();\n ellipse(width/2, constrain(height-micLevel*height*5, 0, height), 10, 10);\n}\n
Effect is a base class for audio effects in p5.
\nThis module handles the nodes and methods that are \ncommon and useful for current and future effects.
This class is extended by p5.Distortion, \np5.Compressor,\np5.Delay, \np5.Filter, \np5.Reverb.
\n',is_constructor:1,params:[{name:"ac",description:"Reference to the audio context of the p5 object
\n",type:"Object",optional:!0},{name:"input",description:"Gain Node effect wrapper
\n",type:"WebAudioNode",optional:!0},{name:"output",description:"Gain Node effect wrapper
\n",type:"WebAudioNode",optional:!0},{name:"_drywet",description:"Tone.JS CrossFade node (defaults to value: 1)
\n",type:"Object",optional:!0},{name:"wet",description:"Effects that extend this class should connect\n to the wet signal to this gain node, so that dry and wet \n signals are mixed properly.
\n",type:"WebAudioNode",optional:!0}]},"p5.Filter":{name:"p5.Filter",shortname:"p5.Filter",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:7825,description:'A p5.Filter uses a Web Audio Biquad Filter to filter\nthe frequency response of an input source. Subclasses\ninclude:
\np5.LowPass
:\nAllows frequencies below the cutoff frequency to pass through,\nand attenuates frequencies above the cutoff.p5.HighPass
:\nThe opposite of a lowpass filter. p5.BandPass
:\nAllows a range of frequencies to pass through and attenuates\nthe frequencies below and above this frequency range.The .res()
method controls either width of the\nbandpass, or resonance of the low/highpass cutoff frequency.
This class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.
'lowpass' (default), 'highpass', 'bandpass'
\n",type:"String",optional:!0}],example:["\n\nvar fft, noise, filter;\n\nfunction setup() {\n fill(255, 40, 255);\n\n filter = new p5.BandPass();\n\n noise = new p5.Noise();\n // disconnect unfiltered noise,\n // and connect to filter\n noise.disconnect();\n noise.connect(filter);\n noise.start();\n\n fft = new p5.FFT();\n}\n\nfunction draw() {\n background(30);\n\n // set the BandPass frequency based on mouseX\n var freq = map(mouseX, 0, width, 20, 10000);\n filter.freq(freq);\n // give the filter a narrow band (lower res = wider bandpass)\n filter.res(50);\n\n // draw filtered spectrum\n var spectrum = fft.analyze();\n noStroke();\n for (var i = 0; i < spectrum.length; i++) {\n var x = map(i, 0, spectrum.length, 0, width);\n var h = -height + map(spectrum[i], 0, 255, height, 0);\n rect(x, height, width/spectrum.length, h);\n }\n\n isMouseOverCanvas();\n}\n\nfunction isMouseOverCanvas() {\n var mX = mouseX, mY = mouseY;\n if (mX > 0 && mX < width && mY < height && mY > 0) {\n noise.amp(0.5, 0.2);\n } else {\n noise.amp(0, 0.2);\n }\n}\n
Constructor: new p5.LowPass()
Filter.\nThis is the same as creating a p5.Filter and then calling\nits method setType('lowpass')
.\nSee p5.Filter for methods.
Constructor: new p5.HighPass()
Filter.\nThis is the same as creating a p5.Filter and then calling\nits method setType('highpass')
.\nSee p5.Filter for methods.
Constructor: new p5.BandPass()
Filter.\nThis is the same as creating a p5.Filter and then calling\nits method setType('bandpass')
.\nSee p5.Filter for methods.
Delay is an echo effect. It processes an existing sound source,\nand outputs a delayed version of that sound. The p5.Delay can\nproduce different effects depending on the delayTime, feedback,\nfilter, and type. In the example below, a feedback of 0.5 (the\ndefaul value) will produce a looping delay that decreases in\nvolume by 50% each repeat. A filter will cut out the high\nfrequencies so that the delay does not sound as piercing as the\noriginal source.
\nThis class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.
\nvar noise, env, delay;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n noise = new p5.Noise('brown');\n noise.amp(0);\n noise.start();\n\n delay = new p5.Delay();\n\n // delay.process() accepts 4 parameters:\n // source, delayTime, feedback, filter frequency\n // play with these numbers!!\n delay.process(noise, .12, .7, 2300);\n\n // play the noise with an envelope,\n // a series of fades ( time / value pairs )\n env = new p5.Env(.01, 0.2, .2, .1);\n}\n\n// mouseClick triggers envelope\nfunction mouseClicked() {\n // is mouse over canvas?\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n env.play(noise);\n }\n}\n
Reverb adds depth to a sound through a large number of decaying\nechoes. It creates the perception that sound is occurring in a\nphysical space. The p5.Reverb has paramters for Time (how long does the\nreverb last) and decayRate (how much the sound decays with each echo)\nthat can be set with the .set() or .process() methods. The p5.Convolver\nextends p5.Reverb allowing you to recreate the sound of actual physical\nspaces through convolution.
\nThis class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.
\nvar soundFile, reverb;\nfunction preload() {\n soundFile = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n reverb = new p5.Reverb();\n soundFile.disconnect(); // so we'll only hear reverb...\n\n // connect soundFile to reverb, process w/\n // 3 second reverbTime, decayRate of 2%\n reverb.process(soundFile, 3, 2);\n soundFile.play();\n}\n
p5.Convolver extends p5.Reverb. It can emulate the sound of real\nphysical spaces through a process called \nconvolution.
\n\nConvolution multiplies any audio input by an "impulse response"\nto simulate the dispersion of sound over time. The impulse response is\ngenerated from an audio file that you provide. One way to\ngenerate an impulse response is to pop a balloon in a reverberant space\nand record the echo. Convolution can also be used to experiment with\nsound.
\n\nUse the method createConvolution(path)
to instantiate a\np5.Convolver with a path to your impulse response audio file.
path to a sound file
\n",type:"String"},{name:"callback",description:"function to call when loading succeeds
\n",type:"Function",optional:!0},{name:"errorCallback",description:"function to call if loading fails.\n This function will receive an error or\n XMLHttpRequest object with information\n about what went wrong.
\n",type:"Function",optional:!0}],example:["\n\nvar cVerb, sound;\nfunction preload() {\n // We have both MP3 and OGG versions of all sound assets\n soundFormats('ogg', 'mp3');\n\n // Try replacing 'bx-spring' with other soundfiles like\n // 'concrete-tunnel' 'small-plate' 'drum' 'beatbox'\n cVerb = createConvolver('assets/bx-spring.mp3');\n\n // Try replacing 'Damscray_DancingTiger' with\n // 'beat', 'doorbell', lucky_dragons_-_power_melody'\n sound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n // disconnect from master output...\n sound.disconnect();\n\n // ...and process with cVerb\n // so that we only hear the convolution\n cVerb.process(sound);\n\n sound.play();\n}\n
A phrase is a pattern of musical events over time, i.e.\na series of notes and rests.
\n\nPhrases must be added to a p5.Part for playback, and\neach part can play multiple phrases at the same time.\nFor example, one Phrase might be a kick drum, another\ncould be a snare, and another could be the bassline.
\n\nThe first parameter is a name so that the phrase can be\nmodified or deleted later. The callback is a a function that\nthis phrase will call at every step—for example it might be\ncalled playNote(value){}
. The array determines\nwhich value is passed into the callback at each step of the\nphrase. It can be numbers, an object with multiple numbers,\nor a zero (0) indicates a rest so the callback won't be called).
Name so that you can access the Phrase.
\n",type:"String"},{name:"callback",description:"The name of a function that this phrase\n will call. Typically it will play a sound,\n and accept two parameters: a time at which\n to play the sound (in seconds from now),\n and a value from the sequence array. The\n time should be passed into the play() or\n start() method to ensure precision.
\n",type:"Function"},{name:"sequence",description:"Array of values to pass into the callback\n at each step of the phrase.
\n",type:"Array"}],example:["\n\nvar mySound, myPhrase, myPart;\nvar pattern = [1,0,0,2,0,2,0,0];\nvar msg = 'click to play';\n\nfunction preload() {\n mySound = loadSound('assets/beatbox.mp3');\n}\n\nfunction setup() {\n noStroke();\n fill(255);\n textAlign(CENTER);\n masterVolume(0.1);\n\n myPhrase = new p5.Phrase('bbox', makeSound, pattern);\n myPart = new p5.Part();\n myPart.addPhrase(myPhrase);\n myPart.setBPM(60);\n}\n\nfunction draw() {\n background(0);\n text(msg, width/2, height/2);\n}\n\nfunction makeSound(time, playbackRate) {\n mySound.rate(playbackRate);\n mySound.play(time);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n myPart.start();\n msg = 'playing pattern';\n }\n}\n\n
A p5.Part plays back one or more p5.Phrases. Instantiate a part\nwith steps and tatums. By default, each step represents 1/16th note.
\n\nSee p5.Phrase for more about musical timing.
",is_constructor:1,params:[{name:"steps",description:"Steps in the part
\n",type:"Number",optional:!0},{name:"tatums",description:"Divisions of a beat (default is 1/16, a quarter note)
\n",type:"Number",optional:!0}],example:["\n\nvar box, drum, myPart;\nvar boxPat = [1,0,0,2,0,2,0,0];\nvar drumPat = [0,1,1,0,2,0,1,0];\nvar msg = 'click to play';\n\nfunction preload() {\n box = loadSound('assets/beatbox.mp3');\n drum = loadSound('assets/drum.mp3');\n}\n\nfunction setup() {\n noStroke();\n fill(255);\n textAlign(CENTER);\n masterVolume(0.1);\n\n var boxPhrase = new p5.Phrase('box', playBox, boxPat);\n var drumPhrase = new p5.Phrase('drum', playDrum, drumPat);\n myPart = new p5.Part();\n myPart.addPhrase(boxPhrase);\n myPart.addPhrase(drumPhrase);\n myPart.setBPM(60);\n masterVolume(0.1);\n}\n\nfunction draw() {\n background(0);\n text(msg, width/2, height/2);\n}\n\nfunction playBox(time, playbackRate) {\n box.rate(playbackRate);\n box.play(time);\n}\n\nfunction playDrum(time, playbackRate) {\n drum.rate(playbackRate);\n drum.play(time);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n myPart.start();\n msg = 'playing part';\n }\n}\n
A Score consists of a series of Parts. The parts will\nbe played back in order. For example, you could have an\nA part, a B part, and a C part, and play them back in this order\nnew p5.Score(a, a, b, a, c)
One or multiple parts, to be played in sequence.
\n",type:"p5.Part",optional:!0,multiple:!0}]},"p5.Compressor":{name:"p5.Compressor",shortname:"p5.Compressor",classitems:[],plugins:[],extensions:[],plugin_for:[],extension_for:[],module:"p5.sound",submodule:"p5.sound",namespace:"",file:"lib/addons/p5.sound.js",line:9544,description:'Compressor is an audio effect class that performs dynamics compression\non an audio input source. This is a very commonly used technique in music\nand sound production. Compression creates an overall louder, richer, \nand fuller sound by lowering the volume of louds and raising that of softs.\nCompression can be used to avoid clipping (sound distortion due to \npeaks in volume) and is especially useful when many sounds are played \nat once. Compression can be used on indivudal sound sources in addition\nto the master output.
\nThis class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.
Record sounds for playback and/or to save as a .wav file.\nThe p5.SoundRecorder records all sound output from your sketch,\nor can be assigned a specific source with setInput().
\nThe record() method accepts a p5.SoundFile as a parameter.\nWhen playback is stopped (either after the given amount of time,\nor with the stop() method), the p5.SoundRecorder will send its\nrecording to that p5.SoundFile for playback.
",is_constructor:1,example:["\n\nvar mic, recorder, soundFile;\nvar state = 0;\n\nfunction setup() {\n background(200);\n // create an audio in\n mic = new p5.AudioIn();\n\n // prompts user to enable their browser mic\n mic.start();\n\n // create a sound recorder\n recorder = new p5.SoundRecorder();\n\n // connect the mic to the recorder\n recorder.setInput(mic);\n\n // this sound file will be used to\n // playback & save the recording\n soundFile = new p5.SoundFile();\n\n text('keyPress to record', 20, 20);\n}\n\nfunction keyPressed() {\n // make sure user enabled the mic\n if (state === 0 && mic.enabled) {\n\n // record to our p5.SoundFile\n recorder.record(soundFile);\n\n background(255,0,0);\n text('Recording!', 20, 20);\n state++;\n }\n else if (state === 1) {\n background(0,255,0);\n\n // stop recorder and\n // send result to soundFile\n recorder.stop();\n\n text('Stopped', 20, 20);\n state++;\n }\n\n else if (state === 2) {\n soundFile.play(); // play the result!\n save(soundFile, 'mySound.wav');\n state++;\n }\n}\n
PeakDetect works in conjunction with p5.FFT to\nlook for onsets in some or all of the frequency spectrum.\n
\n\nTo use p5.PeakDetect, call update
in the draw loop\nand pass in a p5.FFT object.\n
\nYou can listen for a specific part of the frequency spectrum by\nsetting the range between freq1
and freq2
.\n
threshold
is the threshold for detecting a peak,\nscaled between 0 and 1. It is logarithmic, so 0.1 is half as loud\nas 1.0.
\nThe update method is meant to be run in the draw loop, and\nframes determines how many loops must pass before\nanother peak can be detected.\nFor example, if the frameRate() = 60, you could detect the beat of a\n120 beat-per-minute song with this equation:\n framesPerPeak = 60 / (estimatedBPM / 60 );
\n
\nBased on example contribtued by @b2renger, and a simple beat detection\nexplanation by a\nhref="http://www.airtightinteractive.com/2013/10/making-audio-reactive-visuals/"\ntarget="_blank"Felix Turner.\n
',is_constructor:1,params:[{name:"freq1",description:"lowFrequency - defaults to 20Hz
\n",type:"Number",optional:!0},{name:"freq2",description:"highFrequency - defaults to 20000 Hz
\n",type:"Number",optional:!0},{name:"threshold",description:"Threshold for detecting a beat between 0 and 1\n scaled logarithmically where 0.1 is 1/2 the loudness\n of 1.0. Defaults to 0.35.
\n",type:"Number",optional:!0},{name:"framesPerPeak",description:"Defaults to 20.
\n",type:"Number",optional:!0}],example:["\n\n\nvar cnv, soundFile, fft, peakDetect;\nvar ellipseWidth = 10;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n\n soundFile = loadSound('assets/beat.mp3');\n\n // p5.PeakDetect requires a p5.FFT\n fft = new p5.FFT();\n peakDetect = new p5.PeakDetect();\n\n}\n\nfunction draw() {\n background(0);\n text('click to play/pause', width/2, height/2);\n\n // peakDetect accepts an fft post-analysis\n fft.analyze();\n peakDetect.update(fft);\n\n if ( peakDetect.isDetected ) {\n ellipseWidth = 50;\n } else {\n ellipseWidth *= 0.95;\n }\n\n ellipse(width/2, height/2, ellipseWidth, ellipseWidth);\n}\n\n// toggle play/stop when canvas is clicked\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n if (soundFile.isPlaying() ) {\n soundFile.stop();\n } else {\n soundFile.play();\n }\n }\n}\n
A gain node is usefull to set the relative volume of sound.\nIt's typically used to build mixers.
\n",is_constructor:1,example:["\n\n\n // load two soundfile and crossfade beetween them\n var sound1,sound2;\n var gain1, gain2, gain3;\n\n function preload(){\n soundFormats('ogg', 'mp3');\n sound1 = loadSound('../_files/Damscray_-_Dancing_Tiger_01');\n sound2 = loadSound('../_files/beat.mp3');\n }\n\n function setup() {\n createCanvas(400,200);\n\n // create a 'master' gain to which we will connect both soundfiles\n gain3 = new p5.Gain();\n gain3.connect();\n\n // setup first sound for playing\n sound1.rate(1);\n sound1.loop();\n sound1.disconnect(); // diconnect from p5 output\n\n gain1 = new p5.Gain(); // setup a gain node\n gain1.setInput(sound1); // connect the first sound to its input\n gain1.connect(gain3); // connect its output to the 'master'\n\n sound2.rate(1);\n sound2.disconnect();\n sound2.loop();\n\n gain2 = new p5.Gain();\n gain2.setInput(sound2);\n gain2.connect(gain3);\n\n }\n\n function draw(){\n background(180);\n\n // calculate the horizontal distance beetween the mouse and the right of the screen\n var d = dist(mouseX,0,width,0);\n\n // map the horizontal position of the mouse to values useable for volume control of sound1\n var vol1 = map(mouseX,0,width,0,1);\n var vol2 = 1-vol1; // when sound1 is loud, sound2 is quiet and vice versa\n\n gain1.amp(vol1,0.5,0);\n gain2.amp(vol2,0.5,0);\n\n // map the vertical position of the mouse to values useable for 'master volume control'\n var vol3 = map(mouseY,0,height,0,1);\n gain3.amp(vol3,0.5,0);\n }\n
A Distortion effect created with a Waveshaper Node,\nwith an approach adapted from\nKevin Ennis
\nThis class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.
Unbounded distortion amount.\n Normal values range from 0-1.
\n",type:"Number",optional:!0,optdefault:"0.25"},{name:"oversample",description:"'none', '2x', or '4x'.
\n",type:"String",optional:!0,optdefault:"'none'"}]}},elements:{},classitems:[{file:"src/color/color_conversion.js",line:10,description:'Conversions adapted from http://www.easyrgb.com/math.html.
\nIn these functions, hue is always in the range [0,1); all other components\nare in the range [0,1]. 'Brightness' and 'value' are used interchangeably.
\n',class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/color_conversion.js",line:20,description:"Convert an HSBA array to HSLA.
\n",class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/color_conversion.js",line:46,description:"Convert an HSBA array to RGBA.
\n",class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/color_conversion.js",line:95,description:"Convert an HSLA array to HSBA.
\n",class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/color_conversion.js",line:118,description:"Convert an HSLA array to RGBA.
\nWe need to change basis from HSLA to something that can be more easily be\nprojected onto RGBA. We will choose hue and brightness as our first two\ncomponents, and pick a convenient third one ('zest') so that we don't need\nto calculate formal HSBA saturation.
\n",class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/color_conversion.js",line:176,description:"Convert an RGBA array to HSBA.
\n",class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/color_conversion.js",line:211,description:"Convert an RGBA array to HSLA.
\n",class:"p5",module:"Conversion",submodule:"Color Conversion"},{file:"src/color/creating_reading.js",line:16,description:"Extracts the alpha value from a color or pixel array.
\n",itemtype:"method",name:"alpha",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the alpha value",type:"Number"},example:["\n\nnoStroke();\nc = color(0, 126, 255, 102);\nfill(c);\nrect(15, 15, 35, 70);\nvalue = alpha(c); // Sets 'value' to 102\nfill(value);\nrect(50, 15, 35, 70);\n
\nExtracts the blue value from a color or pixel array.
\n",itemtype:"method",name:"blue",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the blue value",type:"Number"},example:["\n\nc = color(175, 100, 220); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(15, 20, 35, 60); // Draw left rectangle\n\nblueValue = blue(c); // Get blue in 'c'\nprint(blueValue); // Prints \"220.0\"\nfill(0, 0, blueValue); // Use 'blueValue' in new fill\nrect(50, 20, 35, 60); // Draw right rectangle\n
\nExtracts the HSB brightness value from a color or pixel array.
\n",itemtype:"method",name:"brightness",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the brightness value",type:"Number"},example:["\n\nnoStroke();\ncolorMode(HSB, 255);\nc = color(0, 126, 255);\nfill(c);\nrect(15, 20, 35, 60);\nvalue = brightness(c); // Sets 'value' to 255\nfill(value);\nrect(50, 20, 35, 60);\n
\nCreates colors for storing in variables of the color datatype. The\nparameters are interpreted as RGB or HSB values depending on the\ncurrent colorMode(). The default mode is RGB values from 0 to 255\nand, therefore, the function call color(255, 204, 0) will return a\nbright yellow color.\n
\nNote that if only one value is provided to color(), it will be interpreted\nas a grayscale value. Add a second value, and it will be used for alpha\ntransparency. When three values are specified, they are interpreted as\neither RGB or HSB values. Adding a fourth value applies alpha\ntransparency.\n
\nIf a single string argument is provided, RGB, RGBA and Hex CSS color\nstrings and all named color strings are supported. In this case, an alpha\nnumber value as a second argument is not supported, the RGBA form should be\nused.
\nvar c = color(255, 204, 0); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nnoStroke(); // Don't draw a stroke around shapes\nrect(30, 20, 55, 55); // Draw rectangle\n
\n\nvar c = color(255, 204, 0); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nnoStroke(); // Don't draw a stroke around shapes\nellipse(25, 25, 80, 80); // Draw left circle\n\n// Using only one value with color()\n// generates a grayscale value.\nvar c = color(65); // Update 'c' with grayscale value\nfill(c); // Use updated 'c' as fill color\nellipse(75, 75, 80, 80); // Draw right circle\n
\n\n// Named SVG & CSS colors may be used,\nvar c = color('magenta');\nfill(c); // Use 'c' as fill color\nnoStroke(); // Don't draw a stroke around shapes\nrect(20, 20, 60, 60); // Draw rectangle\n
\n\n// as can hex color codes:\nnoStroke(); // Don't draw a stroke around shapes\nvar c = color('#0f0');\nfill(c); // Use 'c' as fill color\nrect(0, 10, 45, 80); // Draw rectangle\n\nc = color('#00ff00');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw rectangle\n
\n\n// RGB and RGBA color strings are also supported:\n// these all set to the same color (solid blue)\nvar c;\nnoStroke(); // Don't draw a stroke around shapes\nc = color('rgb(0,0,255)');\nfill(c); // Use 'c' as fill color\nrect(10, 10, 35, 35); // Draw rectangle\n\nc = color('rgb(0%, 0%, 100%)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 35, 35); // Draw rectangle\n\nc = color('rgba(0, 0, 255, 1)');\nfill(c); // Use updated 'c' as fill color\nrect(10, 55, 35, 35); // Draw rectangle\n\nc = color('rgba(0%, 0%, 100%, 1)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 55, 35, 35); // Draw rectangle\n
\n\n// HSL color is also supported and can be specified\n// by value\nvar c;\nnoStroke(); // Don't draw a stroke around shapes\nc = color('hsl(160, 100%, 50%)');\nfill(c); // Use 'c' as fill color\nrect(0, 10, 45, 80); // Draw rectangle\n\nc = color('hsla(160, 100%, 50%, 0.5)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw rectangle\n
\n\n// HSB color is also supported and can be specified\n// by value\nvar c;\nnoStroke(); // Don't draw a stroke around shapes\nc = color('hsb(160, 100%, 50%)');\nfill(c); // Use 'c' as fill color\nrect(0, 10, 45, 80); // Draw rectangle\n\nc = color('hsba(160, 100%, 50%, 0.5)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw rectangle\n
\n\nvar c; // Declare color 'c'\nnoStroke(); // Don't draw a stroke around shapes\n\n// If no colorMode is specified, then the\n// default of RGB with scale of 0-255 is used.\nc = color(50, 55, 100); // Create a color for 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(0, 10, 45, 80); // Draw left rect\n\ncolorMode(HSB, 100); // Use HSB with scale of 0-100\nc = color(50, 55, 100); // Update 'c' with new color\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw right rect\n
\nnumber specifying value between white\n and black.
\n",type:"Number"},{name:"alpha",description:"alpha value relative to current color range\n (default is 0-255)
\n",type:"Number",optional:!0}],return:{description:"resulting color",type:"p5.Color"}},{line:277,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:!0}],return:{description:"",type:"p5.Color"}},{line:289,params:[{name:"value",description:"a color string
\n",type:"String"},{name:"alpha",description:"",type:"Number",optional:!0}],return:{description:"",type:"p5.Color"}},{line:295,params:[{name:"values",description:"an array containing the red,green,blue &\n and alpha components of the color
\n",type:"Array"}],return:{description:"",type:"p5.Color"}},{line:301,params:[{name:"color",description:"",type:"p5.Color" }],return:{description:"",type:"p5.Color"}}]},{file:"src/color/creating_reading.js",line:326,description:"Extracts the green value from a color or pixel array.
\n",itemtype:"method",name:"green",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the green value",type:"Number"},example:["\n\nc = color(20, 75, 200); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(15, 20, 35, 60); // Draw left rectangle\n\ngreenValue = green(c); // Get green in 'c'\nprint(greenValue); // Print \"75.0\"\nfill(0, greenValue, 0); // Use 'greenValue' in new fill\nrect(50, 20, 35, 60); // Draw right rectangle\n
\nExtracts the hue value from a color or pixel array.
\nHue exists in both HSB and HSL. This function will return the\nHSB-normalized hue when supplied with an HSB color object (or when supplied\nwith a pixel array while the color mode is HSB), but will default to the\nHSL-normalized hue otherwise. (The values will only be different if the\nmaximum hue setting for each system is different.)
\n",itemtype:"method",name:"hue",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the hue",type:"Number"},example:["\n\nnoStroke();\ncolorMode(HSB, 255);\nc = color(0, 126, 255);\nfill(c);\nrect(15, 20, 35, 60);\nvalue = hue(c); // Sets 'value' to \"0\"\nfill(value);\nrect(50, 20, 35, 60);\n
\nBlends two colors to find a third color somewhere between them. The amt\nparameter is the amount to interpolate between the two values where 0.0\nequal to the first color, 0.1 is very near the first color, 0.5 is halfway\nin between, etc. An amount below 0 will be treated as 0. Likewise, amounts\nabove 1 will be capped at 1. This is different from the behavior of lerp(),\nbut necessary because otherwise numbers outside the range will produce\nstrange and unexpected colors.\n
\nThe way that colours are interpolated depends on the current color mode.
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"}],return:{description:"interpolated color",type:"p5.Color"},example:["\n\ncolorMode(RGB);\nstroke(255);\nbackground(51);\nfrom = color(218, 165, 32);\nto = color(72, 61, 139);\ncolorMode(RGB); // Try changing to HSB.\ninterA = lerpColor(from, to, .33);\ninterB = lerpColor(from, to, .66);\nfill(from);\nrect(10, 20, 20, 60);\nfill(interA);\nrect(30, 20, 20, 60);\nfill(interB);\nrect(50, 20, 20, 60);\nfill(to);\nrect(70, 20, 20, 60);\n
\nExtracts the HSL lightness value from a color or pixel array.
\n",itemtype:"method",name:"lightness",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the lightness",type:"Number"},example:["\n\nnoStroke();\ncolorMode(HSL);\nc = color(156, 100, 50, 1);\nfill(c);\nrect(15, 20, 35, 60);\nvalue = lightness(c); // Sets 'value' to 50\nfill(value);\nrect(50, 20, 35, 60);\n
\nExtracts the red value from a color or pixel array.
\n",itemtype:"method",name:"red",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the red value",type:"Number"},example:["\n\nc = color(255, 204, 0); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(15, 20, 35, 60); // Draw left rectangle\n\nredValue = red(c); // Get red in 'c'\nprint(redValue); // Print \"255.0\"\nfill(redValue, 0, 0); // Use 'redValue' in new fill\nrect(50, 20, 35, 60); // Draw right rectangle\n
\n\ncolorMode(RGB, 255);\nvar c = color(127, 255, 0);\ncolorMode(RGB, 1);\nvar myColor = red(c);\nprint(myColor);\n
\nExtracts the saturation value from a color or pixel array.
\nSaturation is scaled differently in HSB and HSL. This function will return\nthe HSB saturation when supplied with an HSB color object (or when supplied\nwith a pixel array while the color mode is HSB), but will default to the\nHSL saturation otherwise.
\n",itemtype:"method",name:"saturation",params:[{name:"color",description:"p5.Color object or pixel array
\n",type:"p5.Color|Array"}],return:{description:"the saturation value",type:"Number"},example:["\n\nnoStroke();\ncolorMode(HSB, 255);\nc = color(0, 126, 255);\nfill(c);\nrect(15, 20, 35, 60);\nvalue = saturation(c); // Sets 'value' to 126\nfill(value);\nrect(50, 20, 35, 60);\n
\nHue is the same in HSB and HSL, but the maximum value may be different.\nThis function will return the HSB-normalized saturation when supplied with\nan HSB color object, but will default to the HSL-normalized saturation\notherwise.
\n",class:"p5.Color",module:"Color",submodule:"Creating & Reading"},{file:"src/color/p5.Color.js",line:149,description:"Saturation is scaled differently in HSB and HSL. This function will return\nthe HSB saturation when supplied with an HSB color object, but will default\nto the HSL saturation otherwise.
\n",class:"p5.Color",module:"Color",submodule:"Creating & Reading"},{file:"src/color/p5.Color.js",line:168,description:"CSS named colors.
\n",class:"p5.Color",module:"Color",submodule:"Creating & Reading"},{file:"src/color/p5.Color.js",line:321,description:"These regular expressions are used to build up the patterns for matching\nviable CSS color strings: fragmenting the regexes in this way increases the\nlegibility and comprehensibility of the code.
\nNote that RGB values of .9 are not parsed by IE, but are supported here for\ncolor string consistency.
\n",class:"p5.Color",module:"Color",submodule:"Creating & Reading"},{file:"src/color/p5.Color.js",line:334,description:"Full color string patterns. The capture groups are necessary.
\n",class:"p5.Color",module:"Color",submodule:"Creating & Reading"},{file:"src/color/p5.Color.js",line:447,description:"For a number of different inputs, returns a color formatted as [r, g, b, a]\narrays, with each component normalized between 0 and 1.
\n",params:[{name:"args",description:"An 'array-like' object that represents a list of\n arguments
\n",type:"Array",optional:!0,multiple:!0}],return:{description:"a color formatted as [r, g, b, a]\n Example:\n input ==> output\n g ==> [g, g, g, 255]\n g,a ==> [g, g, g, a]\n r, g, b ==> [r, g, b, 255]\n r, g, b, a ==> [r, g, b, a]\n [g] ==> [g, g, g, 255]\n [g, a] ==> [g, g, g, a]\n [r, g, b] ==> [r, g, b, 255]\n [r, g, b, a] ==> [r, g, b, a]",type:"Number[]"},example:["\n\n// todo\n
\nFor HSB and HSL, interpret the gray level as a brightness/lightness\nvalue (they are equivalent when chroma is zero). For RGB, normalize the\ngray level according to the blue maximum.
\n",class:"p5.Color",module:"Color",submodule:"Creating & Reading"},{file:"src/color/setting.js",line:15,description:"The background() function sets the color used for the background of the\np5.js canvas. The default background is light gray. This function is\ntypically used within draw() to clear the display window at the beginning\nof each frame, but it can be used inside setup() to set the background on\nthe first frame of animation or if the background need only be set once.\n
\nThe color is either specified in terms of the RGB, HSB, or HSL color\ndepending on the current colorMode. (The default color space is RGB, with\neach value in the range from 0 to 255).\n
\nIf a single string argument is provided, RGB, RGBA and Hex CSS color strings\nand all named color strings are supported. In this case, an alpha number\nvalue as a second argument is not supported, the RGBA form should be used.\n
\nA p5.Color object can also be provided to set the background color.\n
\nA p5.Image can also be provided to set the background iamge.
\n// Grayscale integer value\nbackground(51);\n
\n\n// R, G & B integer values\nbackground(255, 204, 0);\n
\n\n// H, S & B integer values\ncolorMode(HSB);\nbackground(255, 204, 100);\n
\n\n// Named SVG/CSS color string\nbackground('red');\n
\n\n// three-digit hexadecimal RGB notation\nbackground('#fae');\n
\n\n// six-digit hexadecimal RGB notation\nbackground('#222222');\n
\n\n// integer RGB notation\nbackground('rgb(0,255,0)');\n
\n\n// integer RGBA notation\nbackground('rgba(0,255,0, 0.25)');\n
\n\n// percentage RGB notation\nbackground('rgb(100%,0%,10%)');\n
\n\n// percentage RGBA notation\nbackground('rgba(100%,0%,100%,0.5)');\n
\n\n// p5 Color object\nbackground(color(0, 0, 255));\n
\nany value created by the color() function
\n",type:"p5.Color"},{name:"a",description:"opacity of the background relative to current\n color range (default is 0-100)
\n",type:"Number",optional:!0}],chainable:1},{line:133,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:"",type:"Number",optional:!0}],chainable:1},{line:142,params:[{name:"gray",description:"specifies a value between white and black
\n",type:"Number"},{name:"a",description:"",type:"Number",optional:!0}],chainable:1},{line:149,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:!0}],chainable:1},{line:161,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:!0}],chainable:1}]},{file:"src/color/setting.js",line:178,description:"Clears the pixels within a buffer. This function only works on p5.Canvas\nobjects created with the createCanvas() function; it won't work with the\nmain display window. Unlike the main graphics context, pixels in\nadditional graphics areas created with createGraphics() can be entirely\nor partially transparent. This function clears everything to make all of\nthe pixels 100% transparent.
\n",itemtype:"method",name:"clear",chainable:1,example:["\n\n// Clear the screen on mouse press.\nfunction setup() {\n createCanvas(100, 100);\n}\n\nfunction draw() {\n ellipse(mouseX, mouseY, 20, 20);\n}\n\nfunction mousePressed() {\n clear();\n}\n
\ncolorMode() changes the way p5.js interprets color data. By default, the\nparameters for fill(), stroke(), background(), and color() are defined by\nvalues between 0 and 255 using the RGB color model. This is equivalent to\nsetting colorMode(RGB, 255). Setting colorMode(HSB) lets you use the HSB\nsystem instead. By default, this is colorMode(HSB, 360, 100, 100, 1). You\ncan also use HSL.\n
\nNote: existing color objects remember the mode that they were created in,\nso you can change modes as you like without affecting their appearance.
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:!0}],chainable:1},{line:235,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/lighntess\n depending on the current color mode
\n",type:"Number"},{name:"maxA",description:"range for the alpha
\n",type:"Number",optional:!0}],chainable:1}]},{file:"src/color/setting.js",line:335,description:"Sets the color used to fill shapes. For example, if you run\nfill(204, 102, 0), all subsequent shapes will be filled with orange. This\ncolor is either specified in terms of the RGB or HSB color depending on\nthe current colorMode(). (The default color space is RGB, with each value\nin the range from 0 to 255).\n
\nIf a single string argument is provided, RGB, RGBA and Hex CSS color strings\nand all named color strings are supported. In this case, an alpha number\nvalue as a second argument is not supported, the RGBA form should be used.\n
\nA p5 Color object can also be provided to set the fill color.
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:!0}],chainable:1},{line:359,params:[{name:"value",description:"a color string
\n",type:"String"},{name:"alpha",description:"",type:"Number",optional:!0}],chainable:1},{line:366,params:[{name:"values",description:"an array containing the red,green,blue &\n and alpha components of the color
\n",type:"Number[]"}],chainable:1},{line:373,params:[{name:"color",description:"the fill color
\n",type:"p5.Color"},{name:"alpha",description:"",type:"Number",optional:!0}],chainable:1}]},{file:"src/color/setting.js",line:489,description:"Disables filling geometry. If both noStroke() and noFill() are called,\nnothing will be drawn to the screen.
\n",itemtype:"method",name:"noFill",chainable:1,example:["\n\nrect(15, 10, 55, 55);\nnoFill();\nrect(20, 20, 60, 60);\n
\nDisables drawing the stroke (outline). If both noStroke() and noFill()\nare called, nothing will be drawn to the screen.
\n",itemtype:"method",name:"noStroke",chainable:1,example:["\n\nnoStroke();\nrect(20, 20, 60, 60);\n
\nSets the color used to draw lines and borders around shapes. This color\nis either specified in terms of the RGB or HSB color depending on the\ncurrent colorMode() (the default color space is RGB, with each value in\nthe range from 0 to 255).\n
\nIf a single string argument is provided, RGB, RGBA and Hex CSS color\nstrings and all named color strings are supported. In this case, an alpha\nnumber value as a second argument is not supported, the RGBA form should be\nused.\n
\nA p5 Color object can also be provided to set the stroke color.
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:!0}],chainable:1},{line:567,params:[{name:"value",description:"a color string
\n",type:"String"},{name:"alpha",description:"",type:"Number",optional:!0}],chainable:1},{line:574,params:[{name:"values",description:"an array containing the red,green,blue &\n and alpha components of the color
\n",type:"Number[]"}],chainable:1},{line:581,params:[{name:"color",description:"the stroke color
\n",type:"p5.Color"},{name:"alpha",description:"",type:"Number",optional:!0}],chainable:1}]},{file:"src/core/2d_primitives.js",line:16,description:"Draw an arc to the screen. If called with only a, b, c, d, start, and\nstop, the arc will be drawn as an open pie. If mode is provided, the arc\nwill be drawn either open, as a chord, or as a pie as specified. The\norigin may be changed with the ellipseMode() function.
\nNote that drawing a full circle (ex: 0 to TWO_PI) will appear blank\nbecause 0 and TWO_PI are the same position on the unit circle. The\nbest way to handle this is by using the ellipse() function instead\nto create a closed ellipse, and to use the arc() function\nonly to draw parts of an ellipse.
x-coordinate of the arc's ellipse
\n",type:"Number"},{name:"b",description:"y-coordinate of the arc's ellipse
\n",type:"Number"},{name:"c",description:"width of the arc's ellipse by default
\n",type:"Number"},{name:"d",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 or PIE
\n",type:"Constant",optional:!0}],chainable:1,example:["\n\narc(50, 55, 50, 50, 0, HALF_PI);\nnoFill();\narc(50, 55, 60, 60, HALF_PI, PI);\narc(50, 55, 70, 70, PI, PI+QUARTER_PI);\narc(50, 55, 80, 80, PI+QUARTER_PI, TWO_PI);\n
\n\narc(50, 50, 80, 80, 0, PI+QUARTER_PI, OPEN);\n
\n\narc(50, 50, 80, 80, 0, PI+QUARTER_PI, CHORD);\n
\n\narc(50, 50, 80, 80, 0, PI+QUARTER_PI, PIE);\n
\nDraws an ellipse (oval) to the screen. An ellipse with equal width and\nheight is a circle. By default, the first two parameters set the location,\nand the third and fourth parameters set the shape's width and height. If\nno height is specified, the value of width is used for both the width and\nheight. If a negative height or width is specified, the absolute value is taken.\nThe origin may be changed with the ellipseMode() function.
\n",itemtype:"method",name:"ellipse",params:[{name:"x",description:"x-coordinate of the ellipse.
\n",type:"Number"},{name:"y",description:"y-coordinate of the 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:!0}],chainable:1,example:["\n\nellipse(56, 46, 55, 55);\n
\nDraws a line (a direct path between two points) to the screen. The version\nof line() with four parameters draws the line in 2D. To color a line, use\nthe stroke() function. A line cannot be filled, therefore the fill()\nfunction will not affect the color of a line. 2D lines are drawn with a\nwidth of one pixel by default, but this can be changed with the\nstrokeWeight() function.
\n",itemtype:"method",name:"line",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,example:["\n\nline(30, 20, 85, 75);\n
\n\nline(30, 20, 85, 20);\nstroke(126);\nline(85, 20, 85, 75);\nstroke(255);\nline(85, 75, 30, 75);\n
\nDraws a point, a coordinate in space at the dimension of one pixel.\nThe first parameter is the horizontal value for the point, the second\nvalue is the vertical value for the point. The color of the point is\ndetermined by the current stroke.
\n",itemtype:"method",name:"point",params:[{name:"x",description:"the x-coordinate
\n",type:"Number"},{name:"y",description:"the y-coordinate
\n",type:"Number"}],chainable:1,example:["\n\npoint(30, 20);\npoint(85, 20);\npoint(85, 75);\npoint(30, 75);\n
\nDraw a quad. A quad is a quadrilateral, a four sided polygon. It is\nsimilar to a rectangle, but the angles between its edges are not\nconstrained to ninety degrees. The first pair of parameters (x1,y1)\nsets the first vertex and the subsequent pairs should proceed\nclockwise or counter-clockwise around the defined shape.
\n",itemtype:"method",name:"quad",chainable:1,example:["\n\nquad(38, 31, 86, 20, 69, 63, 30, 76);\n
\nthe 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"}],chainable:1},{line:341,params:[{name:"x1",description:"",type:"Number"},{name:"y1",description:"",type:"Number"},{name:"x2",description:"",type:"Number"},{name:"y2",description:"",type:"Number"},{name:"x3",description:"",type:"Number"},{name:"y3",description:"",type:"Number"},{name:"x4",description:"",type:"Number"},{name:"y4",description:"",type:"Number"}],chainable:1}]},{file:"src/core/2d_primitives.js",line:393,description:"Draws a rectangle to the screen. A rectangle is a four-sided shape with\nevery angle at ninety degrees. By default, the first two parameters set\nthe location of the upper-left corner, the third sets the width, and the\nfourth sets the height. The way these parameters are interpreted, however,\nmay be changed with the rectMode() function.\n
\nThe fifth, sixth, seventh and eighth parameters, if specified,\ndetermine corner radius for the top-right, top-left, lower-right and\nlower-left corners, respectively. An omitted corner radius parameter is set\nto the value of the previously specified radius value in the parameter list.
\n// Draw a rectangle at location (30, 20) with a width and height of 55.\nrect(30, 20, 55, 55);\n
\n\n// Draw a rectangle with rounded corners, each having a radius of 20.\nrect(30, 20, 55, 55, 20);\n
\n\n// Draw a rectangle with rounded corners having the following radii:\n// top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.\nrect(30, 20, 55, 55, 20, 15, 10, 5);\n
\nx-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"},{name:"tl",description:"optional radius of top-left corner.
\n",type:"Number",optional:!0},{name:"tr",description:"optional radius of top-right corner.
\n",type:"Number",optional:!0},{name:"br",description:"optional radius of bottom-right corner.
\n",type:"Number",optional:!0},{name:"bl",description:"optional radius of bottom-left corner.
\n",type:"Number",optional:!0}],return:{description:"the p5 object.",type:"P5"}},{line:443,params:[{name:"x",description:"",type:"Number"},{name:"y",description:"",type:"Number"},{name:"w",description:"",type:"Number"},{name:"h",description:"",type:"Number"},{name:"detailX",description:"",type:"Number",optional:!0},{name:"detailY",description:"",type:"Number",optional:!0}],chainable:1}]},{file:"src/core/2d_primitives.js",line:477,description:"A triangle is a plane created by connecting three points. The first two\narguments specify the first point, the middle two arguments specify the\nsecond point, and the last two arguments specify the third point.
\n",itemtype:"method",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"}],chainable:1,example:["\n\ntriangle(30, 75, 58, 20, 86, 75);\n
\nModifies the location from which ellipses are drawn by changing the way\nin which parameters given to ellipse() are interpreted.\n
\nThe default mode is ellipseMode(CENTER), which interprets the first two\nparameters of ellipse() as the shape's center point, while the third and\nfourth parameters are its width and height.\n
\nellipseMode(RADIUS) also uses the first two parameters of ellipse() as\nthe shape's center point, but uses the third and fourth parameters to\nspecify half of the shapes's width and height.\n
\nellipseMode(CORNER) interprets the first two parameters of ellipse() as\nthe upper-left corner of the shape, while the third and fourth parameters\nare its width and height.\n
\nellipseMode(CORNERS) interprets the first two parameters of ellipse() as\nthe location of one corner of the ellipse's bounding box, and the third\nand fourth parameters as the location of the opposite corner.\n
\nThe parameter must be written in ALL CAPS because Javascript is a\ncase-sensitive language.
either CENTER, RADIUS, CORNER, or CORNERS
\n",type:"Constant"}],chainable:1, example:["\n\nellipseMode(RADIUS); // Set ellipseMode to RADIUS\nfill(255); // Set fill to white\nellipse(50, 50, 30, 30); // Draw white ellipse using RADIUS mode\n\nellipseMode(CENTER); // Set ellipseMode to CENTER\nfill(100); // Set fill to gray\nellipse(50, 50, 30, 30); // Draw gray ellipse using CENTER mode\n
\n\nellipseMode(CORNER); // Set ellipseMode is CORNER\nfill(255); // Set fill to white\nellipse(25, 25, 50, 50); // Draw white ellipse using CORNER mode\n\nellipseMode(CORNERS); // Set ellipseMode to CORNERS\nfill(100); // Set fill to gray\nellipse(25, 25, 50, 50); // Draw gray ellipse using CORNERS mode\n
\nDraws all geometry with jagged (aliased) edges. Note that smooth() is\nactive by default, so it is necessary to call noSmooth() to disable\nsmoothing of geometry, images, and fonts.
\n",itemtype:"method",name:"noSmooth",chainable:1,example:["\n\nbackground(0);\nnoStroke();\nsmooth();\nellipse(30, 48, 36, 36);\nnoSmooth();\nellipse(70, 48, 36, 36);\n
\nModifies the location from which rectangles are drawn by changing the way\nin which parameters given to rect() are interpreted.\n
\nThe default mode is rectMode(CORNER), which interprets the first two\nparameters of rect() as the upper-left corner of the shape, while the\nthird and fourth parameters are its width and height.\n
\nrectMode(CORNERS) interprets the first two parameters of rect() as the\nlocation of one corner, and the third and fourth parameters as the\nlocation of the opposite corner.\n
\nrectMode(CENTER) interprets the first two parameters of rect() as the\nshape's center point, while the third and fourth parameters are its\nwidth and height.\n
\nrectMode(RADIUS) also uses the first two parameters of rect() as the\nshape's center point, but uses the third and fourth parameters to specify\nhalf of the shapes's width and height.\n
\nThe parameter must be written in ALL CAPS because Javascript is a\ncase-sensitive language.
either CORNER, CORNERS, CENTER, or RADIUS
\n",type:"Constant"}],chainable:1,example:["\n\nrectMode(CORNER); // Default rectMode is CORNER\nfill(255); // Set fill to white\nrect(25, 25, 50, 50); // Draw white rect using CORNER mode\n\nrectMode(CORNERS); // Set rectMode to CORNERS\nfill(100); // Set fill to gray\nrect(25, 25, 50, 50); // Draw gray rect using CORNERS mode\n
\n\nrectMode(RADIUS); // Set rectMode to RADIUS\nfill(255); // Set fill to white\nrect(50, 50, 30, 30); // Draw white rect using RADIUS mode\n\nrectMode(CENTER); // Set rectMode to CENTER\nfill(100); // Set fill to gray\nrect(50, 50, 30, 30); // Draw gray rect using CENTER mode\n
\nDraws all geometry with smooth (anti-aliased) edges. smooth() will also\nimprove image quality of resized images. Note that smooth() is active by\ndefault; noSmooth() can be used to disable smoothing of geometry,\nimages, and fonts.
\n",itemtype:"method",name:"smooth",chainable:1,example:["\n\nbackground(0);\nnoStroke();\nsmooth();\nellipse(30, 48, 36, 36);\nnoSmooth();\nellipse(70, 48, 36, 36);\n
\nSets the style for rendering line endings. These ends are either squared,\nextended, or rounded, each of which specified with the corresponding\nparameters: SQUARE, PROJECT, and ROUND. The default cap is ROUND.
\n",itemtype:"method",name:"strokeCap",params:[{name:"cap",description:"either SQUARE, PROJECT, or ROUND
\n",type:"Constant"}],chainable:1,example:["\n\nstrokeWeight(12.0);\nstrokeCap(ROUND);\nline(20, 30, 80, 30);\nstrokeCap(SQUARE);\nline(20, 50, 80, 50);\nstrokeCap(PROJECT);\nline(20, 70, 80, 70);\n
\nSets the style of the joints which connect line segments. These joints\nare either mitered, beveled, or rounded and specified with the\ncorresponding parameters MITER, BEVEL, and ROUND. The default joint is\nMITER.
\n",itemtype:"method",name:"strokeJoin",params:[{name:"join",description:"either MITER, BEVEL, ROUND
\n",type:"Constant"}],chainable:1,example:["\n\nnoFill();\nstrokeWeight(10.0);\nstrokeJoin(MITER);\nbeginShape();\nvertex(35, 20);\nvertex(65, 50);\nvertex(35, 80);\nendShape();\n
\n\nnoFill();\nstrokeWeight(10.0);\nstrokeJoin(BEVEL);\nbeginShape();\nvertex(35, 20);\nvertex(65, 50);\nvertex(35, 80);\nendShape();\n
\n\nnoFill();\nstrokeWeight(10.0);\nstrokeJoin(ROUND);\nbeginShape();\nvertex(35, 20);\nvertex(65, 50);\nvertex(35, 80);\nendShape();\n
\nSets the width of the stroke used for lines, points, and the border\naround shapes. All widths are set in units of pixels.
\n",itemtype:"method",name:"strokeWeight",params:[{name:"weight",description:"the weight (in pixels) of the stroke
\n",type:"Number"}],return:{description:"the p5 object",type:"P5"},example:["\n\nstrokeWeight(1); // Default\nline(20, 20, 80, 20);\nstrokeWeight(4); // Thicker\nline(20, 40, 80, 40);\nstrokeWeight(10); // Beastly\nline(20, 70, 80, 70);\n
\nHALF_PI is a mathematical constant with the value\n1.57079632679489661923. It is half the ratio of the\ncircumference of a circle to its diameter. It is useful in\ncombination with the trigonometric functions sin() and cos().
\n",itemtype:"property",name:"HALF_PI",type:"Number",final:1,example:["\n\narc(50, 50, 80, 80, 0, HALF_PI);\n
PI is a mathematical constant with the value\n3.14159265358979323846. It is the ratio of the circumference\nof a circle to its diameter. It is useful in combination with\nthe trigonometric functions sin() and cos().
\n",itemtype:"property",name:"PI",type:"Number",final:1,example:["\n\narc(50, 50, 80, 80, 0, PI);\n
QUARTER_PI is a mathematical constant with the value 0.7853982.\nIt is one quarter the ratio of the circumference of a circle to\nits diameter. It is useful in combination with the trigonometric\nfunctions sin() and cos().
\n",itemtype:"property",name:"QUARTER_PI",type:"Number",final:1,example:["\n\narc(50, 50, 80, 80, 0, QUARTER_PI);\n
TAU is an alias for TWO_PI, a mathematical constant with the\nvalue 6.28318530717958647693. It is twice the ratio of the\ncircumference of a circle to its diameter. It is useful in\ncombination with the trigonometric functions sin() and cos().
\n",itemtype:"property",name:"TAU",type:"Number",final:1,example:["\n\narc(50, 50, 80, 80, 0, TAU);\n
TWO_PI is a mathematical constant with the value\n6.28318530717958647693. It is twice the ratio of the\ncircumference of a circle to its diameter. It is useful in\ncombination with the trigonometric functions sin() and cos().
\n",itemtype:"property",name:"TWO_PI",type:"Number",final:1,example:["\n\narc(50, 50, 80, 80, 0, TWO_PI);\n
This is the p5 instance constructor.
\nA p5 instance holds all the properties and methods related to\na p5 sketch. It expects an incoming sketch closure and it can also\ntake an optional node parameter for attaching the generated p5 canvas\nto a node. The sketch closure takes the newly created p5 instance as\nits sole argument and may optionally set preload(), setup(), and/or\ndraw() properties on it for running a sketch.
\nA p5 sketch can run in "global" or "instance" mode:\n"global" - all properties and methods are attached to the window\n"instance" - all properties and methods are bound to this p5 object
\n",params:[{name:"sketch",description:"a closure that can set optional preload(),\n setup(), and/or draw() properties on the\n given p5 instance
\n",type:"Function"},{name:"node",description:"element to attach canvas to, if a\n boolean is passed in use it as sync
\n",type:"HTMLElement|boolean",optional:!0},{name:"sync",description:"start synchronously (optional)
\n",type:"Boolean",optional:!0}],return:{description:"a p5 instance",type:"P5"},class:"p5",module:"Structure",submodule:"Structure"},{file:"src/core/core.js",line:49,description:'Called directly before setup(), the preload() function is used to handle\nasynchronous loading of external files. If a preload function is\ndefined, setup() will wait until any load calls within have finished.\nNothing besides load calls should be inside preload (loadImage,\nloadJSON, loadFont, loadStrings, etc).
\nBy default the text "loading..." will be displayed. To make your own\nloading page, include an HTML element with id "p5_loading" in your\npage. More information here.
\nvar img;\nvar c;\nfunction preload() { // preload() runs once\n img = loadImage('assets/laDefense.jpg');\n}\n\nfunction setup() { // setup() waits until preload() is done\n img.loadPixels();\n // get color of middle pixel\n c = img.get(img.width/2, img.height/2);\n}\n\nfunction draw() {\n background(c);\n image(img, 25, 25, 50, 50);\n}\n
The setup() function is called once when the program starts. It's used to\ndefine initial environment properties such as screen size and background\ncolor and to load media such as images and fonts as the program starts.\nThere can only be one setup() function for each program and it shouldn't\nbe called again after its initial execution.\n
\nNote: Variables declared within setup() are not accessible within other\nfunctions, including draw().
\nvar a = 0;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(102);\n}\n\nfunction draw() {\n rect(a++%width, 10, 2, 80);\n}\n
Called directly after setup(), the draw() function continuously executes\nthe lines of code contained inside its block until the program is stopped\nor noLoop() is called. Note if noLoop() is called in setup(), draw() will\nstill be executed once before stopping. draw() is called automatically and\nshould never be called explicitly.\n
\nIt should always be controlled with noLoop(), redraw() and loop(). After\nnoLoop() stops the code in draw() from executing, redraw() causes the\ncode inside draw() to execute once, and loop() will cause the code\ninside draw() to resume executing continuously.\n
\nThe number of times draw() executes in each second may be controlled with\nthe frameRate() function.\n
\nThere can only be one draw() function for each sketch, and draw() must\nexist if you want the code to run continuously, or to process events such\nas mousePressed(). Sometimes, you might have an empty call to draw() in\nyour program, as shown in the above example.\n
\nIt is important to note that the drawing coordinate system will be reset\nat the beginning of each draw() call. If any transformations are performed\nwithin draw() (ex: scale, rotate, translate, their effects will be\nundone at the beginning of draw(), so transformations will not accumulate\nover time. On the other hand, styling applied (ex: fill, stroke, etc) will\nremain in effect.
\nvar yPos = 0;\nfunction setup() { // setup() runs once\n frameRate(30);\n}\nfunction draw() { // draw() loops forever, until stopped\n background(204);\n yPos = yPos - 1;\n if (yPos < 0) {\n yPos = height;\n }\n line(0, yPos, width, yPos);\n}\n
Removes the entire p5 sketch. This will remove the canvas and any\nelements created by p5.js. It will also stop the draw loop and unbind\nany properties or methods from the window global scope. It will\nleave a variable p5 in case you wanted to create a new p5 sketch.\nIf you like, you can set p5 = null to erase it. While all functions and\nvariables and objects created by the p5 library will be removed, any\nother global variables created by your code will remain.
\n",itemtype:"method",name:"remove",example:["\n\nfunction draw() {\n ellipse(50, 50, 10, 10);\n}\n\nfunction mousePressed() {\n remove(); // remove whole sketch on mouse press\n}\n
Draws a cubic Bezier curve on the screen. These curves are defined by a\nseries of anchor and control points. The first two parameters specify\nthe first anchor point and the last two parameters specify the other\nanchor point, which become the first and last points on the curve. The\nmiddle parameters specify the two control points which define the shape\nof the curve. Approximately speaking, control points "pull" the curve\ntowards them.
Bezier curves were developed by French\nautomotive engineer Pierre Bezier, and are commonly used in computer\ngraphics to define gently sloping curves. See also curve().
\nnoFill();\nstroke(255, 102, 0);\nline(85, 20, 10, 10);\nline(90, 90, 15, 80);\nstroke(0, 0, 0);\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\n
\nx-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"}],return:{description:"the p5 object",type:"P5"}},{line:59,params:[{name:"z1",description:"z-coordinate for the first anchor point
\n",type:"Number"},{name:"z2",description:"z-coordinate for the first control point
\n",type:"Number"},{name:"z3",description:"z-coordinate for the first anchor point
\n",type:"Number"},{name:"z4",description:"z-coordinate for the first control point
\n",type:"Number"}],chainable:1}]},{file:"src/core/curves.js",line:99,description:"Sets the resolution at which Beziers display.
\nThe default value is 20.
\n",params:[{name:"detail",description:"resolution of the curves
\n",type:"Number"}],chainable:1,example:["\n\nbackground(204);\nbezierDetail(50);\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\n
\nEvaluates the Bezier at position t for points a, b, c, d.\nThe parameters a and d are the first and last points\non the curve, and b and c are the control points.\nThe final parameter t varies between 0 and 1.\nThis can be done once with the x coordinates and a second time\nwith the y coordinates to get the location of a bezier curve at t.
\n",itemtype:"method",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"}],return:{description:"the value of the Bezier at position t",type:"Number"},example:["\n\nnoFill();\nx1 = 85, x2 = 10, x3 = 90, x4 = 15;\ny1 = 20, y2 = 10, y3 = 90, y4 = 80;\nbezier(x1, y1, x2, y2, x3, y3, x4, y4);\nfill(255);\nsteps = 10;\nfor (i = 0; i <= steps; i++) {\n t = i / steps;\n x = bezierPoint(x1, x2, x3, x4, t);\n y = bezierPoint(y1, y2, y3, y4, t);\n ellipse(x, y, 5, 5);\n}\n
\nEvaluates the tangent to the Bezier at position t for points a, b, c, d.\nThe parameters a and d are the first and last points\non the curve, and b and c are the control points.\nThe final parameter t varies between 0 and 1.
\n",itemtype:"method",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"}],return:{description:"the tangent at position t",type:"Number"},example:["\n\nnoFill();\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\nsteps = 6;\nfill(255);\nfor (i = 0; i <= steps; i++) {\n t = i / steps;\n // Get the location of the point\n x = bezierPoint(85, 10, 90, 15, t);\n y = bezierPoint(20, 10, 90, 80, t);\n // Get the tangent points\n tx = bezierTangent(85, 10, 90, 15, t);\n ty = bezierTangent(20, 10, 90, 80, t);\n // Calculate an angle from the tangent points\n a = atan2(ty, tx);\n a += PI;\n stroke(255, 102, 0);\n line(x, y, cos(a)*30 + x, sin(a)*30 + y);\n // The following line of code makes a line\n // inverse of the above line\n //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y);\n stroke(0);\n ellipse(x, y, 5, 5);\n}\n
\n\nnoFill();\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\nstroke(255, 102, 0);\nsteps = 16;\nfor (i = 0; i <= steps; i++) {\n t = i / steps;\n x = bezierPoint(85, 10, 90, 15, t);\n y = bezierPoint(20, 10, 90, 80, t);\n tx = bezierTangent(85, 10, 90, 15, t);\n ty = bezierTangent(20, 10, 90, 80, t);\n a = atan2(ty, tx);\n a -= HALF_PI;\n line(x, y, cos(a)*8 + x, sin(a)*8 + y);\n}\n
\nDraws a curved line on the screen between two points, given as the\nmiddle four parameters. The first two parameters are a control point, as\nif the curve came from this point even though it's not drawn. The last\ntwo parameters similarly describe the other control point.
\nLonger curves can be created by putting a series of curve() functions\ntogether or using curveVertex(). An additional function called\ncurveTightness() provides control for the visual quality of the curve.\nThe curve() function is an implementation of Catmull-Rom splines.
\nnoFill();\nstroke(255, 102, 0);\ncurve(5, 26, 5, 26, 73, 24, 73, 61);\nstroke(0);\ncurve(5, 26, 73, 24, 73, 61, 15, 65);\nstroke(255, 102, 0);\ncurve(73, 24, 73, 61, 15, 65, 15, 65);\n
\n\n// Define the curve points as JavaScript objects\np1 = {x: 5, y: 26}, p2 = {x: 73, y: 24}\np3 = {x: 73, y: 61}, p4 = {x: 15, y: 65}\nnoFill();\nstroke(255, 102, 0);\ncurve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y)\nstroke(0);\ncurve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y)\nstroke(255, 102, 0);\ncurve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y)\n
\nx-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"}],return:{description:"the p5 object",type:"P5"}},{line:308,params:[{name:"z1",description:"z-coordinate for the beginning control point
\n",type:"Number"},{name:"z2",description:"z-coordinate for the first point
\n",type:"Number"},{name:"z3",description:"z-coordinate for the second point
\n",type:"Number"},{name:"z4",description:"z-coordinate for the ending control point
\n",type:"Number"}],chainable:1}]},{file:"src/core/curves.js",line:353,description:"Sets the resolution at which curves display.
\nThe default value is 20.
\n",params:[{name:"resolution",description:"of the curves
\n",type:"Number"}],chainable:1,example:["\n\nbackground(204);\ncurveDetail(20);\ncurve(5, 26, 5, 26, 73, 24, 73, 61);\n
\nModifies the quality of forms created with curve() and curveVertex().\nThe parameter tightness determines how the curve fits to the vertex\npoints. The value 0.0 is the default value for tightness (this value\ndefines the curves to be Catmull-Rom splines) and the value 1.0 connects\nall the points with straight lines. Values within the range -5.0 and 5.0\nwill deform the curves but will leave them recognizable and as values\nincrease in magnitude, they will continue to deform.
\n",itemtype:"method",name:"curveTightness",params:[{name:"amount",description:"of deformation from the original vertices
\n",type:"Number"}],chainable:1,example:["\n\n// Move the mouse left and right to see the curve change\n\nfunction setup() {\n createCanvas(100, 100);\n noFill();\n}\n\nfunction draw() {\n background(204);\n var t = map(mouseX, 0, width, -5, 5);\n curveTightness(t);\n beginShape();\n curveVertex(10, 26);\n curveVertex(10, 26);\n curveVertex(83, 24);\n curveVertex(83, 61);\n curveVertex(25, 65);\n curveVertex(25, 65);\n endShape();\n}\n
\nEvaluates the curve at position t for points a, b, c, d.\nThe parameter t varies between 0 and 1, a and d are points\non the curve, and b and c are the control points.\nThis can be done once with the x coordinates and a second time\nwith the y coordinates to get the location of a curve at t.
\n",itemtype:"method",name:"curvePoint",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"}],return:{description:"bezier value at position t",type:"Number"},example:["\n\nnoFill();\ncurve(5, 26, 5, 26, 73, 24, 73, 61);\ncurve(5, 26, 73, 24, 73, 61, 15, 65);\nfill(255);\nellipseMode(CENTER);\nsteps = 6;\nfor (i = 0; i <= steps; i++) {\n t = i / steps;\n x = curvePoint(5, 5, 73, 73, t);\n y = curvePoint(26, 26, 24, 61, t);\n ellipse(x, y, 5, 5);\n x = curvePoint(5, 73, 73, 15, t);\n y = curvePoint(26, 24, 61, 65, t);\n ellipse(x, y, 5, 5);\n}\n
\nEvaluates the tangent to the curve at position t for points a, b, c, d.\nThe parameter t varies between 0 and 1, a and d are points on the curve,\nand b and c are the control points.
\n",itemtype:"method",name:"curveTangent",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"}],return:{description:"the tangent at position t",type:"Number"},example:["\n\nnoFill();\ncurve(5, 26, 73, 24, 73, 61, 15, 65);\nsteps = 6;\nfor (i = 0; i <= steps; i++) {\n t = i / steps;\n x = curvePoint(5, 73, 73, 15, t);\n y = curvePoint(26, 24, 61, 65, t);\n //ellipse(x, y, 5, 5);\n tx = curveTangent(5, 73, 73, 15, t);\n ty = curveTangent(26, 24, 61, 65, t);\n a = atan2(ty, tx);\n a -= PI/2.0;\n line(x, y, cos(a)*8 + x, sin(a)*8 + y);\n}\n
\nThe print() function writes to the console area of your browser.\nThis function is often helpful for looking at the data a program is\nproducing. This function creates a new line of text for each call to\nthe function. Individual elements can be\nseparated with quotes ("") and joined with the addition operator (+).
\n",itemtype:"method",name:"print",params:[{name:"contents",description:"any combination of Number, String, Object, Boolean,\n Array to print
\n",type:"Any"}],example:['\n\nvar x = 10;\nprint("The value of x is " + x);\n// prints "The value of x is 10"\n
The system variable frameCount contains the number of frames that have\nbeen displayed since the program started. Inside setup() the value is 0,\nafter the first iteration of draw it is 1, etc.
\n",itemtype:"property",name:"frameCount",type:"Number",readonly:"",example:["\n\n function setup() {\n frameRate(30);\n textSize(20);\n textSize(30);\n textAlign(CENTER);\n }\n\n function draw() {\n background(200);\n text(frameCount, width/2, height/2);\n }\n
Confirms if the window a p5.js program is in is "focused," meaning that\nthe sketch will accept mouse or keyboard input. This variable is\n"true" if the window is focused and "false" if not.
\n",itemtype:"property",name:"focused",type:"Boolean",readonly:"",example:['\n\n// To demonstrate, put two windows side by side.\n// Click on the window that the p5 sketch isn\'t in!\nfunction draw() {\n background(200);\n noStroke();\n fill(0, 200, 0);\n ellipse(25, 25, 50, 50);\n\n if (!focused) { // or "if (focused === false)"\n stroke(200,0,0);\n line(0, 0, 100, 100);\n line(100, 0, 0, 100);\n }\n}\n
Sets the cursor to a predefined symbol or an image, or makes it visible\nif already hidden. If you are trying to set an image as the cursor, the\nrecommended size is 16x16 or 32x32 pixels. It is not possible to load an\nimage as the cursor if you are exporting your program for the Web, and not\nall MODES work with all browsers. The values for parameters x and y must\nbe less than the dimensions of the image.
\n",itemtype:"method",name:"cursor",params:[{name:"type",description:"either ARROW, CROSS, HAND, MOVE, TEXT, or\n WAIT, or path for image
\n",type:"String|Constant"},{name:"x",description:"the horizontal active spot of the cursor
\n",type:"Number",optional:!0},{name:"y",description:"the vertical active spot of the cursor
\n",type:"Number",optional:!0}],example:["\n\n// Move the mouse left and right across the image\n// to see the cursor change from a cross to a hand\nfunction draw() {\n line(width/2, 0, width/2, height);\n if (mouseX < 50) {\n cursor(CROSS);\n } else {\n cursor(HAND);\n }\n}\n
Specifies the number of frames to be displayed every second. For example,\nthe function call frameRate(30) will attempt to refresh 30 times a second.\nIf the processor is not fast enough to maintain the specified rate, the\nframe rate will not be achieved. Setting the frame rate within setup() is\nrecommended. The default rate is 60 frames per second. This is the same as\nsetFrameRate(val).\n
\nCalling frameRate() with no arguments returns the current framerate. The\ndraw function must run at least once before it will return a value. This\nis the same as getFrameRate().\n
\nCalling frameRate() with arguments that are not of the type numbers\nor are non positive also returns current framerate.
number of frames to be displayed every second
\n",type:"Number"}],chainable:1},{line:188,params:[],return:{description:"current frameRate",type:"Number"}}]},{file:"src/core/environment.js",line:238,description:"Returns the current framerate.
\n",return:{description:"current frameRate",type:"Number"},class:"p5",module:"Environment",submodule:"Environment"},{file:"src/core/environment.js",line:247,description:"Specifies the number of frames to be displayed every second. For example,\nthe function call frameRate(30) will attempt to refresh 30 times a second.\nIf the processor is not fast enough to maintain the specified rate, the\nframe rate will not be achieved. Setting the frame rate within setup() is\nrecommended. The default rate is 60 frames per second.
\nCalling frameRate() with no arguments returns the current framerate.
\n",params:[{name:"fps",description:"number of frames to be displayed every second
\n",type:"Number",optional:!0}],class:"p5",module:"Environment",submodule:"Environment"},{file:"src/core/environment.js",line:262,description:"Hides the cursor from view.
\n",itemtype:"method",name:"noCursor",example:["\n\nfunction setup() {\n noCursor();\n}\n\nfunction draw() {\n background(200);\n ellipse(mouseX, mouseY, 10, 10);\n}\n
System variable that stores the width of the entire screen display. This\nis used to run a full-screen program on any display size.
\n",itemtype:"property",name:"displayWidth",type:"Number",readonly:"",example:['\n\ncreateCanvas(displayWidth, displayHeight);\n
System variable that stores the height of the entire screen display. This\nis used to run a full-screen program on any display size.
\n",itemtype:"property",name:"displayHeight",type:"Number",readonly:"",example:['\n\ncreateCanvas(displayWidth, displayHeight);\n
System variable that stores the width of the inner window, it maps to\nwindow.innerWidth.
\n",itemtype:"property",name:"windowWidth",type:"Number",readonly:"",example:['\n\ncreateCanvas(windowWidth, windowHeight);\n
System variable that stores the height of the inner window, it maps to\nwindow.innerHeight.
\n",itemtype:"property",name:"windowHeight",type:"Number",readonly:"",example:['\n\ncreateCanvas(windowWidth, windowHeight);\n
The windowResized() function is called once every time the browser window\nis resized. This is a good place to resize the canvas or do any other\nadjustments to accommodate the new window size.
\n",itemtype:"method",name:"windowResized",example:['\n\nfunction setup() {\n createCanvas(windowWidth, windowHeight);\n}\n\nfunction draw() {\n background(0, 100, 200);\n}\n\nfunction windowResized() {\n resizeCanvas(windowWidth, windowHeight);\n}\n
System variable that stores the width of the drawing canvas. This value\nis set by the first parameter of the createCanvas() function.\nFor example, the function call createCanvas(320, 240) sets the width\nvariable to the value 320. The value of width defaults to 100 if\ncreateCanvas() is not used in a program.
\n",itemtype:"property",name:"width",type:"Number",readonly:"",class:"p5",module:"Environment",submodule:"Environment"},{file:"src/core/environment.js",line:416,description:"System variable that stores the height of the drawing canvas. This value\nis set by the second parameter of the createCanvas() function. For\nexample, the function call createCanvas(320, 240) sets the height\nvariable to the value 240. The value of height defaults to 100 if\ncreateCanvas() is not used in a program.
\n",itemtype:"property",name:"height",type:"Number",readonly:"",class:"p5",module:"Environment",submodule:"Environment"},{file:"src/core/environment.js",line:428,description:"If argument is given, sets the sketch to fullscreen or not based on the\nvalue of the argument. If no argument is given, returns the current\nfullscreen state. Note that due to browser restrictions this can only\nbe called on user input, for example, on mouse press like the example\nbelow.
\n",itemtype:"method",name:"fullscreen",params:[{name:"val",description:"whether the sketch should be in fullscreen mode\nor not
\n",type:"Boolean",optional:!0}],return:{description:"current fullscreen state",type:"Boolean"},example:["\n\n// Clicking in the box toggles fullscreen on and off.\nfunction setup() {\n background(200);\n}\nfunction mousePressed() {\n if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {\n var fs = fullscreen();\n fullscreen(!fs);\n }\n}\n
\nSets the pixel scaling for high pixel density displays. By default\npixel density is set to match display density, call pixelDensity(1)\nto turn this off. Calling pixelDensity() with no arguments returns\nthe current pixel density of the sketch.
\n",itemtype:"method",name:"pixelDensity",params:[{name:"val",description:"whether or how much the sketch should scale
\n",type:"Number",optional:!0}],return:{description:"current pixel density of the sketch",type:"Number"},example:["\n\nfunction setup() {\n pixelDensity(1);\n createCanvas(100, 100);\n background(200);\n ellipse(width/2, height/2, 50, 50);\n}\n
\n\nfunction setup() {\n pixelDensity(3.0);\n createCanvas(100, 100);\n background(200);\n ellipse(width/2, height/2, 50, 50);\n}\n
\nReturns the pixel density of the current display the sketch is running on.
\n",itemtype:"method",name:"displayDensity",return:{description:"current pixel density of the display",type:"Number"},example:["\n\nfunction setup() {\n var density = displayDensity();\n pixelDensity(density);\n createCanvas(100, 100);\n background(200);\n ellipse(width/2, height/2, 50, 50);\n}\n
\nGets the current URL.
\n",itemtype:"method",name:"getURL",return:{description:"url",type:"String"},example:["\n\nvar url;\nvar x = 100;\n\nfunction setup() {\n fill(0);\n noStroke();\n url = getURL();\n}\n\nfunction draw() {\n background(200);\n text(url, x, height/2);\n x--;\n}\n
\nGets the current URL path as an array.
\n",itemtype:"method",name:"getURLPath",return:{description:"path components",type:"String[]"},example:["\n\nfunction setup() {\n var urlPath = getURLPath();\n for (var i=0; i<urlPath.length; i++) {\n text(urlPath[i], 10, i*20+20);\n }\n}\n
Gets the current URL params as an Object.
\n",itemtype:"method",name:"getURLParams",return:{description:"URL params",type:"Object"},example:["\n\n// Example: http://p5js.org?year=2014&month=May&day=15\n\nfunction setup() {\n var params = getURLParams();\n text(params.day, 10, 20);\n text(params.month, 10, 40);\n text(params.year, 10, 60);\n}\n
\nPrints out a fancy, colorful message to the console log
\n",params:[{name:"message",description:"the words to be said
\n",type:"String"},{name:"func",description:"the name of the function to link
\n",type:"String"},{name:"color",description:"CSS color string or error type
\n",type:"Number|String"}],return:{description:"console logs"},class:"p5",module:"Environment"},{file:"src/core/error_helpers.js",line:106,description:"Validates parameters\nparam {String} func the name of the function\nparam {Array} args user input arguments
\nexample:\n var a;\n ellipse(10,10,a,5);\nconsole ouput:\n "It looks like ellipse received an empty variable in spot #2."
\nexample:\n ellipse(10,"foo",5,5);\nconsole output:\n "ellipse was expecting a number for parameter #1,\n received "foo" instead."
\n",class:"p5",module:"Environment"},{file:"src/core/error_helpers.js",line:273,description:"Prints out all the colors in the color pallete with white text.\nFor color blindness testing.
\n",class:"p5",module:"Environment"},{file:"src/core/init.js",line:5,description:"_globalInit
\nTODO: ???\nif sketch is on window\nassume "global" mode\nand instantiate p5 automatically\notherwise do nothing
\n",return:{description:"",type:"Undefined"},class:"p5.Element",module:"Environment"},{file:"src/core/p5.Element.js",line:25,description:"Underlying HTML element. All normal HTML methods can be called on this.
\n",itemtype:"property",name:"elt",readonly:"",class:"p5.Element",module:"DOM",submodule:"DOM"},{file:"src/core/p5.Element.js",line:39,description:"Attaches the element to the parent specified. A way of setting\n the container for the element. Accepts either a string ID, DOM\n node, or p5.Element. If no arguments given, parent node is returned.\n For more ways to position the canvas, see the\n \n positioning the canvas wiki page.
\n",itemtype:"method",name:"parent",chainable:1,class:"p5.Element",module:"DOM",submodule:"DOM",overloads:[{line:39,params:[{name:"parent",description:"the ID, DOM node, or p5.Element\n of desired parent element
\n",type:"String|p5.Element|Object"}],chainable:1},{line:53,params:[],return:{description:"",type:"p5.Element"}}]},{file:"src/core/p5.Element.js",line:103,description:"Sets the ID of the element. If no ID argument is passed in, it instead\n returns the current ID of the element.
\n",itemtype:"method",name:"id",chainable:1,class:"p5.Element",module:"DOM",submodule:"DOM",overloads:[{line:103,params:[{name:"id",description:"ID of the element
\n",type:"String"}],chainable:1},{line:112,params:[],return:{description:"the id of the element",type:"String"}}]},{file:"src/core/p5.Element.js",line:141,description:"Adds given class to the element. If no class argument is passed in, it\n instead returns a string containing the current class(es) of the element.
\n",itemtype:"method",name:"class",chainable:1,class:"p5.Element",module:"DOM",submodule:"DOM",overloads:[{line:141,params:[{name:"class",description:"class to add
\n",type:"String"}],chainable:1},{line:150,params:[],return:{description:"the class of the element",type:"String"}}]},{file:"src/core/p5.Element.js",line:163,description:"The .mousePressed() function is called once after every time a\nmouse button is pressed over the element. This can be used to\nattach element specific event listeners.
\n",itemtype:"method",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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mousePressed(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires with any click anywhere\nfunction mousePressed() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
The .doubleClicked() function is called once after every time a\nmouse button is pressed twice over the element. This can be used to\nattach element and action specific event listeners.
\n",itemtype:"method",name:"doubleClicked",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.doubleClicked(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires with any double click anywhere\nfunction doubleClicked() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
The .mouseWheel() function is called once after every time a\nmouse wheel is scrolled over the element. This can be used to\nattach element specific event listeners.\n
\nThe function accepts a callback function as argument which will be executed\nwhen the wheel
event is triggered on the element, the callback function is\npassed one argument event
. The event.deltaY
property returns negative\nvalues if the mouse wheel is rotated up or away from the user and positive\nin the other direction. The event.deltaX
does the same as event.deltaY
\nexcept it reads the horizontal wheel scroll of the mouse wheel.\n
\nOn OS X with "natural" scrolling enabled, the event.deltaY
values are\nreversed.
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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseWheel(changeSize); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires with mousewheel movement\n// anywhere on screen\nfunction mouseWheel() {\n g = g + 10;\n}\n\n// this function fires with mousewheel movement\n// over canvas only\nfunction changeSize(event) {\n if (event.deltaY > 0) {\n d = d + 10;\n } else {\n d = d - 10;\n }\n}\n
The .mouseReleased() function is called once after every time a\nmouse button is released over the element. This can be used to\nattach element specific event listeners.
\n",itemtype:"method",name:"mouseReleased",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseReleased(changeGray); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires after the mouse has been\n// released\nfunction mouseReleased() {\n d = d + 10;\n}\n\n// this function fires after the mouse has been\n// released while on canvas\nfunction changeGray() {\n g = random(0, 255);\n}\n
The .mouseClicked() function is called once after a mouse button is\npressed and released over the element. This can be used to\nattach element specific event listeners.
\n",itemtype:"method",name:"mouseClicked",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\n\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseClicked(changeGray); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires after the mouse has been\n// clicked anywhere\nfunction mouseClicked() {\n d = d + 10;\n}\n\n// this function fires after the mouse has been\n// clicked on canvas\nfunction changeGray() {\n g = random(0, 255);\n}\n
\nThe .mouseMoved() function is called once every time a\nmouse moves over the element. This can be used to attach an\nelement specific event listener.
\n",itemtype:"method",name:"mouseMoved",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d = 30;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseMoved(changeSize); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n fill(200);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires when mouse moves anywhere on\n// page\nfunction mouseMoved() {\n g = g + 5;\n if (g > 255) {\n g = 0;\n }\n}\n\n// this function fires when mouse moves over canvas\nfunction changeSize() {\n d = d + 2;\n if (d > 100) {\n d = 0;\n }\n}\n
The .mouseOver() function is called once after every time a\nmouse moves onto the element. This can be used to attach an\nelement specific event listener.
\n",itemtype:"method",name:"mouseOver",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseOver(changeGray);\n d = 10;\n}\n\nfunction draw() {\n ellipse(width/2, height/2, d, d);\n}\n\nfunction changeGray() {\n d = d + 10;\n if (d > 100) {\n d = 0;\n }\n}\n
The .changed() function is called when the value of an\nelement changes.\nThis can be used to attach an element specific event listener.
\n",itemtype:"method",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.
\nvar sel;\n\nfunction setup() {\n textAlign(CENTER);\n background(200);\n sel = createSelect();\n sel.position(10, 10);\n sel.option('pear');\n sel.option('kiwi');\n sel.option('grape');\n sel.changed(mySelectEvent);\n}\n\nfunction mySelectEvent() {\n var item = sel.value();\n background(200);\n text(\"it's a \"+item+\"!\", 50, 50);\n}\n
\nvar checkbox;\nvar cnv;\n\nfunction setup() {\n checkbox = createCheckbox(\" fill\");\n checkbox.changed(changeFill);\n cnv = createCanvas(100, 100);\n cnv.position(0, 30);\n noFill();\n}\n\nfunction draw() {\n background(200);\n ellipse(50, 50, 50, 50);\n}\n\nfunction changeFill() {\n if (checkbox.checked()) {\n fill(0);\n } else {\n noFill();\n }\n}\n
The .input() function is called when any user input is\ndetected with an element. The input event is often used\nto detect keystrokes in a input element, or changes on a\nslider element. This can be used to attach an element specific\nevent listener.
\n",itemtype:"method",name:"input",params:[{name:"fxn",description:"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.
\n// Open your console to see the output\nfunction setup() {\n var inp = createInput('');\n inp.input(myInputEvent);\n}\n\nfunction myInputEvent() {\n console.log('you are typing: ', this.value());\n}\n
The .mouseOut() function is called once after every time a\nmouse moves off the element. This can be used to attach an\nelement specific event listener.
\n",itemtype:"method",name:"mouseOut",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseOut(changeGray);\n d = 10;\n}\n\nfunction draw() {\n ellipse(width/2, height/2, d, d);\n}\n\nfunction changeGray() {\n d = d + 10;\n if (d > 100) {\n d = 0;\n }\n}\n
The .touchStarted() function is called once after every time a touch is\nregistered. This can be used to attach element specific event listeners.
\n",itemtype:"method",name:"touchStarted",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.touchStarted(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires with any touch anywhere\nfunction touchStarted() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
The .touchMoved() function is called once after every time a touch move is\nregistered. This can be used to attach element specific event listeners.
\n",itemtype:"method",name:"touchMoved",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.touchMoved(changeGray); // attach listener for\n // canvas click only\n g = 100;\n}\n\nfunction draw() {\n background(g);\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
The .touchEnded() function is called once after every time a touch is\nregistered. This can be used to attach element specific event listeners.
\n",itemtype:"method",name:"touchEnded",params:[{name:"fxn",description:"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.
\nvar cnv;\nvar d;\nvar g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.touchEnded(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width/2, height/2, d, d);\n}\n\n// this function fires with any touch anywhere\nfunction touchEnded() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
The .dragOver() function is called once after every time a\nfile is dragged over the element. This can be used to attach an\nelement specific event listener.
\n",itemtype:"method",name:"dragOver",params:[{name:"fxn",description:"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.
\n// To test this sketch, simply drag a\n// file over the canvas\nfunction setup() {\n var c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('Drag file', width/2, height/2);\n c.dragOver(dragOverCallback);\n}\n\n// This function will be called whenever\n// a file is dragged over the canvas\nfunction dragOverCallback() {\n background(240);\n text('Dragged over', width/2, height/2);\n}\n
The .dragLeave() function is called once after every time a\ndragged file leaves the element area. This can be used to attach an\nelement specific event listener.
\n",itemtype:"method",name:"dragLeave",params:[{name:"fxn",description:"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.
\n// To test this sketch, simply drag a file\n// over and then out of the canvas area\nfunction setup() {\n var c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('Drag file', width/2, height/2);\n c.dragLeave(dragLeaveCallback);\n}\n\n// This function will be called whenever\n// a file is dragged out of the canvas\nfunction dragLeaveCallback() {\n background(240);\n text('Dragged off', width/2, height/2);\n}\n
The .drop() function is called for each file dropped on the element.\nIt requires a callback that is passed a p5.File object. You can\noptionally pass two callbacks, the first one (required) is triggered\nfor each file dropped when the file is loaded. The second (optional)\nis triggered just once when a file (or files) are dropped.
\n",itemtype:"method",name:"drop",params:[{name:"callback",description:"callback triggered when files are dropped.
\n",type:"Function|Boolean"},{name:"fxn",description:"callback to receive loaded file.
\n",type:"Function|Boolean"}],chainable:1,example:["\n\nfunction setup() {\n var c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('drop image', width/2, height/2);\n c.drop(gotFile);\n}\n\nfunction gotFile(file) {\n var img = createImg(file.data).hide();\n // Draw the image onto the canvas\n image(img, 0, 0, width, height);\n}\n
Helper fxn for sharing pixel methods
\n",class:"p5.Element",module:"DOM",submodule:"DOM"},{file:"src/core/p5.Renderer.js",line:72,description:"Resize our canvas element.
\n",class:"p5.Renderer",module:"Rendering",submodule:"Rendering"},{file:"src/core/p5.Renderer.js",line:146,description:"Helper fxn to check font type (system or otf)
\n",class:"p5.Renderer",module:"Rendering",submodule:"Rendering"},{file:"src/core/p5.Renderer.js",line:202,description:'Helper fxn to measure ascent and descent.\nAdapted from http://stackoverflow.com/a/25355178
\n',class:"p5.Renderer",module:"Rendering",submodule:"Rendering"},{file:"src/core/p5.Renderer2D.js",line:9,description:"p5.Renderer2D\nThe 2D graphics canvas renderer class.\nextends p5.Renderer
\n",class:"p5",module:"Rendering"},{file:"src/core/p5.Renderer2D.js",line:356,description:"Generate a cubic Bezier representing an arc on the unit circle of total\nangle size
radians, beginning start
radians above the x-axis. Up to\nfour of these curves are combined to make a full arc.
See www.joecridge.me/bezier.pdf for an explanation of the method.
\n",class:"p5",module:"Rendering"},{file:"src/core/rendering.js",line:14,description:"Creates a canvas element in the document, and sets the dimensions of it\nin pixels. This method should be called only once at the start of setup.\nCalling createCanvas more than once in a sketch will result in very\nunpredicable behavior. If you want more than one drawing canvas\nyou could use createGraphics (hidden by default but it can be shown).\n
\nThe system variables width and height are set by the parameters passed\nto this function. If createCanvas() is not used, the window will be\ngiven a default size of 100x100 pixels.\n
\nFor more ways to position the canvas, see the\n\npositioning the canvas wiki page.
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:!0}],return:{description:"canvas generated",type:"HTMLCanvasElement"},example:["\n\nfunction setup() {\n createCanvas(100, 50);\n background(153);\n line(0, 0, width, height);\n}\n
\nResizes the canvas to given width and height. The canvas will be cleared\nand draw will be called immediately, allowing the sketch to re-render itself\nin the resized canvas.
\n",itemtype:"method",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:!0}],example:['\n\nfunction setup() {\n createCanvas(windowWidth, windowHeight);\n}\n\nfunction draw() {\n background(0, 100, 200);\n}\n\nfunction windowResized() {\n resizeCanvas(windowWidth, windowHeight);\n}\n
Removes the default canvas for a p5 sketch that doesn't\nrequire a canvas
\n",itemtype:"method",name:"noCanvas",example:["\n\nfunction setup() {\n noCanvas();\n}\n
\nCreates and returns a new p5.Renderer object. Use this class if you need\nto draw into an off-screen graphics buffer. The two parameters define the\nwidth and height in pixels.
\n",itemtype:"method",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\nundefined defaults to p2d
\n",type:"Constant",optional:!0}],return:{description:"offscreen graphics buffer",type:"p5.Graphics"},example:["\n\nvar pg;\nfunction setup() {\n createCanvas(100, 100);\n pg = createGraphics(100, 100);\n}\nfunction draw() {\n background(200);\n pg.background(100);\n pg.noStroke();\n pg.ellipse(pg.width/2, pg.height/2, 50, 50);\n image(pg, 50, 50);\n image(pg, 0, 0, 50, 50);\n}\n
\nBlends the pixels in the display window according to the defined mode.\nThere is a choice of the following modes to blend the source pixels (A)\nwith the ones of pixels already in the display window (B):
\nBLEND
- linear interpolation of colours: C =\nAfactor + B. This is the default blending mode.ADD
- sum of A and BDARKEST
- only the darkest colour succeeds: C =\nmin(Afactor, B).LIGHTEST
- only the lightest colour succeeds: C =\nmax(A*factor, B).DIFFERENCE
- subtract colors from underlying image.EXCLUSION
- similar to DIFFERENCE
, but less\nextreme.MULTIPLY
- multiply the colors, result will always be\ndarker.SCREEN
- opposite multiply, uses inverse values of the\ncolors.REPLACE
- the pixels entirely replace the others and\ndon't utilize alpha (transparency) values.OVERLAY
- mix of MULTIPLY
and SCREEN\n
. Multiplies dark values, and screens light values.HARD_LIGHT
- SCREEN
when greater than 50%\ngray, MULTIPLY
when lower.SOFT_LIGHT
- mix of DARKEST
and\nLIGHTEST
. Works like OVERLAY
, but not as harsh.\nDODGE
- lightens light tones and increases contrast,\nignores darks.BURN
- darker areas are applied, increasing contrast,\nignores lights.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 or NORMAL
\n",type:"Constant"}],example:["\n\nblendMode(LIGHTEST);\nstrokeWeight(30);\nstroke(80, 150, 255);\nline(25, 25, 75, 75);\nstroke(255, 50, 50);\nline(75, 25, 25, 75);\n
\n\nblendMode(MULTIPLY);\nstrokeWeight(30);\nstroke(80, 150, 255);\nline(25, 25, 75, 75);\nstroke(255, 50, 50);\nline(75, 25, 25, 75);\n
\nshim for Uint8ClampedArray.slice\n(allows arrayCopy to work with pixels[])\nwith thanks to http://halfpapstudios.com/blog/tag/html5-canvas/\nEnumerable set to false to protect for...in from\nUint8ClampedArray.prototype pollution.
\n',class:"p5",module:"Rendering"},{file:"src/core/structure.js",line:15,description:"Stops p5.js from continuously executing the code within draw().\nIf loop() is called, the code in draw() begins to run continuously again.\nIf using noLoop() in setup(), it should be the last line inside the block.\n
\nWhen noLoop() is used, it's not possible to manipulate or access the\nscreen inside event handling functions such as mousePressed() or\nkeyPressed(). Instead, use those functions to call redraw() or loop(),\nwhich will run draw(), which can update the screen properly. This means\nthat when noLoop() has been called, no drawing can happen, and functions\nlike saveFrame() or loadPixels() may not be used.\n
\nNote that if the sketch is resized, redraw() will be called to update\nthe sketch, even after noLoop() has been specified. Otherwise, the sketch\nwould enter an odd state until loop() was called.
\nfunction setup() {\n createCanvas(100, 100);\n background(200);\n noLoop();\n}\n\nfunction draw() {\n line(10, 10, 90, 90);\n}\n
\nvar x = 0;\nfunction setup() {\n createCanvas(100, 100);\n}\n\nfunction draw() {\n background(204);\n x = x + 0.1;\n if (x > width) {\n x = 0;\n }\n line(x, 0, x, height);\n}\n\nfunction mousePressed() {\n noLoop();\n}\n\nfunction mouseReleased() {\n loop();\n}\n
By default, p5.js loops through draw() continuously, executing the code\nwithin it. However, the draw() loop may be stopped by calling noLoop().\nIn that case, the draw() loop can be resumed with loop().
\n",itemtype:"method",name:"loop",example:["\n\nvar x = 0;\nfunction setup() {\n createCanvas(100, 100);\n noLoop();\n}\n\nfunction draw() {\n background(204);\n x = x + 0.1;\n if (x > width) {\n x = 0;\n }\n line(x, 0, x, height);\n}\n\nfunction mousePressed() {\n loop();\n}\n\nfunction mouseReleased() {\n noLoop();\n}\n
The push() function saves the current drawing style settings and\ntransformations, while pop() restores these settings. Note that these\nfunctions are always used together. They allow you to change the style\nand transformation settings and later return to what you had. When a new\nstate is started with push(), it builds on the current style and transform\ninformation. The push() and pop() functions can be embedded to provide\nmore control. (See the second example for a demonstration.)\n
\npush() stores information related to the current transformation state\nand style settings controlled by the following functions: fill(),\nstroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(),\nimageMode(), rectMode(), ellipseMode(), colorMode(), textAlign(),\ntextFont(), textMode(), textSize(), textLeading().
\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\nstrokeWeight(10);\nfill(204, 153, 0);\ntranslate(50, 0);\nellipse(0, 50, 33, 33); // Middle circle\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n
\n\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\nstrokeWeight(10);\nfill(204, 153, 0);\nellipse(33, 50, 33, 33); // Left-middle circle\n\npush(); // Start another new drawing state\nstroke(0, 102, 153);\nellipse(66, 50, 33, 33); // Right-middle circle\npop(); // Restore previous state\n\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n
\nThe push() function saves the current drawing style settings and\ntransformations, while pop() restores these settings. Note that these\nfunctions are always used together. They allow you to change the style\nand transformation settings and later return to what you had. When a new\nstate is started with push(), it builds on the current style and transform\ninformation. The push() and pop() functions can be embedded to provide\nmore control. (See the second example for a demonstration.)\n
\npush() stores information related to the current transformation state\nand style settings controlled by the following functions: fill(),\nstroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(),\nimageMode(), rectMode(), ellipseMode(), colorMode(), textAlign(),\ntextFont(), textMode(), textSize(), textLeading().
\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\ntranslate(50, 0);\nstrokeWeight(10);\nfill(204, 153, 0);\nellipse(0, 50, 33, 33); // Middle circle\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n
\n\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\nstrokeWeight(10);\nfill(204, 153, 0);\nellipse(33, 50, 33, 33); // Left-middle circle\n\npush(); // Start another new drawing state\nstroke(0, 102, 153);\nellipse(66, 50, 33, 33); // Right-middle circle\npop(); // Restore previous state\n\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n
\nExecutes the code within draw() one time. This functions allows the\n program to update the display window only when necessary, for example\n when an event registered by mousePressed() or keyPressed() occurs.\n
\n In structuring a program, it only makes sense to call redraw() within\n events such as mousePressed(). This is because redraw() does not run\n draw() immediately (it only sets a flag that indicates an update is\n needed).\n
\n The redraw() function does not work properly when called inside draw().\n To enable/disable animations, use loop() and noLoop().\n
\n In addition you can set the number of redraws per method call. Just\n add an integer as single parameter for the number of redraws.
Redraw for n-times. The default value is 1.
\n",type:"Integer",optional:!0}],example:["\n\n var x = 0;\nfunction setup() {\n createCanvas(100, 100);\n noLoop();\n }\nfunction draw() {\n background(204);\n line(x, 0, x, height);\n }\nfunction mousePressed() {\n x += 1;\n redraw();\n }\n
\n var x = 0;\nfunction setup() {\n createCanvas(100, 100);\n noLoop();\n }\nfunction draw() {\n background(204);\n x += 1;\n line(x, 0, x, height);\n }\nfunction mousePressed() {\n redraw(5);\n }\n
Multiplies the current matrix by the one specified through the parameters.\nThis is a powerful operation that can perform the equivalent of translate,\nscale, shear and rotate all at once. You can learn more about transformation\nmatrices on \nWikipedia.
\nThe naming of the arguments here follows the naming of the \nWHATWG specification and corresponds to a\ntransformation matrix of the\nform:
\n\n\n\n',itemtype:"method",name:"applyMatrix",params:[{name:"a",description:"
numbers which define the 2x3 matrix to be multiplied
\n",type:"Number"},{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"}],chainable:1,example:["\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20;\n background(200);\n // Equivalent to translate(x, y);\n applyMatrix(1, 0, 0, 1, 40 + step, 50);\n rect(0, 0, 50, 50);\n}\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20;\n background(200);\n translate(50, 50);\n // Equivalent to scale(x, y);\n applyMatrix(1 / step, 0, 0, 1 / step, 0, 0);\n rect(0, 0, 50, 50);\n}\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20\n var angle = map(step, 0, 20, 0, TWO_PI);\n var cos_a = cos(angle);\n var sin_a = sin(angle);\n background(200);\n translate(50, 50);\n // Equivalent to rotate(angle);\n applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0);\n rect(0, 0, 50, 50);\n}\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20\n var angle = map(step, 0, 20, -PI/4, PI/4);\n background(200);\n translate(50, 50);\n // equivalent to shearX(angle);\n var shear_factor = 1 / tan(PI/2 - angle);\n applyMatrix(1, 0, shear_factor, 1, 0, 0);\n rect(0, 0, 50, 50);\n}\n
\nReplaces the current matrix with the identity matrix.
\n",itemtype:"method",name:"resetMatrix",chainable:1,example:["\n\ntranslate(50, 50);\napplyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0);\nrect(0, 0, 20, 20);\n// Note that the translate is also reset.\nresetMatrix();\nrect(0, 0, 20, 20);\n
\nRotates a shape the amount specified by the angle parameter. This\nfunction accounts for angleMode, so angles can be entered in either\nRADIANS or DEGREES.\n
\nObjects are always rotated around their relative position to the\norigin and positive numbers rotate objects in a clockwise direction.\nTransformations apply to everything that happens after and subsequent\ncalls to the function accumulates the effect. For example, calling\nrotate(HALF_PI) and then rotate(HALF_PI) is the same as rotate(PI).\nAll tranformations are reset when draw() begins again.\n
\nTechnically, rotate() multiplies the current transformation matrix\nby a rotation matrix. This function can be further controlled by\nthe push() and pop().
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|Array",optional:!0}],chainable:1,example:["\n\ntranslate(width/2, height/2);\nrotate(PI/3.0);\nrect(-26, -26, 52, 52);\n
\nRotates around X axis.
\n",itemtype:"method",name:"rotateX",params:[{name:"rad",description:"angles in radians
\n",type:"Number"}],chainable:1,class:"p5",module:"Transform",submodule:"Transform"},{file:"src/core/transform.js",line:233,description:"Rotates around Y axis.
\n",itemtype:"method",name:"rotateY",params:[{name:"rad",description:"angles in radians
\n",type:"Number"}],chainable:1,class:"p5",module:"Transform",submodule:"Transform"},{file:"src/core/transform.js",line:248,description:"Rotates around Z axis. Webgl mode only.
\n",itemtype:"method",name:"rotateZ",params:[{name:"rad",description:"angles in radians
\n",type:"Number"}],chainable:1,class:"p5",module:"Transform",submodule:"Transform"},{file:"src/core/transform.js",line:263,description:"Increases or decreases the size of a shape by expanding and contracting\nvertices. Objects always scale from their relative origin to the\ncoordinate system. Scale values are specified as decimal percentages.\nFor example, the function call scale(2.0) increases the dimension of a\nshape by 200%.\n
\nTransformations apply to everything that happens after and subsequent\ncalls to the function multiply the effect. For example, calling scale(2.0)\nand then scale(1.5) is the same as scale(3.0). If scale() is called\nwithin draw(), the transformation is reset when the loop begins again.\n
\nUsing this function with the z parameter is only available in WEBGL mode.\nThis function can be further controlled with push() and pop().
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|Array"},{name:"y",description:"percent to scale the object in the y-axis
\n",type:"Number",optional:!0},{name:"z",description:"percent to scale the object in the z-axis (webgl only)
\n",type:"Number",optional:!0}],chainable:1,example:["\n\ntranslate(width/2, height/2);\nrotate(PI/3.0);\nrect(-26, -26, 52, 52);\n
\n\nrect(30, 20, 50, 50);\nscale(0.5, 1.3);\nrect(30, 20, 50, 50);\n
\nShears a shape around the x-axis the amount specified by the angle\nparameter. Angles should be specified in the current angleMode.\nObjects are always sheared around their relative position to the origin\nand positive numbers shear objects in a clockwise direction.\n
\nTransformations apply to everything that happens after and subsequent\ncalls to the function accumulates the effect. For example, calling\nshearX(PI/2) and then shearX(PI/2) is the same as shearX(PI).\nIf shearX() is called within the draw(), the transformation is reset when\nthe loop begins again.\n
\nTechnically, shearX() multiplies the current transformation matrix by a\nrotation matrix. This function can be further controlled by the\npush() and pop() functions.
angle of shear specified in radians or degrees,\n depending on current angleMode
\n",type:"Number"}],chainable:1,example:["\n\ntranslate(width/4, height/4);\nshearX(PI/4.0);\nrect(0, 0, 30, 30);\n
\nShears a shape around the y-axis the amount specified by the angle\nparameter. Angles should be specified in the current angleMode. Objects\nare always sheared around their relative position to the origin and\npositive numbers shear objects in a clockwise direction.\n
\nTransformations apply to everything that happens after and subsequent\ncalls to the function accumulates the effect. For example, calling\nshearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If\nshearY() is called within the draw(), the transformation is reset when\nthe loop begins again.\n
\nTechnically, shearY() multiplies the current transformation matrix by a\nrotation matrix. This function can be further controlled by the\npush() and pop() functions.
angle of shear specified in radians or degrees,\n depending on current angleMode
\n",type:"Number"}],chainable:1,example:["\n\ntranslate(width/4, height/4);\nshearY(PI/4.0);\nrect(0, 0, 30, 30);\n
\nSpecifies an amount to displace objects within the display window.\nThe x parameter specifies left/right translation, the y parameter\nspecifies up/down translation.\n
\nTransformations are cumulative and apply to everything that happens after\nand subsequent calls to the function accumulates the effect. For example,\ncalling translate(50, 0) and then translate(20, 0) is the same as\ntranslate(70, 0). If translate() is called within draw(), the\ntransformation is reset when the loop begins again. This function can be\nfurther controlled by using push() and pop().
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:!0}],chainable:1,example:["\n\ntranslate(30, 20);\nrect(0, 0, 55, 55);\n
\n\nrect(0, 0, 55, 55); // Draw rect at original 0,0\ntranslate(30, 20);\nrect(0, 0, 55, 55); // Draw rect at new 0,0\ntranslate(14, 14);\nrect(0, 0, 55, 55); // Draw rect at new 0,0\n
\nUse the beginContour() and endContour() functions to create negative\nshapes within shapes such as the center of the letter 'O'. beginContour()\nbegins recording vertices for the shape and endContour() stops recording.\nThe vertices that define a negative shape must "wind" in the opposite\ndirection from the exterior shape. First draw vertices for the exterior\nclockwise order, then for internal shapes, draw vertices\nshape in counter-clockwise.\n
\nThese functions can only be used within a beginShape()/endShape() pair and\ntransformations such as translate(), rotate(), and scale() do not work\nwithin a beginContour()/endContour() pair. It is also not possible to use\nother shapes, such as ellipse() or rect() within.
\ntranslate(50, 50);\nstroke(255, 0, 0);\nbeginShape();\n// Exterior part of shape, clockwise winding\nvertex(-40, -40);\nvertex(40, -40);\nvertex(40, 40);\nvertex(-40, 40);\n// Interior part of shape, counter-clockwise winding\nbeginContour();\nvertex(-20, -20);\nvertex(-20, 20);\nvertex(20, 20);\nvertex(20, -20);\nendContour();\nendShape(CLOSE);\n
\nUsing the beginShape() and endShape() functions allow creating more\ncomplex forms. beginShape() begins recording vertices for a shape and\nendShape() stops recording. The value of the kind parameter tells it which\ntypes of shapes to create from the provided vertices. With no mode\nspecified, the shape can be any irregular polygon.\n
\nThe parameters available for beginShape() are POINTS, LINES, TRIANGLES,\nTRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP. After calling the\nbeginShape() function, a series of vertex() commands must follow. To stop\ndrawing the shape, call endShape(). Each shape will be outlined with the\ncurrent stroke color and filled with the fill color.\n
\nTransformations such as translate(), rotate(), and scale() do not work\nwithin beginShape(). It is also not possible to use other shapes, such as\nellipse() or rect() within beginShape().
either POINTS, LINES, TRIANGLES, TRIANGLE_FAN\n TRIANGLE_STRIP, QUADS, or QUAD_STRIP
\n",type:"Constant",optional:!0}],chainable:1,example:["\n\nbeginShape();\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape(CLOSE);\n
\n\n// currently not working\nbeginShape(POINTS);\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n
\n\nbeginShape(LINES);\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n
\n\nnoFill();\nbeginShape();\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n
\n\nnoFill();\nbeginShape();\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape(CLOSE);\n
\n\nbeginShape(TRIANGLES);\nvertex(30, 75);\nvertex(40, 20);\nvertex(50, 75);\nvertex(60, 20);\nvertex(70, 75);\nvertex(80, 20);\nendShape();\n
\n\nbeginShape(TRIANGLE_STRIP);\nvertex(30, 75);\nvertex(40, 20);\nvertex(50, 75);\nvertex(60, 20);\nvertex(70, 75);\nvertex(80, 20);\nvertex(90, 75);\nendShape();\n
\n\nbeginShape(TRIANGLE_FAN);\nvertex(57.5, 50);\nvertex(57.5, 15);\nvertex(92, 50);\nvertex(57.5, 85);\nvertex(22, 50);\nvertex(57.5, 15);\nendShape();\n
\n\nbeginShape(QUADS);\nvertex(30, 20);\nvertex(30, 75);\nvertex(50, 75);\nvertex(50, 20);\nvertex(65, 20);\nvertex(65, 75);\nvertex(85, 75);\nvertex(85, 20);\nendShape();\n
\n\nbeginShape(QUAD_STRIP);\nvertex(30, 20);\nvertex(30, 75);\nvertex(50, 20);\nvertex(50, 75);\nvertex(65, 20);\nvertex(65, 75);\nvertex(85, 20);\nvertex(85, 75);\nendShape();\n
\n\nbeginShape();\nvertex(20, 20);\nvertex(40, 20);\nvertex(40, 40);\nvertex(60, 40);\nvertex(60, 60);\nvertex(20, 60);\nendShape(CLOSE);\n
\nSpecifies vertex coordinates for Bezier curves. Each call to\nbezierVertex() defines the position of two control points and\none anchor point of a Bezier curve, adding a new segment to a\nline or shape.\n
\nThe first time bezierVertex() is used within a\nbeginShape() call, it must be prefaced with a call to vertex()\nto set the first anchor point. This function must be used between\nbeginShape() and endShape() and only when there is no MODE\nparameter specified to beginShape().
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,example:["\n\nnoFill();\nbeginShape();\nvertex(30, 20);\nbezierVertex(80, 0, 80, 75, 30, 75);\nendShape();\n
\n\nbeginShape();\nvertex(30, 20);\nbezierVertex(80, 0, 80, 75, 30, 75);\nbezierVertex(50, 80, 60, 25, 30, 20);\nendShape();\n
\nSpecifies vertex coordinates for curves. This function may only\nbe used between beginShape() and endShape() and only when there\nis no MODE parameter specified to beginShape().\n
\nThe first and last points in a series of curveVertex() lines will be used to\nguide the beginning and end of a the curve. A minimum of four\npoints is required to draw a tiny curve between the second and\nthird points. Adding a fifth point with curveVertex() will draw\nthe curve between the second, third, and fourth points. The\ncurveVertex() function is an implementation of Catmull-Rom\nsplines.
x-coordinate of the vertex
\n",type:"Number"},{name:"y",description:"y-coordinate of the vertex
\n",type:"Number"}],chainable:1,example:["\n\nnoFill();\nbeginShape();\ncurveVertex(84, 91);\ncurveVertex(84, 91);\ncurveVertex(68, 19);\ncurveVertex(21, 17);\ncurveVertex(32, 100);\ncurveVertex(32, 100);\nendShape();\n
\nUse the beginContour() and endContour() functions to create negative\nshapes within shapes such as the center of the letter 'O'. beginContour()\nbegins recording vertices for the shape and endContour() stops recording.\nThe vertices that define a negative shape must "wind" in the opposite\ndirection from the exterior shape. First draw vertices for the exterior\nclockwise order, then for internal shapes, draw vertices\nshape in counter-clockwise.\n
\nThese functions can only be used within a beginShape()/endShape() pair and\ntransformations such as translate(), rotate(), and scale() do not work\nwithin a beginContour()/endContour() pair. It is also not possible to use\nother shapes, such as ellipse() or rect() within.
\ntranslate(50, 50);\nstroke(255, 0, 0);\nbeginShape();\n// Exterior part of shape, clockwise winding\nvertex(-40, -40);\nvertex(40, -40);\nvertex(40, 40);\nvertex(-40, 40);\n// Interior part of shape, counter-clockwise winding\nbeginContour();\nvertex(-20, -20);\nvertex(-20, 20);\nvertex(20, 20);\nvertex(20, -20);\nendContour();\nendShape(CLOSE);\n
\nThe endShape() function is the companion to beginShape() and may only be\ncalled after beginShape(). When endshape() is called, all of image data\ndefined since the previous call to beginShape() is written into the image\nbuffer. The constant CLOSE as the value for the MODE parameter to close\nthe shape (to connect the beginning and the end).
\n",itemtype:"method",name:"endShape",params:[{name:"mode",description:"use CLOSE to close the shape
\n",type:"Constant",optional:!0}],chainable:1,example:["\n\nnoFill();\n\nbeginShape();\nvertex(20, 20);\nvertex(45, 20);\nvertex(45, 80);\nendShape(CLOSE);\n\nbeginShape();\nvertex(50, 20);\nvertex(75, 20);\nvertex(75, 80);\nendShape();\n
\nSpecifies vertex coordinates for quadratic Bezier curves. Each call to\nquadraticVertex() defines the position of one control points and one\nanchor point of a Bezier curve, adding a new segment to a line or shape.\nThe first time quadraticVertex() is used within a beginShape() call, it\nmust be prefaced with a call to vertex() to set the first anchor point.\nThis function must be used between beginShape() and endShape() and only\nwhen there is no MODE parameter specified to beginShape().
\n",itemtype:"method",name:"quadraticVertex",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,example:["\n\nnoFill();\nstrokeWeight(4);\nbeginShape();\nvertex(20, 20);\nquadraticVertex(80, 20, 50, 50);\nendShape();\n
\n\nnoFill();\nstrokeWeight(4);\nbeginShape();\nvertex(20, 20);\nquadraticVertex(80, 20, 50, 50);\nquadraticVertex(20, 80, 80, 80);\nvertex(80, 60);\nendShape();\n
\nAll shapes are constructed by connecting a series of vertices. vertex()\nis used to specify the vertex coordinates for points, lines, triangles,\nquads, and polygons. It is used exclusively within the beginShape() and\nendShape() functions.
\n",itemtype:"method",name:"vertex",params:[{name:"x",description:"x-coordinate of the vertex
\n",type:"Number"},{name:"y",description:"y-coordinate of the vertex
\n",type:"Number"},{name:"z",description:"z-coordinate of the vertex
\n",type:"Number|Boolean",optional:!0}],chainable:1,example:["\n\nbeginShape(POINTS);\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n
\nCreates a new instance of p5.StringDict using the key, value pair\n or object you provide.
\n",itemtype:"method",name:"createStringDict",params:[{name:"key",description:"or object
\n",type:"String|Object"},{name:"value",description:"",type:"String"}],return:{description:"",type:"p5.StringDict"},class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:32,description:"Creates a new instance of p5.NumberDict using the key, value pair\n or object you provide.
\n",itemtype:"method",name:"createNumberDict",params:[{name:"key",description:"or object
\n",type:"Number|Object"},{name:"value",description:"",type:"Number"}],return:{description:"",type:"p5.NumberDict"},class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:68,description:"Returns the number of key-value pairs currently in Dictionary object
\n",itemtype:"method",name:"size",return:{description:"the number of key-value pairs in Dictionary object",type:"Number"},example:['\n\n\nfunction setup() {\n var myDictionary = createNumberDict(1, 10);\n myDictionary.create(2, 20);\n myDictionary.create(3, 30);\n var amt = myDictionary.size(); // value of amt is 3\n}\n\n
Returns true if key exists in Dictionary\notherwise returns false
\n",itemtype:"method",name:"hasKey",params:[{name:"key",description:"that you want to access
\n",type:"Number|String"}],return:{description:"whether that key exists in Dictionary",type:"Boolean"},example:["\n\n\nfunction setup() {\n var myDictionary = createStringDict('p5', 'js');\n print(myDictionary.hasKey('p5')); // logs true to console\n}\n\n
Returns value stored at supplied key.
\n",itemtype:"method",name:"get",params:[{name:"key",description:"that you want to access
\n",type:"Number|String"}],return:{description:"the value stored at that key",type:"Number|String"},example:["\n\n\nfunction setup() {\n var myDictionary = createStringDict('p5', 'js');\n var myValue = myDictionary.get('p5');\n print(myValue === 'js'); // logs true to console\n}\n\n
Changes the value of key if in it already exists in\nin the Dictionary otherwise makes a new key-value pair
\n",itemtype:"method",name:"set",params:[{name:"key",description:"",type:"Number|String"},{name:"value",description:"",type:"Number|String"}],example:["\n\n\nfunction setup() {\n var myDictionary = createStringDict('p5', 'js');\n myDictionary.set('p5', 'JS');\n myDictionary.print()\n // above logs \"key: p5 - value: JS\" to console\n}\n\n
private helper function to handle the user passing objects in\nduring construction or calls to create()
\n",class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:194,description:"Removes a key-value pair in the Dictionary
\n",itemtype:"method",name:"create",class:"p5.TypedDict",module:"Data",submodule:"Dictionary",overloads:[{line:194,params:[{name:"key",description:"",type:"Number|String"},{name:"value",description:"",type:"Number|String"}]},{line:201,params:[{name:"obj",description:"key/value pair
\n",type:"Object"}]}]},{file:"src/data/p5.TypedDict.js",line:234,description:"Empties Dictionary of all key-value pairs
\n",itemtype:"method",name:"clear",class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:245,description:"Removes a key-value pair in the Dictionary
\n",itemtype:"method",name:"remove",params:[{name:"key",description:"for the pair to remove
\n",type:"Number|String"}],example:["\n\n\nfunction setup() {\n var myDictionary = createStringDict('p5', 'js');\n myDictionary.create('happy', 'coding');\n myDictionary.print()\n // above logs \"key: p5 - value: js, key: happy - value: coding\" to console\n myDictionary.remove('p5');\n myDictionary.print();\n // above logs \"key: happy value: coding\" to console\n}\n\n
Logs the list of items currently in the Dictionary to the console
\n",itemtype:"method",name:"print",class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:289,description:"Converts the Dictionary into a CSV file for local\nstorage.
\n",itemtype:"method",name:"saveTable",class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:310,description:"Converts the Dictionary into a JSON file for local\nstorage.
\n",itemtype:"method",name:"saveJSON",class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:321,description:"private helper function to ensure that the user passed in valid\nvalues for the Dictionary type
\n",class:"p5.TypedDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:368,description:"private helper function to ensure that the user passed in valid\nvalues for the Dictionary type
\n",class:"p5.NumberDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:377,description:"Add to a value stored at a certain key\nThe sum is stored in that location in the Dictionary.
\n",itemtype:"method",name:"add",params:[{name:"Key",description:"for value you wish to add to
\n",type:"Number"},{name:"Amount",description:"to add to the value
\n",type:"Number"}],example:["\n\nfunction setup() {\n var myDictionary = createNumberDict(2, 5);\n myDictionary.add(2, 2);\n console.log(myDictionary.get(2)); // logs 7 to console.\n}\n
Subtract from a value stored at a certain key\nThe difference is stored in that location in the Dictionary.
\n",itemtype:"method",name:"sub",params:[{name:"Key",description:"for value you wish to subtract from
\n",type:"Number"},{name:"Amount",description:"to subtract from the value
\n",type:"Number"}],example:["\n\nfunction setup() {\n var myDictionary = createNumberDict(2, 5);\n myDictionary.sub(2, 2);\n console.log(myDictionary.get(2)); // logs 3 to console.\n}\n
Multiply a value stored at a certain key\nThe product is stored in that location in the Dictionary.
\n",itemtype:"method",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"}],example:["\n\nfunction setup() {\n var myDictionary = createNumberDict(2, 4);\n myDictionary.mult(2, 2);\n console.log(myDictionary.get(2)); // logs 8 to console.\n}\n
Divide a value stored at a certain key\nThe quotient is stored in that location in the Dictionary.
\n",itemtype:"method",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"}],example:["\n\nfunction setup() {\n var myDictionary = createNumberDict(2, 8);\n myDictionary.div(2, 2);\n console.log(myDictionary.get(2)); // logs 4 to console.\n}\n
private helper function for finding lowest or highest value\nthe argument 'flip' is used to flip the comparison arrow\nfrom 'less than' to 'greater than'
\n",class:"p5.NumberDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:508,description:"Return the lowest value.
\n",itemtype:"method",name:"minValue",return:{description:"",type:"Number"},example:["\n\nfunction setup() {\n var myDictionary = createNumberDict({2 : -10, 4 : 0.65, 1.2 : 3});\n var lowestValue = myDictionary.minValue(); // value is -10\n}\n
Return the highest value.
\n",itemtype:"method",name:"maxValue",return:{description:"",type:"Number"},example:["\n\nfunction setup() {\n var myDictionary = createNumberDict({2 : -10, 4 : 0.65, 1.2 : 3});\n var highestValue = myDictionary.maxValue(); // value is 3\n}\n
private helper function for finding lowest or highest key\nthe argument 'flip' is used to flip the comparison arrow\nfrom 'less than' to 'greater than'
\n",class:"p5.NumberDict",module:"Data",submodule:"Dictionary"},{file:"src/data/p5.TypedDict.js",line:571,description:"Return the lowest key.
\n",itemtype:"method",name:"minKey",return:{description:"",type:"Number"},example:["\n\nfunction setup() {\n var myDictionary = createNumberDict({2 : 4, 4 : 6, 1.2 : 3});\n var lowestKey = myDictionary.minKey(); // value is 1.2\n}\n
Return the highest key.
\n",itemtype:"method",name:"maxKey",return:{description:"",type:"Number"},example:["\n\nfunction setup() {\n var myDictionary = createNumberDict({ 2 : 4, 4 : 6, 1.2 : 3});\n var highestKey = myDictionary.maxKey(); // value is 4\n}\n
The system variable deviceOrientation always contains the orientation of\nthe device. The value of this variable will either be set 'landscape'\nor 'portrait'. If no data is available it will be set to 'undefined'.\neither LANDSCAPE or PORTRAIT.
\n",itemtype:"property",name:"deviceOrientation",type:"Constant",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:23,description:"The system variable accelerationX always contains the acceleration of the\ndevice along the x axis. Value is represented as meters per second squared.
\n",itemtype:"property",name:"accelerationX",type:"Number",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:32,description:"The system variable accelerationY always contains the acceleration of the\ndevice along the y axis. Value is represented as meters per second squared.
\n",itemtype:"property",name:"accelerationY",type:"Number",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:41,description:"The system variable accelerationZ always contains the acceleration of the\ndevice along the z axis. Value is represented as meters per second squared.
\n",itemtype:"property",name:"accelerationZ",type:"Number",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:50, description:"The system variable pAccelerationX always contains the acceleration of the\ndevice along the x axis in the frame previous to the current frame. Value\nis represented as meters per second squared.
\n",itemtype:"property",name:"pAccelerationX",type:"Number",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:60,description:"The system variable pAccelerationY always contains the acceleration of the\ndevice along the y axis in the frame previous to the current frame. Value\nis represented as meters per second squared.
\n",itemtype:"property",name:"pAccelerationY",type:"Number",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:70,description:"The system variable pAccelerationZ always contains the acceleration of the\ndevice along the z axis in the frame previous to the current frame. Value\nis represented as meters per second squared.
\n",itemtype:"property",name:"pAccelerationZ",type:"Number",readonly:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:80,description:"_updatePAccelerations updates the pAcceleration values
\n",access:"private",tagname:"",class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:91,description:"The system variable rotationX always contains the rotation of the\ndevice along the x axis. Value is represented as 0 to +/-180 degrees.\n
\nNote: The order the rotations are called is important, ie. if used\ntogether, it must be called in the order Z-X-Y or there might be\nunexpected behaviour.
\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n //rotateZ(radians(rotationZ));\n rotateX(radians(rotationX));\n //rotateY(radians(rotationY));\n box(200, 200, 200);\n}\n
\nThe system variable rotationY always contains the rotation of the\ndevice along the y axis. Value is represented as 0 to +/-90 degrees.\n
\nNote: The order the rotations are called is important, ie. if used\ntogether, it must be called in the order Z-X-Y or there might be\nunexpected behaviour.
\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n //rotateZ(radians(rotationZ));\n //rotateX(radians(rotationX));\n rotateY(radians(rotationY));\n box(200, 200, 200);\n}\n
\nThe system variable rotationZ always contains the rotation of the\ndevice along the z axis. Value is represented as 0 to 359 degrees.\n
\nUnlike rotationX and rotationY, this variable is available for devices\nwith a built-in compass only.\n
\nNote: The order the rotations are called is important, ie. if used\ntogether, it must be called in the order Z-X-Y or there might be\nunexpected behaviour.
\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n rotateZ(radians(rotationZ));\n //rotateX(radians(rotationX));\n //rotateY(radians(rotationY));\n box(200, 200, 200);\n}\n
\nThe system variable pRotationX always contains the rotation of the\ndevice along the x axis in the frame previous to the current frame. Value\nis represented as 0 to +/-180 degrees.\n
\npRotationX can also be used with rotationX to determine the rotate\ndirection of the device along the X-axis.
\n// A simple if statement looking at whether\n// rotationX - pRotationX < 0 is true or not will be\n// sufficient for determining the rotate direction\n// in most cases.\n\n// Some extra logic is needed to account for cases where\n// the angles wrap around.\nvar rotateDirection = 'clockwise';\n\n// Simple range conversion to make things simpler.\n// This is not absolutely neccessary but the logic\n// will be different in that case.\n\nvar rX = rotationX + 180;\nvar pRX = pRotationX + 180;\n\nif ((rX - pRX > 0 && rX - pRX < 270)|| rX - pRX < -270){\n rotateDirection = 'clockwise';\n} else if (rX - pRX < 0 || rX - pRX > 270){\n rotateDirection = 'counter-clockwise';\n}\n
\nThe system variable pRotationY always contains the rotation of the\ndevice along the y axis in the frame previous to the current frame. Value\nis represented as 0 to +/-90 degrees.\n
\npRotationY can also be used with rotationY to determine the rotate\ndirection of the device along the Y-axis.
\n// A simple if statement looking at whether\n// rotationY - pRotationY < 0 is true or not will be\n// sufficient for determining the rotate direction\n// in most cases.\n\n// Some extra logic is needed to account for cases where\n// the angles wrap around.\nvar rotateDirection = 'clockwise';\n\n// Simple range conversion to make things simpler.\n// This is not absolutely neccessary but the logic\n// will be different in that case.\n\nvar rY = rotationY + 180;\nvar pRY = pRotationY + 180;\n\nif ((rY - pRY > 0 && rY - pRY < 270)|| rY - pRY < -270){\n rotateDirection = 'clockwise';\n} else if (rY - pRY < 0 || rY - pRY > 270){\n rotateDirection = 'counter-clockwise';\n}\n
\nThe system variable pRotationZ always contains the rotation of the\ndevice along the z axis in the frame previous to the current frame. Value\nis represented as 0 to 359 degrees.\n
\npRotationZ can also be used with rotationZ to determine the rotate\ndirection of the device along the Z-axis.
\n// A simple if statement looking at whether\n// rotationZ - pRotationZ < 0 is true or not will be\n// sufficient for determining the rotate direction\n// in most cases.\n\n// Some extra logic is needed to account for cases where\n// the angles wrap around.\nvar rotateDirection = 'clockwise';\n\nif ((rotationZ - pRotationZ > 0 &&\n rotationZ - pRotationZ < 270)||\n rotationZ - pRotationZ < -270){\n\n rotateDirection = 'clockwise';\n\n} else if (rotationZ - pRotationZ < 0 ||\n rotationZ - pRotationZ > 270){\n\n rotateDirection = 'counter-clockwise';\n\n}\n
\nThe setMoveThreshold() function is used to set the movement threshold for\nthe deviceMoved() function. The default threshold is set to 0.5.
\n",itemtype:"method",name:"setMoveThreshold",params:[{name:"value",description:"The threshold value
\n",type:"Number"}],class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:359,description:"The setShakeThreshold() function is used to set the movement threshold for\nthe deviceShaken() function. The default threshold is set to 30.
\n",itemtype:"method",name:"setShakeThreshold",params:[{name:"value",description:"The threshold value
\n",type:"Number"}],class:"p5",module:"Events",submodule:"Acceleration"},{file:"src/events/acceleration.js",line:372,description:"The deviceMoved() function is called when the device is moved by more than\nthe threshold value along X, Y or Z axis. The default threshold is set to\n0.5.
\n",itemtype:"method",name:"deviceMoved",example:['\n\n// Run this example on a mobile device\n// Move the device around\n// to change the value.\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceMoved() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n
\nThe deviceTurned() function is called when the device rotates by\nmore than 90 degrees continuously.\n
\nThe axis that triggers the deviceTurned() method is stored in the turnAxis\nvariable. The deviceTurned() method can be locked to trigger on any axis:\nX, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'.
\n// Run this example on a mobile device\n// Rotate the device by 90 degrees\n// to change the value.\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceTurned() {\n if (value == 0){\n value = 255\n } else if (value == 255) {\n value = 0;\n }\n}\n
\n\n// Run this example on a mobile device\n// Rotate the device by 90 degrees in the\n// X-axis to change the value.\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceTurned() {\n if (turnAxis == 'X'){\n if (value == 0){\n value = 255\n } else if (value == 255) {\n value = 0;\n }\n }\n}\n
\nThe deviceShaken() function is called when the device total acceleration\nchanges of accelerationX and accelerationY values is more than\nthe threshold value. The default threshold is set to 30.
\n",itemtype:"method",name:"deviceShaken",example:['\n\n// Run this example on a mobile device\n// Shake the device to change the value.\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceShaken() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n
\nHolds the key codes of currently pressed keys.
\n",access:"private",tagname:"",class:"p5",module:"Events",submodule:"Keyboard"},{file:"src/events/keyboard.js",line:18,description:"The boolean system variable keyIsPressed is true if any key is pressed\nand false if no keys are pressed.
\n",itemtype:"property",name:"keyIsPressed",type:"Boolean",readonly:"",example:["\n\nvar value = 0;\nfunction draw() {\n if (keyIsPressed === true) {\n fill(0);\n } else {\n fill(255);\n }\n rect(25, 25, 50, 50);\n}\n
\nThe system variable key always contains the value of the most recent\nkey on the keyboard that was typed. To get the proper capitalization, it\nis best to use it within keyTyped(). For non-ASCII keys, use the keyCode\nvariable.
\n",itemtype:"property",name:"key",type:"String",readonly:"",example:["\n\n// Click any key to display it!\n// (Not Guaranteed to be Case Sensitive)\nfunction setup() {\n fill(245, 123, 158);\n textSize(50);\n}\n\nfunction draw() {\n background(200);\n text(key, 33,65); // Display last key pressed.\n}\n
The variable keyCode is used to detect special keys such as BACKSPACE,\nDELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW,\nDOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.\nYou can also check for custom keys by looking up the keyCode of any key\non a site like this: keycode.info.
\n',itemtype:"property",name:"keyCode",type:"Number",readonly:"",example:["\n\nvar fillVal = 126;\nfunction draw() {\n fill(fillVal);\n rect(25, 25, 50, 50);\n}\n\nfunction keyPressed() {\n if (keyCode == UP_ARROW) {\n fillVal = 255;\n } else if (keyCode == DOWN_ARROW) {\n fillVal = 0;\n }\n return false; // prevent default\n}\n
The keyPressed() function is called once every time a key is pressed. The\nkeyCode for the key that was pressed is stored in the keyCode variable.\n
\nFor non-ASCII keys, use the keyCode variable. You can check if the keyCode\nequals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL,\nOPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.\n
\nFor ASCII keys that was pressed is stored in the key variable. However, it\ndoes not distinguish between uppercase and lowercase. For this reason, it\nis recommended to use keyTyped() to read the key variable, in which the\ncase of the variable will be distinguished.\n
\nBecause of how operating systems handle key repeats, holding down a key\nmay cause multiple calls to keyTyped() (and keyReleased() as well). The\nrate of repeat is set by the operating system and how each computer is\nconfigured.
\nBrowsers may have different default\nbehaviors attached to various key events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyPressed() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyPressed() {\n if (keyCode === LEFT_ARROW) {\n value = 255;\n } else if (keyCode === RIGHT_ARROW) {\n value = 0;\n }\n}\n
\n\nfunction keyPressed(){\n // Do something\n return false; // prevent any default behaviour\n}\n
\nThe keyReleased() function is called once every time a key is released.\nSee key and keyCode for more information.
\nBrowsers may have different default\nbehaviors attached to various key events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyReleased() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n return false; // prevent any default behavior\n}\n
\nThe keyTyped() function is called once every time a key is pressed, but\naction keys such as Ctrl, Shift, and Alt are ignored. The most recent\nkey pressed will be stored in the key variable.\n
\nBecause of how operating systems handle key repeats, holding down a key\nwill cause multiple calls to keyTyped() (and keyReleased() as well). The\nrate of repeat is set by the operating system and how each computer is\nconfigured.
\nBrowsers may have different default behaviors attached to various key\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.
\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyTyped() {\n if (key === 'a') {\n value = 255;\n } else if (key === 'b') {\n value = 0;\n }\n // uncomment to prevent any default behavior\n // return false;\n}\n
\nThe onblur function is called when the user is no longer focused\non the p5 element. Because the keyup events will not fire if the user is\nnot focused on the element we must assume all keys currently down have\nbeen released.
\n",class:"p5",module:"Events",submodule:"Keyboard"},{file:"src/events/keyboard.js",line:317,description:'The keyIsDown() function checks if the key is currently down, i.e. pressed.\nIt can be used if you have an object that moves, and you want several keys\nto be able to affect its behaviour simultaneously, such as moving a\nsprite diagonally. You can put in any number representing the keyCode of\nthe key, or use any of the variable keyCode names listed\nhere.
\n',itemtype:"method",name:"keyIsDown",params:[{name:"code",description:"The key to check for.
\n",type:"Number"}],return:{description:"whether key is down or not",type:"Boolean"},example:["\n\nvar x = 100;\nvar y = 100;\n\nfunction setup() {\n createCanvas(512, 512);\n}\n\nfunction draw() {\n if (keyIsDown(LEFT_ARROW))\n x-=5;\n\n if (keyIsDown(RIGHT_ARROW))\n x+=5;\n\n if (keyIsDown(UP_ARROW))\n y-=5;\n\n if (keyIsDown(DOWN_ARROW))\n y+=5;\n\n clear();\n fill(255, 0, 0);\n ellipse(x, y, 50, 50);\n}\n
The checkDownKeys function returns a boolean true if any keys pressed\nand a false if no keys are currently pressed.
\nHelps avoid instances where a multiple keys are pressed simultaneously and\nreleasing a single key will then switch the\nkeyIsPressed property to true.
\n",access:"private",tagname:"",class:"p5",module:"Events",submodule:"Keyboard"},{file:"src/events/mouse.js",line:23,description:"The system variable mouseX always contains the current horizontal\nposition of the mouse, relative to (0, 0) of the canvas. If touch is\nused instead of mouse input, mouseX will hold the x value of the most\nrecent touch point.
\n",itemtype:"property",name:"mouseX",type:"Number",readonly:"",example:["\n\n// Move the mouse across the canvas\nfunction draw() {\n background(244, 248, 252);\n line(mouseX, 0, mouseX, 100);\n}\n
\nThe system variable mouseY always contains the current vertical position\nof the mouse, relative to (0, 0) of the canvas. If touch is\nused instead of mouse input, mouseY will hold the y value of the most\nrecent touch point.
\n",itemtype:"property",name:"mouseY",type:"Number",readonly:"",example:["\n\n// Move the mouse across the canvas\nfunction draw() {\n background(244, 248, 252);\n line(0, mouseY, 100, mouseY);\n}\n
\nThe system variable pmouseX always contains the horizontal position of\nthe mouse or finger in the frame previous to the current frame, relative to\n(0, 0) of the canvas.
\n",itemtype:"property",name:"pmouseX",type:"Number",readonly:"",example:['\n\n// Move the mouse across the canvas to leave a trail\nfunction setup() {\n //slow down the frameRate to make it more visible\n frameRate(10);\n}\n\nfunction draw() {\n background(244, 248, 252);\n line(mouseX, mouseY, pmouseX, pmouseY);\n print(pmouseX + " -> " + mouseX);\n}\n\n
\nThe system variable pmouseY always contains the vertical position of the\nmouse or finger in the frame previous to the current frame, relative to\n(0, 0) of the canvas.
\n",itemtype:"property",name:"pmouseY",type:"Number",readonly:"",example:['\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n //draw a square only if the mouse is not moving\n if(mouseY == pmouseY && mouseX == pmouseX)\n rect(20,20,60,60);\n\n print(pmouseY + " -> " + mouseY);\n}\n\n
\nThe system variable winMouseX always contains the current horizontal\nposition of the mouse, relative to (0, 0) of the window.
\n",itemtype:"property",name:"winMouseX",type:"Number",readonly:"",example:["\n\nvar myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n}\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n //move the canvas to the horizontal mouse position\n //relative to the window\n myCanvas.position(winMouseX+1, windowHeight/2);\n\n //the y of the square is relative to the canvas\n rect(20,mouseY,60,60);\n}\n\n
\nThe system variable winMouseY always contains the current vertical\nposition of the mouse, relative to (0, 0) of the window.
\n",itemtype:"property",name:"winMouseY",type:"Number",readonly:"",example:["\n\nvar myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n}\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n //move the canvas to the vertical mouse position\n //relative to the window\n myCanvas.position(windowWidth/2, winMouseY+1);\n\n //the x of the square is relative to the canvas\n rect(mouseX,20,60,60);\n}\n\n
\nThe system variable pwinMouseX always contains the horizontal position\nof the mouse in the frame previous to the current frame, relative to\n(0, 0) of the window.
\n",itemtype:"property",name:"pwinMouseX",type:"Number",readonly:"",example:["\n\n\nvar myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n noStroke();\n fill(237, 34, 93);\n }\n\nfunction draw() {\n clear();\n //the difference between previous and\n //current x position is the horizontal mouse speed\n var speed = abs(winMouseX-pwinMouseX);\n //change the size of the circle\n //according to the horizontal speed\n ellipse(50, 50, 10+speed*5, 10+speed*5);\n //move the canvas to the mouse position\n myCanvas.position( winMouseX+1, winMouseY+1);\n}\n\n
\nThe system variable pwinMouseY always contains the vertical position of\nthe mouse in the frame previous to the current frame, relative to (0, 0)\nof the window.
\n",itemtype:"property",name:"pwinMouseY",type:"Number",readonly:"",example:["\n\n\nvar myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n noStroke();\n fill(237, 34, 93);\n }\n\nfunction draw() {\n clear();\n //the difference between previous and\n //current y position is the vertical mouse speed\n var speed = abs(winMouseY-pwinMouseY);\n //change the size of the circle\n //according to the vertical speed\n ellipse(50, 50, 10+speed*5, 10+speed*5);\n //move the canvas to the mouse position\n myCanvas.position( winMouseX+1, winMouseY+1);\n}\n\n
\nProcessing automatically tracks if the mouse button is pressed and which\nbutton is pressed. The value of the system variable mouseButton is either\nLEFT, RIGHT, or CENTER depending on which button was pressed last.\nWarning: different browsers may track mouseButton differently.
\n",itemtype:"property",name:"mouseButton",type:"Constant",readonly:"",example:["\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n if (mouseIsPressed) {\n if (mouseButton == LEFT)\n ellipse(50, 50, 50, 50);\n if (mouseButton == RIGHT)\n rect(25, 25, 50, 50);\n if (mouseButton == CENTER)\n triangle(23, 75, 50, 20, 78, 75);\n }\n\n print(mouseButton);\n}\n
\nThe boolean system variable mouseIsPressed is true if the mouse is pressed\nand false if not.
\n",itemtype:"property",name:"mouseIsPressed",type:"Boolean",readonly:"",example:["\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n if (mouseIsPressed)\n ellipse(50, 50, 50, 50);\n else\n rect(25, 25, 50, 50);\n\n print(mouseIsPressed);\n}\n
\nThe mouseMoved() function is called every time the mouse moves and a mouse\nbutton is not pressed.
\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\n// Move the mouse across the page\n// to change its value\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mouseMoved() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n
\n\nfunction mouseMoved() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe mouseDragged() function is called once every time the mouse moves and\na mouse button is pressed. If no mouseDragged() function is defined, the\ntouchMoved() function will be called instead if it is defined.
\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\n// Drag the mouse across the page\n// to change its value\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mouseDragged() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n
\n\nfunction mouseDragged() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe mousePressed() function is called once after every time a mouse button\nis pressed. The mouseButton variable (see the related reference entry)\ncan be used to determine which button has been pressed. If no\nmousePressed() function is defined, the touchStarted() function will be\ncalled instead if it is defined.
\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\n// Click within the image to change\n// the value of the rectangle\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mousePressed() {\n if (value == 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nfunction mousePressed() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe mouseReleased() function is called every time a mouse button is\nreleased. If no mouseReleased() function is defined, the touchEnded()\nfunction will be called instead if it is defined.
\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\n// Click within the image to change\n// the value of the rectangle\n// after the mouse has been clicked\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mouseReleased() {\n if (value == 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nfunction mouseReleased() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe mouseClicked() function is called once after a mouse button has been\npressed and then released.
\nBrowsers handle clicks differently, so this function is only guaranteed to be\nrun when the left mouse button is clicked. To handle other mouse buttons\nbeing pressed or released, see mousePressed() or mouseReleased().
\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.
\n// Click within the image to change\n// the value of the rectangle\n// after the mouse has been clicked\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\n\nfunction mouseClicked() {\n if (value == 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nfunction mouseClicked() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe doubleClicked() function is executed every time a event\nlistener has detected a dblclick event which is a part of the\nDOM L3 specification. The doubleClicked event is fired when a\npointing device button (usually a mouse's primary button)\nis clicked twice on a single element. For more info on the\ndblclick event refer to mozilla's documentation here:\nhttps://developer.mozilla.org/en-US/docs/Web/Events/dblclick
\n',itemtype:"method",name:"doubleClicked",example:['\n\n// Click within the image to change\n// the value of the rectangle\n// after the mouse has been double clicked\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\n\nfunction doubleClicked() {\n if (value == 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nfunction doubleClicked() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe function mouseWheel() is executed every time a vertical mouse wheel\nevent is detected either triggered by an actual mouse wheel or by a\ntouchpad.
\nThe event.delta property returns the amount the mouse wheel\nhave scrolled. The values can be positive or negative depending on the\nscroll direction (on OS X with "natural" scrolling enabled, the signs\nare inverted).
\nBrowsers may have different default behaviors attached to various\nmouse events. To prevent any default behavior for this event, add\n"return false" to the end of the method.
\nDue to the current support of the "wheel" event on Safari, the function\nmay only work as expected if "return false" is included while using Safari.
\nvar pos = 25;\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n rect(25, pos, 50, 50);\n}\n\nfunction mouseWheel(event) {\n print(event.delta);\n //move the square according to the vertical scroll amount\n pos += event.delta;\n //uncomment to block page scrolling\n //return false;\n}\n
\nThe system variable touches[] contains an array of the positions of all\ncurrent touch points, relative to (0, 0) of the canvas, and IDs identifying a\nunique touch as it moves. Each element in the array is an object with x, y,\nand id properties.
\nThe touches[] array is not supported on Safari and IE on touch-based\ndesktops (laptops).
\n",itemtype:"property",name:"touches",type:"Object[]",readonly:"",class:"p5",module:"Events",submodule:"Touch"},{file:"src/events/touch.js",line:53,description:"The touchStarted() function is called once after every time a touch is\nregistered. If no touchStarted() function is defined, the mousePressed()\nfunction will be called instead if it is defined.
\nBrowsers may have different default behaviors attached to various touch\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.
\n// Touch within the image to change\n// the value of the rectangle\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction touchStarted() {\n if (value == 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nfunction touchStarted() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe touchMoved() function is called every time a touch move is registered.\nIf no touchMoved() function is defined, the mouseDragged() function will\nbe called instead if it is defined.
\nBrowsers may have different default behaviors attached to various touch\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.
\n// Move your finger across the page\n// to change its value\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction touchMoved() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n
\n\nfunction touchMoved() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThe touchEnded() function is called every time a touch ends. If no\ntouchEnded() function is defined, the mouseReleased() function will be\ncalled instead if it is defined.
\nBrowsers may have different default behaviors attached to various touch\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.
\n// Release touch within the image to\n// change the value of the rectangle\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction touchEnded() {\n if (value == 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n
\n\nfunction touchEnded() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n
\nThis module defines the filters for use with image buffers.
\nThis module is basically a collection of functions stored in an object\nas opposed to modules. The functions are destructive, modifying\nthe passed in canvas rather than creating a copy.
\nGenerally speaking users of this module will use the Filters.apply method\non a canvas to create an effect.
\nA number of functions are borrowed/adapted from\nhttp://www.html5rocks.com/en/tutorials/canvas/imagefilters/\nor the java processing implementation.
\n',class:"p5",module:"Events"},{file:"src/image/filters.js",line:28,description:"Returns the pixel buffer for a canvas
\n",access:"private",tagname:"",params:[{name:"canvas",description:"the canvas to get pixels from
\n",type:"Canvas|ImageData"}],return:{description:"a one-dimensional array containing\n the data in thc RGBA order, with integer\n values between 0 and 255",type:"Uint8ClampedArray"},class:"p5",module:"Events"},{file:"src/image/filters.js",line:51,description:"Returns a 32 bit number containing ARGB data at ith pixel in the\n1D array containing pixels data.
\n",access:"private",tagname:"",params:[{name:"data",description:"array returned by _toPixels()
\n",type:"Uint8ClampedArray"},{name:"i",description:"index of a 1D Image Array
\n",type:"Integer"}],return:{description:"32 bit integer value representing\n ARGB value.",type:"Integer"},class:"p5",module:"Events"},{file:"src/image/filters.js",line:70,description:"Modifies pixels RGBA values to values contained in the data object.
\n",access:"private",tagname:"",params:[{name:"pixels",description:"array returned by _toPixels()
\n",type:"Uint8ClampedArray"},{name:"data",description:"source 1D array where each value\n represents ARGB values
\n",type:"Int32Array"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:90,description:'Returns the ImageData object for a canvas\nhttps://developer.mozilla.org/en-US/docs/Web/API/ImageData
\n',access:"private",tagname:"",params:[{name:"canvas",description:"canvas to get image data from
\n",type:"Canvas|ImageData"}],return:{description:"Holder of pixel data (and width and\n height) for a canvas",type:"ImageData"},class:"p5",module:"Events"},{file:"src/image/filters.js",line:113,description:"Returns a blank ImageData object.
\n",access:"private",tagname:"",params:[{name:"width",description:"",type:"Integer"},{name:"height",description:"",type:"Integer"}],return:{description:"",type:"ImageData"},class:"p5",module:"Events"},{file:"src/image/filters.js",line:129,description:"Applys a filter function to a canvas.
\nThe difference between this and the actual filter functions defined below\nis that the filter functions generally modify the pixel buffer but do\nnot actually put that data back to the canvas (where it would actually\nupdate what is visible). By contrast this method does make the changes\nactually visible in the canvas.
\nThe apply method is the method that callers of this module would generally\nuse. It has been separated from the actual filters to support an advanced\nuse case of creating a filter chain that executes without actually updating\nthe canvas in between everystep.
\n",params:[{name:"canvas",description:"[description]
\n",type:"HTMLCanvasElement"},{name:"func",description:"[description]
\n",type:"Function(ImageData,Object)"},{name:"filterParam",description:"[description]
\n",type:"Object"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:167,description:'Converts the image to black and white pixels depending if they are above or\nbelow the threshold defined by the level parameter. The parameter must be\nbetween 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.
\nBorrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
\n',params:[{name:"canvas",description:"",type:"Canvas"},{name:"level",description:"",type:"Float"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:202,description:'Converts any colors in the image to grayscale equivalents.\nNo parameter is used.
\nBorrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
\n',params:[{name:"canvas",description:"",type:"Canvas"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:224,description:"Sets the alpha channel to entirely opaque. No parameter is used.
\n",params:[{name:"canvas",description:"",type:"Canvas"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:239,description:"Sets each pixel to its inverse value. No parameter is used.
\n",params:[{name:"canvas",description:"",type:"Canvas"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:255,description:"Limits each channel of the image to the number of colors specified as\nthe parameter. The parameter can be set to values between 2 and 255, but\nresults are most noticeable in the lower ranges.
\nAdapted from java based processing implementation
\n",params:[{name:"canvas",description:"",type:"Canvas"},{name:"level",description:"",type:"Integer"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:286,description:"reduces the bright areas in an image
\n",params:[{name:"canvas",description:"",type:"Canvas"}],class:"p5",module:"Events"},{file:"src/image/filters.js",line:367,description:"increases the bright areas in an image
\n",params:[{name:"canvas",description:"",type:"Canvas"}],class:"p5",module:"Events"},{file:"src/image/image.js",line:8,description:"This module defines the p5 methods for the p5.Image class\nfor drawing images to the main display canvas.
\n",class:"p5",module:"Image",submodule:"Image"},{file:"src/image/image.js",line:24,description:"Creates a new p5.Image (the datatype for storing images). This provides a\nfresh buffer of pixels to play with. Set the size of the buffer with the\nwidth and height parameters.\n
\n.pixels gives access to an array containing the values for all the pixels\nin the display window.\nThese values are numbers. This array is the size (including an appropriate\nfactor for the pixelDensity) of the display window x4,\nrepresenting the R, G, B, A values in order for each pixel, moving from\nleft to right across each row, then down each column. See .pixels for\nmore info. It may also be simpler to use set() or get().\n
\nBefore accessing the pixels of an image, the data must loaded with the\nloadPixels() function. After the array data has been modified, the\nupdatePixels() function must be run to update the changes.
width in pixels
\n",type:"Integer"},{name:"height",description:"height in pixels
\n",type:"Integer"}],return:{description:"the p5.Image object",type:"p5.Image"},example:["\n\nimg = createImage(66, 66);\nimg.loadPixels();\nfor (i = 0; i < img.width; i++) {\n for (j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\n
\n\nimg = createImage(66, 66);\nimg.loadPixels();\nfor (i = 0; i < img.width; i++) {\n for (j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102, i % img.width * 2));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\nimage(img, 34, 34);\n
\n\nvar pink = color(255, 102, 204);\nimg = createImage(66, 66);\nimg.loadPixels();\nvar d = pixelDensity();\nvar halfImage = 4 * (width * d) * (height/2 * d);\nfor (var i = 0; i < halfImage; i+=4) {\n img.pixels[i] = red(pink);\n img.pixels[i+1] = green(pink);\n img.pixels[i+2] = blue(pink);\n img.pixels[i+3] = alpha(pink);\n}\nimg.updatePixels();\nimage(img, 17, 17);\n
\nSave the current canvas as an image. In Safari, this will open the\nimage in the window and the user must provide their own\nfilename on save-as. Other browsers will either save the\nfile immediately, or prompt the user with a dialogue window.
\n",itemtype:"method",name:"saveCanvas",class:"p5",module:"Image",submodule:"Image",overloads:[{line:103,params:[{name:"selectedCanvas",description:"a variable\n representing a specific html5 canvas (optional)
\n",type:"p5.Element|HTMLCanvasElement"},{name:"filename",description:"",type:"String",optional:!0},{name:"extension",description:"'jpg' or 'png'
\n",type:"String",optional:!0}]},{line:115,params:[{name:"filename",description:"",type:"String",optional:!0},{name:"extension",description:"",type:"String",optional:!0}]}]},{file:"src/image/image.js",line:233,description:'Capture a sequence of frames that can be used to create a movie.\nAccepts a callback. For example, you may wish to send the frames\nto a server where they can be stored or converted into a movie.\nIf no callback is provided, the browser will pop up save dialogues in an\nattempt to download all of the images that have just been created. With the\ncallback provided the image data isn't saved by default but instead passed\nas an argument to the callback function as an array of objects, with the\nsize of array equal to the total number of frames.
\nNote that saveFrames() will only save the first 15 frames of an animation.\nTo export longer animations, you might look into a library like\nccapture.js.
\n',itemtype:"method",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:!0}],example:['\n\nfunction draw() {\n background(mouseX);\n}\n\nfunction mousePressed() {\n saveFrames("out", "png", 1, 25, function(data){\n print(data);\n });\n}\n
Loads an image from a path and creates a p5.Image from it.\n
\nThe image may not be immediately available for rendering\nIf you want to ensure that the image is ready before doing\nanything with it, place the loadImage() call in preload().\nYou may also supply a callback function to handle the image when it's ready.\n
\nThe path to the image should be relative to the HTML file\nthat links in your sketch. Loading an image from a URL or other\nremote location may be blocked due to your browser's built-in\nsecurity.
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:!0},{name:"failureCallback",description:"called with event error if\n the image fails to load.
\n",type:"Function(Event)",optional:!0}],return:{description:"the p5.Image object",type:"p5.Image"},example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/laDefense.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n}\n
\n\nfunction setup() {\n // here we use a callback to display the image after loading\n loadImage("assets/laDefense.jpg", function(img) {\n image(img, 0, 0);\n });\n}\n
\nValidates clipping params. Per drawImage spec sWidth and sHight cannot be\nnegative or greater than image intrinsic width and height
\n",access:"private",tagname:"",params:[{name:"sVal",description:"",type:"Number"},{name:"iVal",description:"",type:"Number"}],return:{description:"",type:"Number"},class:"p5",module:"Image",submodule:"Loading & Displaying"},{file:"src/image/loading_displaying.js",line:125,description:'Draw an image to the p5.js canvas.
\nThis function can be used with different numbers of parameters. The\nsimplest use requires only three parameters: img, x, and y—where (x, y) is\nthe position of the image. Two more parameters can optionally be added to\nspecify the width and height of the image.
\nThis function can also be used with all eight Number parameters. To\ndifferentiate between all these parameters, p5.js uses the language of\n"destination rectangle" (which corresponds to "dx", "dy", etc.) and "source\nimage" (which corresponds to "sx", "sy", etc.) below. Specifying the\n"source image" dimensions can be useful when you want to display a\nsubsection of the source image instead of the whole thing. Here's a diagram\nto explain further:\n
\n',itemtype:"method",name:"image",example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/laDefense.jpg");\n}\nfunction setup() {\n // Top-left corner of the img is at (0, 0)\n // Width and height are the img\'s original width and height\n image(img, 0, 0);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/laDefense.jpg");\n}\nfunction setup() {\n background(50);\n // Top-left corner of the img is at (10, 10)\n // Width and height are 50 x 50\n image(img, 10, 10, 50, 50);\n}\n
\n\nfunction setup() {\n // Here, we use a callback to display the image after loading\n loadImage("assets/laDefense.jpg", function(img) {\n image(img, 0, 0);\n });\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/gradient.png");\n}\nfunction setup() {\n // 1. Background image\n // Top-left corner of the img is at (0, 0)\n // Width and height are the img\'s original width and height, 100 x 100\n image(img, 0, 0);\n // 2. Top right image\n // Top-left corner of destination rectangle is at (50, 0)\n // Destination rectangle width and height are 40 x 20\n // The next parameters are relative to the source image:\n // - Starting at position (50, 50) on the source image, capture a 50 x 50\n // subsection\n // - Draw this subsection to fill the dimensions of the destination rectangle\n image(img, 50, 0, 40, 20, 50, 50, 50, 50);\n}\n
\nthe image to display
\n",type:"p5.Image|p5.Graphics"},{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:!0},{name:"height",description:"the height to draw the image
\n",type:"Number",optional:!0}]},{line:213,params:[{name:"img",description:"",type:"p5.Image|p5.Graphics"},{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:!0},{name:"sHeight",description:"the height of the subsection of the\n source image to draw into the destination rectangle
\n",type:"Number",optional:!0}]}]},{file:"src/image/loading_displaying.js",line:289,description:"Sets the fill value for displaying images. Images can be tinted to\nspecified colors or made transparent by including an alpha value.\n
\nTo apply transparency to an image without affecting its color, use\nwhite as the tint color and specify an alpha value. For instance,\ntint(255, 128) will make an image 50% transparent (assuming the default\nalpha range of 0-255, which can be changed with colorMode()).\n
\nThe value for the gray parameter must be less than or equal to the current\nmaximum value as specified by colorMode(). The default maximum value is\n255.
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:!0}]},{line:313,params:[{name:"value",description:"a color string
\n",type:"String"},{name:"alpha",description:"",type:"Number",optional:!0}]},{line:319,params:[{name:"values",description:"an array containing the red,green,blue &\n and alpha components of the color
\n",type:"Number[]"}]},{line:325,params:[{name:"color",description:"the tint color
\n",type:"p5.Color"},{name:"alpha",description:"",type:"Number",optional:!0}]}]},{file:"src/image/loading_displaying.js",line:384,description:"Removes the current fill value for displaying images and reverts to\ndisplaying images with their original hues.
\n",itemtype:"method",name:"noTint",example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n tint(0, 153, 204); // Tint blue\n image(img, 0, 0);\n noTint(); // Disable tint\n image(img, 50, 0);\n}\n
\nApply the current tint color to the input image, return the resulting\ncanvas.
\n",params:[{name:"The",description:"image to be tinted
\n",type:"p5.Image"}],return:{description:"The resulting tinted canvas",type:"Canvas"},class:"p5",module:"Image",submodule:"Loading & Displaying"},{file:"src/image/loading_displaying.js",line:449,description:"Set image mode. Modifies the location from which images are drawn by\nchanging the way in which parameters given to image() are interpreted.\nThe default mode is imageMode(CORNER), which interprets the second and\nthird parameters of image() as the upper-left corner of the image. If\ntwo additional parameters are specified, they are used to set the image's\nwidth and height.\n
\nimageMode(CORNERS) interprets the second and third parameters of image()\nas the location of one corner, and the fourth and fifth parameters as the\nopposite corner.\n
\nimageMode(CENTER) interprets the second and third parameters of image()\nas the image's center point. If two additional parameters are specified,\nthey are used to set the image's width and height.
either CORNER, CORNERS, or CENTER
\n",type:"Constant"}],example:['\n\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n imageMode(CORNER);\n image(img, 10, 10, 50, 50);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n imageMode(CORNERS);\n image(img, 10, 10, 90, 40);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n imageMode(CENTER);\n image(img, 50, 50, 80, 80);\n}\n
\nThis module defines the p5.Image class and P5 methods for\ndrawing images to the main display canvas.
\n",class:"p5.Image",module:"Image",submodule:"Image"},{file:"src/image/p5.Image.js",line:45,description:"Image width.
\n",itemtype:"property",name:"width",type:"Number",readonly:"",example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n createCanvas(100, 100);\n image(img, 0, 0);\n for (var i=0; i < img.width; i++) {\n var c = img.get(i, img.height/2);\n stroke(c);\n line(i, height/2, i, height);\n }\n}\n
Image height.
\n",itemtype:"property",name:"height",type:"Number",readonly:"",example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n createCanvas(100, 100);\n image(img, 0, 0);\n for (var i=0; i < img.height; i++) {\n var c = img.get(img.width/2, i);\n stroke(c);\n line(0, i, width/2, i);\n }\n}\n
Array containing the values for all the pixels in the display window.\nThese values are numbers. This array is the size (include an appropriate\nfactor for pixelDensity) of the display window x4,\nrepresenting the R, G, B, A values in order for each pixel, moving from\nleft to right across each row, then down each column. Retina and other\nhigh denisty displays may have more pixels[] (by a factor of\npixelDensity^2).\nFor example, if the image is 100x100 pixels, there will be 40,000. With\npixelDensity = 2, there will be 160,000. The first four values\n(indices 0-3) in the array will be the R, G, B, A values of the pixel at\n(0, 0). The second four values (indices 4-7) will contain the R, G, B, A\nvalues of the pixel at (1, 0). More generally, to set values for a pixel\nat (x, y):
\nvar d = pixelDensity;\nfor (var i = 0; i < d; i++) {\n for (var j = 0; j < d; j++) {\n // loop over\n idx = 4 * ((y * d + j) * width * d + (x * d + i));\n pixels[idx] = r;\n pixels[idx+1] = g;\n pixels[idx+2] = b;\n pixels[idx+3] = a;\n }\n}\n
\n
\nBefore accessing this array, the data must loaded with the loadPixels()\nfunction. After the array data has been modified, the updatePixels()\nfunction must be run to update the changes.
\nimg = createImage(66, 66);\nimg.loadPixels();\nfor (i = 0; i < img.width; i++) {\n for (j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\n
\n\nvar pink = color(255, 102, 204);\nimg = createImage(66, 66);\nimg.loadPixels();\nfor (var i = 0; i < 4*(width*height/2); i+=4) {\n img.pixels[i] = red(pink);\n img.pixels[i+1] = green(pink);\n img.pixels[i+2] = blue(pink);\n img.pixels[i+3] = alpha(pink);\n}\nimg.updatePixels();\nimage(img, 17, 17);\n
\nHelper fxn for sharing pixel methods
\n",class:"p5.Image",module:"Image",submodule:"Image"},{file:"src/image/p5.Image.js",line:186,description:"Loads the pixels data for this image into the [pixels] attribute.
\n",itemtype:"method",name:"loadPixels",example:['\n\nvar myImage;\nvar halfImage;\n\nfunction preload() {\n myImage = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n myImage.loadPixels();\n halfImage = 4 * width * height/2;\n for(var i = 0; i < halfImage; i++){\n myImage.pixels[i+halfImage] = myImage.pixels[i];\n }\n myImage.updatePixels();\n}\n\nfunction draw() {\n image(myImage, 0, 0);\n}\n
Updates the backing canvas for this image with the contents of\nthe [pixels] array.
\n",itemtype:"method",name:"updatePixels",class:"p5.Image",module:"Image",submodule:"Image",overloads:[{line:222,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"}]},{line:236,params:[]}]},{file:"src/image/p5.Image.js",line:270,description:"Get a region of pixels from an image.
\nIf no params are passed, those whole image is returned,\nif x and y are the only params passed a single pixel is extracted\nif all params are passed a rectangle region is extracted and a p5.Image\nis returned.
\nReturns undefined if the region is outside the bounds of the image
\n",itemtype:"method",name:"get",params:[{name:"x",description:"x-coordinate of the pixel
\n",type:"Number",optional:!0},{name:"y",description:"y-coordinate of the pixel
\n",type:"Number",optional:!0},{name:"w",description:"width
\n",type:"Number",optional:!0},{name:"h",description:"height
\n",type:"Number",optional:!0}],return:{description:"color of pixel at x,y in array format\n [R, G, B, A] or p5.Image",type:"Number[]|Color|p5.Image"},example:['\n\nvar myImage;\nvar c;\n\nfunction preload() {\n myImage = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n background(myImage);\n noStroke();\n c = myImage.get(60, 90);\n fill(c);\n rect(25, 25, 50, 50);\n}\n\n//get() returns color here\n
Set the color of a single pixel or write an image into\nthis p5.Image.
\nNote that for a large number of pixels this will\nbe slower than directly manipulating the pixels array\nand then calling updatePixels().
\n",itemtype:"method",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|Array|Object"}],example:["\n\nimg = createImage(66, 66);\nimg.loadPixels();\nfor (i = 0; i < img.width; i++) {\n for (j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102, i % img.width * 2));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\nimage(img, 34, 34);\n
\nResize the image to a new width and height. To make the image scale\nproportionally, use 0 as the value for the wide or high parameter.\nFor instance, to make the width of an image 150 pixels, and change\nthe height using the same proportion, use resize(150, 0).
\n",itemtype:"method",name:"resize",params:[{name:"width",description:"the resized image width
\n",type:"Number"},{name:"height",description:"the resized image height
\n",type:"Number"}],example:['\n\nvar img;\n\nfunction setup() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction draw() {\n image(img, 0, 0);\n}\n\nfunction mousePressed() {\n img.resize(50, 100);\n}\n
Copies a region of pixels from one image to another. If no\nsrcImage is specified this is used as the source. If the source\nand destination regions aren't the same size, it will\nautomatically resize source pixels to fit the specified\ntarget region.
\n",itemtype:"method",name:"copy",params:[{name:"srcImage",description:"source image
\n",type:"p5.Image|p5.Graphics|undefined"},{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"}],example:['\n\nvar photo;\nvar bricks;\nvar x;\nvar y;\n\nfunction preload() {\n photo = loadImage("assets/rockies.jpg");\n bricks = loadImage("assets/bricks.jpg");\n}\n\nfunction setup() {\n x = bricks.width/2;\n y = bricks.height/2;\n photo.copy(bricks, 0, 0, x, y, 0, 0, x, y);\n image(photo, 0, 0);\n}\n
Masks part of an image from displaying by loading another\nimage and using it's alpha channel as an alpha channel for\nthis image.
\n",itemtype:"method",name:"mask",params:[{name:"srcImage",description:"source image
\n",type:"p5.Image"}],example:['\n\nvar photo, maskImage;\nfunction preload() {\n photo = loadImage("assets/rockies.jpg");\n maskImage = loadImage("assets/mask2.png");\n}\n\nfunction setup() {\n createCanvas(100, 100);\n photo.mask(maskImage);\n image(photo, 0, 0);\n}\n
Applies an image filter to a p5.Image
\n",itemtype:"method",name:"filter",params:[{name:"operation",description:"one of threshold, gray, invert, posterize, opaque\n erode, dilate and blur. See Filters.js for docs on\n each available filter
\n",type:"String"},{name:"value",description:"",type:"Number|undefined"}],example:['\n\nvar photo1;\nvar photo2;\n\nfunction preload() {\n photo1 = loadImage("assets/rockies.jpg");\n photo2 = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n photo2.filter("gray");\n image(photo1, 0, 0);\n image(photo2, width/2, 0);\n}\n
Copies a region of pixels from one image to another, using a specified\nblend mode to do the operation.
\n",itemtype:"method",name:"blend",params:[{name:"srcImage",description:"source image
\n",type:"p5.Image|undefined"},{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
\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:"Integer"}],example:['\n\nvar mountains;\nvar bricks;\n\nfunction preload() {\n mountains = loadImage("assets/rockies.jpg");\n bricks = loadImage("assets/bricks_third.jpg");\n}\n\nfunction setup() {\n mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);\n image(mountains, 0, 0);\n image(bricks, 0, 0);\n}\n
\nvar mountains;\nvar bricks;\n\nfunction preload() {\n mountains = loadImage("assets/rockies.jpg");\n bricks = loadImage("assets/bricks_third.jpg");\n}\n\nfunction setup() {\n mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);\n image(mountains, 0, 0);\n image(bricks, 0, 0);\n}\n
\nvar mountains;\nvar bricks;\n\nfunction preload() {\n mountains = loadImage("assets/rockies.jpg");\n bricks = loadImage("assets/bricks_third.jpg");\n}\n\nfunction setup() {\n mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);\n image(mountains, 0, 0);\n image(bricks, 0, 0);\n}\n
helper method for web GL mode to indicate that an image has been\nchanged or unchanged since last upload. gl texture upload will\nset this value to false after uploading the texture.
\n",itemtype:"method",name:"setModified",params:[{name:"val",description:"sets whether or not the image has been\nmodified.
\n",type:"Boolean"}],access:"private",tagname:"",class:"p5.Image",module:"Image",submodule:"Image"},{file:"src/image/p5.Image.js",line:671,description:"helper method for web GL mode to figure out if the image\nhas been modified and might need to be re-uploaded to texture\nmemory between frames.
\n",itemtype:"method",name:"isModified",access:"private",tagname:"",return:{description:"a boolean indicating whether or not the\nimage has been updated or modified since last texture upload.",type:"Boolean"},class:"p5.Image",module:"Image",submodule:"Image"},{file:"src/image/p5.Image.js",line:684,description:"Saves the image to a file and force the browser to download it.\nAccepts two strings for filename and file extension\nSupports png (default) and jpg.
\n",itemtype:"method",name:"save",params:[{name:"filename",description:"give your file a name
\n",type:"String"},{name:"extension",description:"'png' or 'jpg'
\n",type:"String"}],example:['\n\nvar photo;\n\nfunction preload() {\n photo = loadImage("assets/rockies.jpg");\n}\n\nfunction draw() {\n image(photo, 0, 0);\n}\n\nfunction keyTyped() {\n if (key == \'s\') {\n photo.save("photo", "png");\n }\n}\n
Uint8ClampedArray\ncontaining the values for all the pixels in the display window.\nThese values are numbers. This array is the size (include an appropriate\nfactor for pixelDensity) of the display window x4,\nrepresenting the R, G, B, A values in order for each pixel, moving from\nleft to right across each row, then down each column. Retina and other\nhigh density displays will have more pixels[] (by a factor of\npixelDensity^2).\nFor example, if the image is 100x100 pixels, there will be 40,000. On a\nretina display, there will be 160,000.\n
\nThe first four values (indices 0-3) in the array will be the R, G, B, A\nvalues of the pixel at (0, 0). The second four values (indices 4-7) will\ncontain the R, G, B, A values of the pixel at (1, 0). More generally, to\nset values for a pixel at (x, y):
var d = pixelDensity();\nfor (var i = 0; i < d; i++) {\n for (var j = 0; j < d; j++) {\n // loop over\n idx = 4 * ((y * d + j) * width * d + (x * d + i));\n pixels[idx] = r;\n pixels[idx+1] = g;\n pixels[idx+2] = b;\n pixels[idx+3] = a;\n }\n}\n
\nWhile the above method is complex, it is flexible enough to work with\nany pixelDensity. Note that set() will automatically take care of\nsetting all the appropriate values in pixels[] for a given (x, y) at\nany pixelDensity, but the performance may not be as fast when lots of\nmodifications are made to the pixel array.\n
\nBefore accessing this array, the data must loaded with the loadPixels()\nfunction. After the array data has been modified, the updatePixels()\nfunction must be run to update the changes.\n
\nNote that this is not a standard javascript array. This means that\nstandard javascript functions such as slice()
or\narrayCopy()
do not\nwork.
\nvar pink = color(255, 102, 204);\nloadPixels();\nvar d = pixelDensity();\nvar halfImage = 4 * (width * d) * (height/2 * d);\nfor (var i = 0; i < halfImage; i+=4) {\n pixels[i] = red(pink);\n pixels[i+1] = green(pink);\n pixels[i+2] = blue(pink);\n pixels[i+3] = alpha(pink);\n}\nupdatePixels();\n
\nCopies a region of pixels from one image to another, using a specified\nblend mode to do the operation.
\nAvailable blend modes are: BLEND | DARKEST | LIGHTEST | DIFFERENCE |\nMULTIPLY| EXCLUSION | SCREEN | REPLACE | OVERLAY | HARD_LIGHT |\nSOFT_LIGHT | DODGE | BURN | ADD | NORMAL
source image
\n",type:"p5.Image|undefined"},{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
\n",type:"Integer"}],example:['\n\nvar img0;\nvar img1;\n\nfunction preload() {\n img0 = loadImage("assets/rockies.jpg");\n img1 = loadImage("assets/bricks_third.jpg");\n}\n\nfunction setup() {\n background(img0);\n image(img1, 0, 0);\n blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);\n}\n
\nvar img0;\nvar img1;\n\nfunction preload() {\n img0 = loadImage("assets/rockies.jpg");\n img1 = loadImage("assets/bricks_third.jpg");\n}\n\nfunction setup() {\n background(img0);\n image(img1, 0, 0);\n blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);\n}\n
\nvar img0;\nvar img1;\n\nfunction preload() {\n img0 = loadImage("assets/rockies.jpg");\n img1 = loadImage("assets/bricks_third.jpg");\n}\n\nfunction setup() {\n background(img0);\n image(img1, 0, 0);\n blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);\n}\n
Copies a region of the canvas to another region of the canvas\nand copies a region of pixels from an image used as the srcImg parameter\ninto the canvas srcImage is specified this is used as the source. If\nthe source and destination regions aren't the same size, it will\nautomatically resize source pixels to fit the specified\ntarget region.
\n",itemtype:"method",name:"copy",params:[{name:"srcImage",description:"source image
\n",type:"p5.Image|undefined"},{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"}],example:['\n\nvar img;\n\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n background(img);\n copy(img, 7, 22, 10, 10, 35, 25, 50, 50);\n stroke(255);\n noFill();\n // Rectangle shows area being copied\n rect(7, 22, 10, 10);\n}\n
Applies a filter to the canvas.\n
The presets options are:\n
THRESHOLD\nConverts the image to black and white pixels depending if they are above or\nbelow the threshold defined by the level parameter. The parameter must be\nbetween 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.\n
GRAY\nConverts any colors in the image to grayscale equivalents. No parameter\nis used.\n
OPAQUE\nSets the alpha channel to entirely opaque. No parameter is used.\n
INVERT\nSets each pixel to its inverse value. No parameter is used.\n
POSTERIZE\nLimits each channel of the image to the number of colors specified as the\nparameter. The parameter can be set to values between 2 and 255, but\nresults are most noticeable in the lower ranges.\n
BLUR\nExecutes a Guassian blur with the level parameter specifying the extent\nof the blurring. If no parameter is used, the blur is equivalent to\nGuassian blur of radius 1. Larger values increase the blur.\n
ERODE\nReduces the light areas. No parameter is used.\n
DILATE\nIncreases the light areas. No parameter is used.
\n",itemtype:"method",name:"filter",params:[{name:"filterType",description:"either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, BLUR, ERODE or DILATE
\n",type:"Constant"},{name:"filterParam",description:"an optional parameter unique\n to each filter, see above
\n",type:"Number"}],example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(THRESHOLD);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(GRAY);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(OPAQUE);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(INVERT);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(POSTERIZE,3);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(DILATE);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(BLUR,3);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/bricks.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n filter(ERODE);\n}\n
\nReturns an array of [R,G,B,A] values for any pixel or grabs a section of\nan image. If no parameters are specified, the entire image is returned.\nUse the x and y parameters to get the value of one pixel. Get a section of\nthe display window by specifying additional w and h parameters. When\ngetting an image, the x and y parameters define the coordinates for the\nupper-left corner of the image, regardless of the current imageMode().\n
\nIf the pixel requested is outside of the image window, [0,0,0,255] is\nreturned. To get the numbers scaled according to the current color ranges\nand taking into account colorMode, use getColor instead of get.\n
\nGetting the color of a single pixel with get(x, y) is easy, but not as fast\nas grabbing the data directly from pixels[]. The equivalent statement to\nget(x, y) using pixels[] with pixel density d is\n\nvar off = (y width + x) d * 4;\n[pixels[off],\npixels[off+1],\npixels[off+2],\npixels[off+3]]
\n
\nSee the reference for pixels[] for more information.
x-coordinate of the pixel
\n",type:"Number",optional:!0},{name:"y",description:"y-coordinate of the pixel
\n",type:"Number",optional:!0},{name:"w",description:"width
\n",type:"Number",optional:!0},{name:"h",description:"height
\n",type:"Number",optional:!0}],return:{description:"values of pixel at x,y in array format\n [R, G, B, A] or p5.Image",type:"Number[]|p5.Image"},example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n var c = get();\n image(c, width/2, 0);\n}\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\nfunction setup() {\n image(img, 0, 0);\n var c = get(50, 90);\n fill(c);\n noStroke();\n rect(25, 25, 50, 50);\n}\n
\nLoads the pixel data for the display window into the pixels[] array. This\nfunction must always be called before reading from or writing to pixels[].\nNote that only changes made with set() or direct manipulation of pixels[]\nwill occur.
\n",itemtype:"method",name:"loadPixels",example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n image(img, 0, 0);\n var d = pixelDensity();\n var halfImage = 4 * (img.width * d) *\n (img.height/2 * d);\n loadPixels();\n for (var i = 0; i < halfImage; i++) {\n pixels[i+halfImage] = pixels[i];\n }\n updatePixels();\n}\n
\nChanges the color of any pixel, or writes an image directly to the\ndisplay window.
\nThe x and y parameters specify the pixel to change and the c parameter\nspecifies the color value. This can be a p5.Color object, or [R, G, B, A]\npixel array. It can also be a single grayscale value.\nWhen setting an image, the x and y parameters define the coordinates for\nthe upper-left corner of the image, regardless of the current imageMode().\n
\n\nAfter using set(), you must call updatePixels() for your changes to appear.\nThis should be called once all pixels have been set, and must be called before\ncalling .get() or drawing the image.\n
\nSetting the color of a single pixel with set(x, y) is easy, but not as\nfast as putting the data directly into pixels[]. Setting the pixels[]\nvalues directly may be complicated when working with a retina display,\nbut will perform better when lots of pixels need to be set directly on\nevery loop.
\nSee the reference for pixels[] for more information.
",itemtype:"method",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|Array|Object"}],example:['\n\nvar black = color(0);\nset(30, 20, black);\nset(85, 20, black);\nset(85, 75, black);\nset(30, 75, black);\nupdatePixels();\n
\n\nfor (var i = 30; i < width-15; i++) {\n for (var j = 20; j < height-25; j++) {\n var c = color(204-j, 153-i, 0);\n set(i, j, c);\n }\n}\nupdatePixels();\n
\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n set(0, 0, img);\n updatePixels();\n line(0, 0, width, height);\n line(0, height, width, 0);\n}\n
\nUpdates the display window with the data in the pixels[] array.\nUse in conjunction with loadPixels(). If you're only reading pixels from\nthe array, there's no need to call updatePixels() — updating is only\nnecessary to apply changes. updatePixels() should be called anytime the\npixels array is manipulated or set() is called, and only changes made with\nset() or direct changes to pixels[] will occur.
\n",itemtype:"method",name:"updatePixels",params:[{name:"x",description:"x-coordinate of the upper-left corner of region\n to update
\n",type:"Number",optional:!0},{name:"y",description:"y-coordinate of the upper-left corner of region\n to update
\n",type:"Number",optional:!0},{name:"w",description:"width of region to update
\n",type:"Number",optional:!0},{name:"h",description:"height of region to update
\n",type:"Number",optional:!0}],example:['\n\nvar img;\nfunction preload() {\n img = loadImage("assets/rockies.jpg");\n}\n\nfunction setup() {\n image(img, 0, 0);\n var halfImage = 4 * (img.width * pixelDensity()) *\n (img.height * pixelDensity()/2);\n loadPixels();\n for (var i = 0; i < halfImage; i++) {\n pixels[i+halfImage] = pixels[i];\n }\n updatePixels();\n}\n
\nLoads a JSON file from a file or a URL, and returns an Object.\nNote that even if the JSON file contains an Array, an Object will be\nreturned with index numbers as keys.
\nThis method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed. JSONP is supported via a polyfill and you\ncan pass in as the second argument an object with definitions of the json\ncallback following the syntax specified here.
\n',itemtype:"method",name:"loadJSON",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:!0},{name:"datatype",description:""json" or "jsonp"
\n",type:"String",optional:!0},{name:"callback",description:"function to be executed after\n loadJSON() completes, data is passed\n in as first argument
\n",type:"Function",optional:!0},{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:!0}],return:{description:"JSON data",type:"Object|Array"},example:["\n\nCalling loadJSON() inside preload() guarantees to complete the\noperation before setup() and draw() are called.
\n\n\n// Examples use USGS Earthquake API:\n// https://earthquake.usgs.gov/fdsnws/event/1/#methods\nvar earthquakes;\nfunction preload() {\n // Get the most recent earthquake in the database\n var url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +\n 'format=geojson&limit=1&orderby=time';\n earthquakes = loadJSON(url);\n}\n\nfunction setup() {\n noLoop();\n}\n\nfunction draw() {\n background(200);\n // Get the magnitude and name of the earthquake out of the loaded JSON\n var earthquakeMag = earthquakes.features[0].properties.mag;\n var earthquakeName = earthquakes.features[0].properties.place;\n ellipse(width/2, height/2, earthquakeMag * 10, earthquakeMag * 10);\n textAlign(CENTER);\n text(earthquakeName, 0, height - 30, width, 30);\n}\n
Outside of preload(), you may supply a callback function to handle the\nobject:
\n\nfunction setup() {\n noLoop();\n var url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +\n 'format=geojson&limit=1&orderby=time';\n loadJSON(url, drawEarthquake);\n}\n\nfunction draw() {\n background(200);\n}\n\nfunction drawEarthquake(earthquakes) {\n // Get the magnitude and name of the earthquake out of the loaded JSON\n var earthquakeMag = earthquakes.features[0].properties.mag;\n var earthquakeName = earthquakes.features[0].properties.place;\n ellipse(width/2, height/2, earthquakeMag * 10, earthquakeMag * 10);\n textAlign(CENTER);\n text(earthquakeName, 0, height - 30, width, 30);\n}\n
Reads the contents of a file and creates a String array of its individual\nlines. If the name of the file is used as the parameter, as in the above\nexample, the file must be located in the sketch directory/folder.\n
\nAlternatively, the file maybe be loaded from anywhere on the local\ncomputer using an absolute path (something that starts with / on Unix and\nLinux, or a drive letter on Windows), or the filename parameter can be a\nURL for a file found on a network.\n
\nThis method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed.
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:!0},{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:!0}],return:{description:"Array of Strings",type:"String[]"},example:["\n\nCalling loadStrings() inside preload() guarantees to complete the\noperation before setup() and draw() are called.
\n\n\nvar result;\nfunction preload() {\n result = loadStrings('assets/test.txt');\n}\n\nfunction setup() {\n background(200);\n var ind = floor(random(result.length));\n text(result[ind], 10, 10, 80, 80);\n}\n
Outside of preload(), you may supply a callback function to handle the\nobject:
\n\n\nfunction setup() {\n loadStrings('assets/test.txt', pickString);\n}\n\nfunction pickString(result) {\n background(200);\n var ind = floor(random(result.length));\n text(result[ind], 10, 10, 80, 80);\n}\n
Reads the contents of a file or URL and creates a p5.Table object with\nits values. If a file is specified, it must be located in the sketch's\n"data" folder. The filename parameter can also be a URL to a file found\nonline. By default, the file is assumed to be comma-separated (in CSV\nformat). Table only looks for a header row if the 'header' option is\nincluded.
\n\nPossible options include:\n
When passing in multiple options, pass them in as separate parameters,\nseperated by commas. For example:\n
\n\n loadTable("my_csv_file.csv", "csv", "header")\n
\n
All files loaded and saved use UTF-8 encoding.
\n\nThis method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed. Calling loadTable() inside preload()\nguarantees to complete the operation before setup() and draw() are called.\n
Outside of preload(), you may supply a callback function to handle the\nobject:
\n",itemtype:"method",name:"loadTable",params:[{name:"filename",description:"name of the file or URL to load
\n",type:"String"},{name:"options",description:""header" "csv" "tsv"
\n",type:"String",optional:!0},{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:!0},{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:!0}],return:{description:"Table object containing data",type:"Object"},example:['\n\n// Given the following CSV file called "mammals.csv"\n// located in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n //the file can be remote\n //table = loadTable("http://p5js.org/reference/assets/mammals.csv",\n // "csv", "header");\n}\n\nfunction setup() {\n //count the columns\n print(table.getRowCount() + " total rows in table");\n print(table.getColumnCount() + " total columns in table");\n\n print(table.getColumn("name"));\n //["Goat", "Leopard", "Zebra"]\n\n //cycle through the table\n for (var r = 0; r < table.getRowCount(); r++)\n for (var c = 0; c < table.getColumnCount(); c++) {\n print(table.getString(r, c));\n }\n}\n
\nReads the contents of a file and creates an XML object with its values.\nIf the name of the file is used as the parameter, as in the above example,\nthe file must be located in the sketch directory/folder.
\nAlternatively, the file maybe be loaded from anywhere on the local\ncomputer using an absolute path (something that starts with / on Unix and\nLinux, or a drive letter on Windows), or the filename parameter can be a\nURL for a file found on a network.
\nThis method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed. Calling loadXML() inside preload()\nguarantees to complete the operation before setup() and draw() are called.
\nOutside of preload(), you may supply a callback function to handle the\nobject.
\n",itemtype:"method",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:!0},{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:!0}],return:{description:"XML object containing data",type:"Object"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var children = xml.getChildren("animal");\n\n for (var i = 0; i < children.length; i++) {\n var id = children[i].getNum("id");\n var coloring = children[i].getString("species");\n var name = children[i].getContent();\n print(id + ", " + coloring + ", " + name);\n }\n}\n\n// Sketch prints:\n// 0, Capra hircus, Goat\n// 1, Panthera pardus, Leopard\n// 2, Equus zebra, Zebra\n
Method for executing an HTTP GET request. If data type is not specified,\np5 will try to guess based on the URL, defaulting to text. This is equivalent to\ncalling httpDo(path, 'GET')
.
name of the file or url to load
\n",type:"String"},{name:"datatype",description:""json", "jsonp", "xml", or "text"
\n",type:"String",optional:!0},{name:"data",description:"param data passed sent with request
\n",type:"Object",optional:!0},{name:"callback",description:"function to be executed after\n httpGet() completes, data is passed in\n as first argument
\n",type:"Function",optional:!0},{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:!0}],example:["\n\n // Examples use USGS Earthquake API:\n // https://earthquake.usgs.gov/fdsnws/event/1/#methods\n var earthquakes;\n function preload() {\n // Get the most recent earthquake in the database\n var url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +\n 'format=geojson&limit=1&orderby=time';\n httpGet(url, \"jsonp\", false, function(response) {\n // when the HTTP request completes, populate the variable that holds the\n // earthquake data used in the visualization.\n earthquakes = response;\n });\n }\n\n function draw() {\n if (!earthquakes) {\n // Wait until the earthquake data has loaded before drawing.\n return\n }\n background(200);\n // Get the magnitude and name of the earthquake out of the loaded JSON\n var earthquakeMag = earthquakes.features[0].properties.mag;\n var earthquakeName = earthquakes.features[0].properties.place;\n ellipse(width/2, height/2, earthquakeMag * 10, earthquakeMag * 10);\n textAlign(CENTER);\n text(earthquakeName, 0, height - 30, width, 30);\n noLoop();\n }\n
Method for executing an HTTP POST request. If data type is not specified,\np5 will try to guess based on the URL, defaulting to text. This is equivalent to\ncalling httpDo(path, 'POST')
.
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:!0},{name:"data",description:"param data passed sent with request
\n",type:"Object",optional:!0},{name:"callback",description:"function to be executed after\n httpPost() completes, data is passed in\n as first argument
\n",type:"Function",optional:!0},{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:!0}],example:["\n\n// Examples use jsonplaceholder.typicode.com for a Mock Data API\n\nvar url = 'https://jsonplaceholder.typicode.com/posts';\nvar postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is way cool.' };\n\nfunction setup() {\n createCanvas(800, 800);\n}\n\nfunction mousePressed() {\n // Pick new random color values\n var r = random(255);\n var g = random(255);\n var b = random(255);\n\n httpPost(url, 'json',\n postData,\n function (result) {\n strokeWeight(2);\n stroke(r, g, b);\n fill(r, g, b, 127);\n ellipse(mouseX, mouseY, 200, 200);\n text(result.body, mouseX, mouseY);\n });\n}\n
\n\n\n var url = 'https://invalidURL'; // A bad URL that will cause errors\n var postData = { title: 'p5 Clicked!', body: 'p5.js is way cool.' };\n\n function setup() {\n createCanvas(800, 800);\n }\n\n function mousePressed() {\n // Pick new random color values\n var r = random(255);\n var g = random(255);\n var b = random(255);\n\n httpPost(url, 'json',\n postData,\n function (result) {\n // ... won't be called\n },\n function (error) {\n strokeWeight(2);\n stroke(r, g, b);\n fill(r, g, b, 127);\n text(error.toString(), mouseX, mouseY);\n });\n }\n\n
\nMethod for executing an HTTP request. If data type is not specified,\np5 will try to guess based on the URL, defaulting to text.
\nFor more advanced use, you may also pass in the path as the first argument\nand a object as the second argument, the signature follows the one specified\nin the Fetch API specification.
\n// Examples use USGS Earthquake API:\n// https://earthquake.usgs.gov/fdsnws/event/1/#methods\n\n// displays an animation of all USGS earthquakes\nvar earthquakes;\nvar eqFeatureIndex = 0;\n\nfunction preload() {\n var url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';\n httpDo(url,\n {\n method: 'GET',\n // Other Request options, like special headers for apis\n headers: { authorization: 'Bearer secretKey' }\n },\n function(res) {\n earthquakes = res;\n });\n}\n\nfunction draw() {\n // wait until the data is loaded\n if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {\n return;\n }\n clear();\n\n var feature = earthquakes.features[eqFeatureIndex];\n var mag = feature.properties.mag;\n var rad = mag / 11 * ((width + height) / 2);\n fill(255, 0, 0, 100);\n ellipse(\n width / 2 + random(-2, 2),\n height / 2 + random(-2, 2),\n rad, rad\n );\n\n if (eqFeatureIndex >= earthquakes.features.length) {\n eqFeatureIndex = 0;\n } else {\n eqFeatureIndex += 1;\n }\n}\n
\nname 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:!0},{name:"datatype",description:""json", "jsonp", "xml", or "text"
\n",type:"String",optional:!0},{name:"data",description:"param data passed sent with request
\n",type:"Object",optional:!0},{name:"callback",description:"function to be executed after\n httpGet() completes, data is passed in\n as first argument
\n",type:"Function",optional:!0},{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:!0}]},{line:865,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:!0},{name:"errorCallback",description:"",type:"Function",optional:!0}]}]},{file:"src/io/files.js",line:1077,description:"Save an image, text, json, csv, wav, or html. Prompts download to\nthe client's computer. Note that it is not recommended to call save()\nwithin draw if it's looping, as the save() function will open a new save\ndialog every frame.
\nThe default behavior is to save the canvas as an image. You can\noptionally specify a filename.\nFor example:
\n\nsave();\nsave('myCanvas.jpg'); // save a specific canvas with a filename\n
\n\nAlternately, the first parameter can be a pointer to a canvas\np5.Element, an Array of Strings,\nan Array of JSON, a JSON object, a p5.Table, a p5.Image, or a\np5.SoundFile (requires p5.sound). The second parameter is a filename\n(including extension). The third parameter is for options specific\nto this type of object. This method will save a file that fits the\ngiven paramaters. For example:
\n\n\n\nsave('myCanvas.jpg'); // Saves canvas as an image\n\nvar cnv = createCanvas(100, 100);\nsave(cnv, 'myCanvas.jpg'); // Saves canvas as an image\n\nvar gb = createGraphics(100, 100);\nsave(gb, 'myGraphics.jpg'); // Saves p5.Renderer object as an image\n\nsave(myTable, 'myTable.html'); // Saves table as html file\nsave(myTable, 'myTable.csv',); // Comma Separated Values\nsave(myTable, 'myTable.tsv'); // Tab Separated Values\n\nsave(myJSON, 'my.json'); // Saves pretty JSON\nsave(myJSON, 'my.json', true); // Optimizes JSON filesize\n\nsave(img, 'my.png'); // Saves pImage as a png image\n\nsave(arrayOfStrings, 'my.txt'); // Saves strings to a text file with line\n // breaks after each item in the array\n
",itemtype:"method",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:!0},{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:!0},{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.
Writes the contents of an Array or a JSON object to a .json file.\nThe file saving process and location of the saved file will\nvary between web browsers.
\n",itemtype:"method",name:"saveJSON",params:[{name:"json",description:"",type:"Array|Object"},{name:"filename",description:"",type:"String"},{name:"optimize",description:"If true, removes line breaks\n and spaces from the output\n file to optimize filesize\n (but not readability).
\n",type:"Boolean",optional:!0}],example:['\n\nvar json;\n\nfunction setup() {\n\n json = {}; // new JSON Object\n\n json.id = 0;\n json.species = \'Panthera leo\';\n json.name = \'Lion\';\n\n// To save, un-comment the line below, then click \'run\'\n// saveJSON(json, \'lion.json\');\n}\n\n// Saves the following to a file called "lion.json":\n// {\n// "id": 0,\n// "species": "Panthera leo",\n// "name": "Lion"\n// }\n
Writes an array of Strings to a text file, one line per String.\nThe file saving process and location of the saved file will\nvary between web browsers.
\n",itemtype:"method",name:"saveStrings",params:[{name:"list",description:"string array to be written
\n",type:"Array"},{name:"filename",description:"filename for output
\n",type:"String"}],example:["\n\nvar words = 'apple bear cat dog';\n\n// .split() outputs an Array\nvar list = split(words, ' ');\n\n// To save the file, un-comment next line and click 'run'\n// saveStrings(list, 'nouns.txt');\n\n// Saves the following to a file called 'nouns.txt':\n//\n// apple\n// bear\n// cat\n// dog\n
Writes the contents of a Table object to a file. Defaults to a\ntext file with comma-separated-values ('csv') but can also\nuse tab separation ('tsv'), or generate an HTML table ('html').\nThe file saving process and location of the saved file will\nvary between web browsers.
\n",itemtype:"method",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:!0}],example:["\n\nvar table;\n\nfunction setup() {\n table = new p5.Table();\n\n table.addColumn('id');\n table.addColumn('species');\n table.addColumn('name');\n\n var newRow = table.addRow();\n newRow.setNum('id', table.getRowCount() - 1);\n newRow.setString('species', 'Panthera leo');\n newRow.setString('name', 'Lion');\n\n // To save, un-comment next line then click 'run'\n // saveTable(table, 'new.csv');\n }\n\n // Saves the following to a file called 'new.csv':\n // id,species,name\n // 0,Panthera leo,Lion\n
Generate a blob of file data as a url to prepare for download.\nAccepts an array of data, a filename, and an extension (optional).\nThis is a private function because it does not do any formatting,\nbut it is used by saveStrings, saveJSON, saveTable etc.
\n",params:[{name:"dataToDownload",description:"",type:"Array"},{name:"filename",description:"",type:"String"},{name:"extension",description:"",type:"[String]"}],access:"private",tagname:"",class:"p5",module:"IO",submodule:"Output"},{file:"src/io/files.js",line:1456,description:"Forces download. Accepts a url to filedata/blob, a filename,\nand an extension (optional).\nThis is a private function because it does not do any formatting,\nbut it is used by saveStrings, saveJSON, saveTable etc.
\n",params:[{name:"href",description:"i.e. an href generated by createObjectURL
\n",type:"String"},{name:"filename",description:"",type:"[String]"},{name:"extension",description:"",type:"[String]"}],class:"p5",module:"IO",submodule:"Output"},{file:"src/io/files.js",line:1496,description:"Returns a file extension, or another string\nif the provided parameter has no extension.
\n",params:[{name:"filename",description:"",type:"String"}],return:{description:"[fileName, fileExtension]",type:"String[]"},access:"private",tagname:"",class:"p5",module:"IO",submodule:"Output"},{file:"src/io/files.js",line:1528,description:"Returns true if the browser is Safari, false if not.\nSafari makes trouble for downloading files.
\n",return:{description:"[description]",type:"Boolean"},access:"private",tagname:"",class:"p5",module:"IO",submodule:"Output"},{file:"src/io/files.js",line:1540,description:"Helper function, a callback for download that deletes\nan invisible anchor element from the DOM once the file\nhas been automatically downloaded.
\n",access:"private",tagname:"",class:"p5",module:"IO",submodule:"Output"},{file:"src/io/p5.Table.js",line:12,description:'Table Options
\nGeneric class for handling tabular data, typically from a\nCSV, TSV, or other sort of spreadsheet file.
\nCSV files are\n\ncomma separated values, often with the data in quotes. TSV\nfiles use tabs as separators, and usually don't bother with the\nquotes.
\nFile names should end with .csv if they're comma separated.
\nA rough "spec" for CSV can be found\nhere.
\nTo load files, use the loadTable method.
\nTo save tables to your computer, use the save method\n or the saveTable method.
\n\nPossible options include:
\nUse addRow() to add a new row of data to a p5.Table object. By default,\nan empty row is created. Typically, you would store a reference to\nthe new row in a TableRow object (see newRow in the example above),\nand then set individual values using set().
\nIf a p5.TableRow object is included as a parameter, then that row is\nduplicated and added to the table.
\n",itemtype:"method",name:"addRow",params:[{name:"row",description:"row to be added to the table
\n",type:"p5.TableRow",optional:!0}],example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n //add a row\n var newRow = table.addRow();\n newRow.setString("id", table.getRowCount() - 1);\n newRow.setString("species", "Canis Lupus");\n newRow.setString("name", "Wolf");\n\n //print the results\n for (var r = 0; r < table.getRowCount(); r++)\n for (var c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n }\n
\n Removes a row from the table object.
\n",itemtype:"method",name:"removeRow",params:[{name:"id",description:"ID number of the row to remove
\n",type:"Number"}],example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n //remove the first row\n var r = table.removeRow(0);\n\n //print the results\n for (var r = 0; r < table.getRowCount(); r++)\n for (var c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n}\n
\nReturns a reference to the specified p5.TableRow. The reference\ncan then be used to get and set values of the selected row.
\n",itemtype:"method",name:"getRow",params:[{name:"rowID",description:"ID number of the row to get
\n",type:"Number"}],return:{description:"p5.TableRow object",type:"p5.TableRow"}, example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n var row = table.getRow(1);\n //print it column by column\n //note: a row is an object, not an array\n for (var c = 0; c < table.getColumnCount(); c++)\n print(row.getString(c));\n}\n
\nGets all rows from the table. Returns an array of p5.TableRows.
\n",itemtype:"method",name:"getRows",return:{description:"Array of p5.TableRows",type:"p5.TableRow[]"},example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n var rows = table.getRows();\n\n //warning: rows is an array of objects\n for (var r = 0; r < rows.length; r++)\n rows[r].set("name", "Unicorn");\n\n //print the results\n for (var r = 0; r < table.getRowCount(); r++)\n for (var c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n }\n
\n Finds the first row in the Table that contains the value\nprovided, and returns a reference to that row. Even if\nmultiple rows are possible matches, only the first matching\nrow is returned. The column to search may be specified by\neither its ID or title.
\n",itemtype:"method",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:"Number|String"}],return:{description:"",type:"p5.TableRow"},example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n //find the animal named zebra\n var row = table.findRow("Zebra", "name");\n //find the corresponding species\n print(row.getString("species"));\n }\n
\n Finds the rows in the Table that contain the value\nprovided, and returns references to those rows. Returns an\nArray, so for must be used to iterate through all the rows,\nas shown in the example above. The column to search may be\nspecified by either its ID or title.
\n",itemtype:"method",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:"Number|String"}],return:{description:"An Array of TableRow objects",type:"p5.TableRow[]"},example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n //add another goat\n var newRow = table.addRow();\n newRow.setString("id", table.getRowCount() - 1);\n newRow.setString("species", "Scape Goat");\n newRow.setString("name", "Goat");\n\n //find the rows containing animals named Goat\n var rows = table.findRows("Goat", "name");\n print(rows.length + " Goats found");\n }\n
\n Finds the first row in the Table that matches the regular\nexpression provided, and returns a reference to that row.\nEven if multiple rows are possible matches, only the first\nmatching row is returned. The column to search may be\nspecified by either its ID or title.
\n",itemtype:"method",name:"matchRow",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|Number"}],return:{description:"TableRow object",type:"p5.TableRow"},class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:431,description:"Finds the rows in the Table that match the regular expression provided,\nand returns references to those rows. Returns an array, so for must be\nused to iterate through all the rows, as shown in the example. The\ncolumn to search may be specified by either its ID or title.
\n",itemtype:"method",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|Number",optional:!0}],return:{description:"An Array of TableRow objects",type:"p5.TableRow[]"},example:["\nvar table;\n\nfunction setup() {\n\n table = new p5.Table();\n\n table.addColumn('name');\n table.addColumn('type');\n\n var newRow = table.addRow();\n newRow.setString('name', 'Lion');\n newRow.setString('type', 'Mammal');\n\n newRow = table.addRow();\n newRow.setString('name', 'Snake');\n newRow.setString('type', 'Reptile');\n\n newRow = table.addRow();\n newRow.setString('name', 'Mosquito');\n newRow.setString('type', 'Insect');\n\n newRow = table.addRow();\n newRow.setString('name', 'Lizard');\n newRow.setString('type', 'Reptile');\n\n var rows = table.matchRows('R.*', 'type');\n for (var i = 0; i < rows.length; i++) {\n print(rows[i].getString('name') + ': ' + rows[i].getString('type'));\n }\n}\n// Sketch prints:\n// Snake: Reptile\n// Lizard: Reptile"],class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:498,description:"Retrieves all values in the specified column, and returns them\nas an array. The column may be specified by either its ID or title.
\n",itemtype:"method",name:"getColumn",params:[{name:"column",description:"String or Number of the column to return
\n",type:"String|Number"}],return:{description:"Array of column values",type:"Array"},example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n //getColumn returns an array that can be printed directly\n print(table.getColumn("species"));\n //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"]\n }\n
\n Removes all rows from a Table. While all rows are removed,\ncolumns and column titles are maintained.
\n",itemtype:"method",name:"clearRows",example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n table.clearRows();\n print(table.getRowCount() + " total rows in table");\n print(table.getColumnCount() + " total columns in table");\n }\n
\n Use addColumn() to add a new column to a Table object.\nTypically, you will want to specify a title, so the column\nmay be easily referenced later by name. (If no title is\nspecified, the new column's title will be null.)
\n",itemtype:"method",name:"addColumn",params:[{name:"title",description:"title of the given column
\n",type:"String",optional:!0}],example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n table.addColumn("carnivore");\n table.set(0, "carnivore", "no");\n table.set(1, "carnivore", "yes");\n table.set(2, "carnivore", "no");\n\n //print the results\n for (var r = 0; r < table.getRowCount(); r++)\n for (var c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n }\n
\n Returns the total number of columns in a Table.
\n",return:{description:"Number of columns in this table",type:"Number"},class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:653,description:"Returns the total number of rows in a Table.
\n",itemtype:"method",name:"getRowCount",return:{description:"Number of rows in this table",type:"Number"},class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:664,description:"Removes any of the specified characters (or "tokens").
\n\nIf no column is specified, then the values in all columns and\nrows are processed. A specific column may be referenced by\neither its ID or title.
",itemtype:"method",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|Number",optional:!0}],class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:715,description:"Trims leading and trailing whitespace, such as spaces and tabs,\nfrom String table values. If no column is specified, then the\nvalues in all columns and rows are trimmed. A specific column\nmay be referenced by either its ID or title.
\n",itemtype:"method",name:"trim",params:[{name:"column",description:"Column ID (number)\n or name (string)
\n",type:"String|Number"}],class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:757,description:"Use removeColumn() to remove an existing column from a Table\nobject. The column to be removed may be identified by either\nits title (a String) or its index value (an int).\nremoveColumn(0) would remove the first column, removeColumn(1)\nwould remove the second column, and so on.
\n",itemtype:"method",name:"removeColumn",params:[{name:"column",description:"columnName (string) or ID (number)
\n",type:"String|Number"}],example:['\n\n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n var table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n }\n\n function setup() {\n table.removeColumn("id");\n print(table.getColumnCount());\n }\n
\n Stores a value in the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified\nby either its ID or title.
\n",itemtype:"method",name:"set",params:[{name:"column",description:"column ID (Number)\n or title (String)
\n",type:"String|Number"},{name:"value",description:"value to assign
\n",type:"String|Number"}],example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n table.set(0, "species", "Canis Lupus");\n table.set(0, "name", "Wolf");\n\n //print the results\n for (var r = 0; r < table.getRowCount(); r++)\n for (var c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n}\n
\nStores a Float value in the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified\nby either its ID or title.
\n",itemtype:"method",name:"setNum",params:[{name:"row",description:"row ID
\n",type:"Number"},{name:"column",description:"column ID (Number)\n or title (String)
\n",type:"String|Number"},{name:"value",description:"value to assign
\n",type:"Number"}],example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n table.setNum(1, "id", 1);\n\n print(table.getColumn(0));\n //["0", 1, "2"]\n}\n
\nStores a String value in the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified\nby either its ID or title.
\n",itemtype:"method",name:"setString",params:[{name:"row",description:"row ID
\n",type:"Number"},{name:"column",description:"column ID (Number)\n or title (String)
\n",type:"String|Number"},{name:"value",description:"value to assign
\n",type:"String"}],class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.Table.js",line:937,description:"Retrieves a value from the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified by\neither its ID or title.
\n",itemtype:"method",name:"get",params:[{name:"row",description:"row ID
\n",type:"Number"},{name:"column",description:"columnName (string) or\n ID (number)
\n",type:"String|Number"}],return:{description:"",type:"String|Number"},example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n print(table.get(0, 1));\n //Capra hircus\n print(table.get(0, "species"));\n //Capra hircus\n}\n
\nRetrieves a Float value from the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified by\neither its ID or title.
\n",itemtype:"method",name:"getNum",params:[{name:"row",description:"row ID
\n",type:"Number"},{name:"column",description:"columnName (string) or\n ID (number)
\n",type:"String|Number"}],return:{description:"",type:"Number"},example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n print(table.getNum(1, 0) + 100);\n //id 1 + 100 = 101\n}\n
\nRetrieves a String value from the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified by\neither its ID or title.
\n",itemtype:"method",name:"getString",params:[{name:"row",description:"row ID
\n",type:"Number"},{name:"column",description:"columnName (string) or\n ID (number)
\n",type:"String|Number"}],return:{description:"",type:"String"},example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n var tableArray = table.getArray();\n\n //output each row as array\n for (var i = 0; i < tableArray.length; i++)\n print(tableArray[i]);\n}\n
\nRetrieves all table data and returns as an object. If a column name is\npassed in, each row object will be stored with that attribute as its\ntitle.
\n",itemtype:"method",name:"getObject",params:[{name:"headerColumn",description:"Name of the column which should be used to\n title each row object (optional)
\n",type:"String"}],return:{description:"",type:"Object"},example:['\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nvar table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable("assets/mammals.csv", "csv", "header");\n}\n\nfunction setup() {\n var tableObject = table.getObject();\n\n print(tableObject);\n //outputs an object\n}\n
\nRetrieves all table data and returns it as a multidimensional array.
\n",itemtype:"method",name:"getArray",return:{description:"",type:"Array"},class:"p5.Table",module:"IO",submodule:"Table"},{file:"src/io/p5.TableRow.js",line:43,description:"Stores a value in the TableRow's specified column.\nThe column may be specified by either its ID or title.
\n",itemtype:"method",name:"set",params:[{name:"column",description:"Column ID (Number)\n or Title (String)
\n",type:"String|Number"},{name:"value",description:"The value to be stored
\n",type:"String|Number"}],class:"p5.TableRow",module:"IO",submodule:"Table"},{file:"src/io/p5.TableRow.js",line:79,description:"Stores a Float value in the TableRow's specified column.\nThe column may be specified by either its ID or title.
\n",itemtype:"method",name:"setNum",params:[{name:"column",description:"Column ID (Number)\n or Title (String)
\n",type:"String|Number"},{name:"value",description:"The value to be stored\n as a Float
\n",type:"Number"}],class:"p5.TableRow",module:"IO",submodule:"Table"},{file:"src/io/p5.TableRow.js",line:95,description:"Stores a String value in the TableRow's specified column.\nThe column may be specified by either its ID or title.
\n",itemtype:"method",name:"setString",params:[{name:"column",description:"Column ID (Number)\n or Title (String)
\n",type:"String|Number"},{name:"value",description:"The value to be stored\n as a String
\n",type:"String"}],class:"p5.TableRow",module:"IO",submodule:"Table"},{file:"src/io/p5.TableRow.js",line:110,description:"Retrieves a value from the TableRow's specified column.\nThe column may be specified by either its ID or title.
\n",itemtype:"method",name:"get",params:[{name:"column",description:"columnName (string) or\n ID (number)
\n",type:"String|Number"}],return:{description:"",type:"String|Number"},class:"p5.TableRow",module:"IO",submodule:"Table"},{file:"src/io/p5.TableRow.js",line:127,description:"Retrieves a Float value from the TableRow's specified\ncolumn. The column may be specified by either its ID or\ntitle.
\n",itemtype:"method",name:"getNum",params:[{name:"column",description:"columnName (string) or\n ID (number)
\n",type:"String|Number"}],return:{description:"Float Floating point number",type:"Number"},class:"p5.TableRow",module:"IO",submodule:"Table"},{file:"src/io/p5.TableRow.js",line:151,description:"Retrieves an String value from the TableRow's specified\ncolumn. The column may be specified by either its ID or\ntitle.
\n",itemtype:"method",name:"getString",params:[{name:"column",description:"columnName (string) or\n ID (number)
\n",type:"String|Number"}],return:{description:"String",type:"String"},class:"p5.TableRow",module:"IO",submodule:"Table"},{file:"src/io/p5.XML.js",line:66,description:"Gets a copy of the element's parent. Returns the parent as another\np5.XML object.
\n",itemtype:"method",name:"getParent",return:{description:"element parent",type:"p5.XML"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var children = xml.getChildren("animal");\n var parent = children[1].getParent();\n print(parent.getName());\n}\n\n// Sketch prints:\n// mammals\n
Gets the element's full name, which is returned as a String.
\n",itemtype:"method",name:"getName",return:{description:"the name of the node",type:"String"},example:['<animal\n\n // The following short XML file called "mammals.xml" is parsed\n // in the code below.\n //\n // \n // <mammals>\n // <animal id="0" species="Capra hircus">Goat</animal>\n // <animal id="1" species="Panthera pardus">Leopard</animal>\n // <animal id="2" species="Equus zebra">Zebra</animal>\n // </mammals>\n\n var xml;\n\n function preload() {\n xml = loadXML("assets/mammals.xml");\n }\n\n function setup() {\n print(xml.getName());\n }\n\n // Sketch prints:\n // mammals\n
Sets the element's name, which is specified as a String.
\n",itemtype:"method",name:"setName",params:[{name:"the",description:"new name of the node
\n",type:"String"}],example:['<animal\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n print(xml.getName());\n xml.setName("fish");\n print(xml.getName());\n}\n\n// Sketch prints:\n// mammals\n// fish\n
Checks whether or not the element has any children, and returns the result\nas a boolean.
\n",itemtype:"method",name:"hasChildren",return:{description:"",type:"Boolean"},example:['<animal\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n print(xml.hasChildren());\n}\n\n// Sketch prints:\n// true\n
Get the names of all of the element's children, and returns the names as an\narray of Strings. This is the same as looping through and calling getName()\non each child element individually.
\n",itemtype:"method",name:"listChildren",return:{description:"names of the children of the element",type:"String[]"},example:['<animal\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n print(xml.listChildren());\n}\n\n// Sketch prints:\n// ["animal", "animal", "animal"]\n
Returns all of the element's children as an array of p5.XML objects. When\nthe name parameter is specified, then it will return all children that match\nthat name.
\n",itemtype:"method",name:"getChildren",params:[{name:"name",description:"element name
\n",type:"String",optional:!0}],return:{description:"children of the element",type:"p5.XML[]"},example:['<animal\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var animals = xml.getChildren("animal");\n\n for (var i = 0; i < animals.length; i++) {\n print(animals[i].getContent());\n }\n}\n\n// Sketch prints:\n// "Goat"\n// "Leopard"\n// "Zebra"\n
Returns the first of the element's children that matches the name parameter\nor the child of the given index.It returns undefined if no matching\nchild is found.
\n",itemtype:"method",name:"getChild",params:[{name:"name",description:"element name or index
\n",type:"String|Number"}],return:{description:"",type:"p5.XML"},example:['<animal\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getContent());\n}\n\n// Sketch prints:\n// "Goat"\n
\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var secondChild = xml.getChild(1);\n print(secondChild.getContent());\n}\n\n// Sketch prints:\n// "Leopard"\n
Appends a new child to the element. The child can be specified with\neither a String, which will be used as the new tag's name, or as a\nreference to an existing p5.XML object.\nA reference to the newly created child is returned as an p5.XML object.
\n",itemtype:"method",name:"addChild",params:[{name:"a",description:"p5.XML Object which will be the child to be added
\n",type:"p5.XML"}],class:"p5.XML",module:"IO",submodule:"XML"},{file:"src/io/p5.XML.js",line:377,description:"Removes the element specified by name or index.
\n",itemtype:"method",name:"removeChild",params:[{name:"name",description:"element name or index
\n",type:"String|Number"}], example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n xml.removeChild("animal");\n var children = xml.getChildren();\n for (var i=0; i
\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n xml.removeChild(1);\n var children = xml.getChildren();\n for (var i=0; i
Counts the specified element's number of attributes, returned as an Number.
\n",itemtype:"method",name:"getAttributeCount",return:{description:"",type:"Number"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getAttributeCount());\n}\n\n// Sketch prints:\n// 2\n
Gets all of the specified element's attributes, and returns them as an\narray of Strings.
\n",itemtype:"method",name:"listAttributes",return:{description:"an array of strings containing the names of attributes",type:"String[]"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.listAttributes());\n}\n\n// Sketch prints:\n// ["id", "species"]\n
Checks whether or not an element has the specified attribute.
\n",itemtype:"method",name:"hasAttribute",params:[{name:"the",description:"attribute to be checked
\n",type:"String"}],return:{description:"true if attribute found else false",type:"Boolean"},example:['\n\n // The following short XML file called "mammals.xml" is parsed\n // in the code below.\n //\n // \n // <mammals>\n // <animal id="0" species="Capra hircus">Goat</animal>\n // <animal id="1" species="Panthera pardus">Leopard</animal>\n // <animal id="2" species="Equus zebra">Zebra</animal>\n // </mammals>\n\n var xml;\n\n function preload() {\n xml = loadXML("assets/mammals.xml");\n }\n\n function setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.hasAttribute("species"));\n print(firstChild.hasAttribute("color"));\n }\n\n // Sketch prints:\n // true\n // false\n
Returns an attribute value of the element as an Number. If the defaultValue\nparameter is specified and the attribute doesn't exist, then defaultValue\nis returned. If no defaultValue is specified and the attribute doesn't\nexist, the value 0 is returned.
\n",itemtype:"method",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:!0}],return:{description:"",type:"Number"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getNum("id"));\n}\n\n// Sketch prints:\n// 0\n
Returns an attribute value of the element as an String. If the defaultValue\nparameter is specified and the attribute doesn't exist, then defaultValue\nis returned. If no defaultValue is specified and the attribute doesn't\nexist, null is returned.
\n",itemtype:"method",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:!0}],return:{description:"",type:"Number"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getString("species"));\n}\n\n// Sketch prints:\n// "Capra hircus"\n
Sets the content of an element's attribute. The first parameter specifies\nthe attribute name, while the second specifies the new content.
\n",itemtype:"method",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"}],example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getString("species"));\n firstChild.setAttribute("species", "Jamides zebra");\n print(firstChild.getString("species"));\n}\n\n// Sketch prints:\n// "Capra hircus"\n// "Jamides zebra"\n
Returns the content of an element. If there is no such content,\ndefaultValue is returned if specified, otherwise null is returned.
\n",itemtype:"method",name:"getContent",params:[{name:"defaultValue",description:"value returned if no content is found
\n",type:"String",optional:!0}],return:{description:"",type:"String"},example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getContent());\n}\n\n// Sketch prints:\n// "Goat"\n
Sets the element's content.
\n",itemtype:"method",name:"setContent",params:[{name:"text",description:"the new content
\n",type:"String"}],example:['\n\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nvar xml;\n\nfunction preload() {\n xml = loadXML("assets/mammals.xml");\n}\n\nfunction setup() {\n var firstChild = xml.getChild("animal");\n print(firstChild.getContent());\n firstChild.setContent("Mountain Goat");\n print(firstChild.getContent());\n}\n\n// Sketch prints:\n// "Goat"\n// "Mountain Goat"\n
This method is called while the parsing of XML (when loadXML() is\ncalled). The difference between this method and the setContent()\nmethod defined later is that this one is used to set the content\nwhen the node in question has more nodes under it and so on and\nnot directly text content. While in the other one is used when\nthe node in question directly has text inside it.
\n",class:"p5.XML",module:"IO",submodule:"XML"},{file:"src/io/p5.XML.js",line:784,description:"This method is called while the parsing of XML (when loadXML() is\ncalled). The XML node is passed and its attributes are stored in the\np5.XML's attribute Object.
\n",class:"p5.XML",module:"IO",submodule:"XML"},{file:"src/math/calculation.js",line:12,description:"Calculates the absolute value (magnitude) of a number. Maps to Math.abs().\nThe absolute value of a number is always positive.
\n",itemtype:"method",name:"abs",params:[{name:"n",description:"number to compute
\n",type:"Number"}],return:{description:"absolute value of given number",type:"Number"},example:['\n\nfunction setup() {\n var x = -3;\n var y = abs(x);\n\n print(x); // -3\n print(y); // 3\n}\n
Calculates the closest int value that is greater than or equal to the\nvalue of the parameter. Maps to Math.ceil(). For example, ceil(9.03)\nreturns the value 10.
\n",itemtype:"method",name:"ceil",params:[{name:"n",description:"number to round up
\n",type:"Number"}],return:{description:"rounded up number",type:"Number"},example:["\n\nfunction draw() {\n background(200);\n // map, mouseX between 0 and 5.\n var ax = map(mouseX, 0, 100, 0, 5);\n var ay = 66;\n\n //Get the ceiling of the mapped number.\n var bx = ceil(map(mouseX, 0, 100, 0,5));\n var by = 33;\n\n // Multiply the mapped numbers by 20 to more easily\n // see the changes.\n stroke(0);\n fill(0);\n line(0, ay, ax * 20, ay);\n line(0, by, bx * 20, by);\n\n // Reformat the float returned by map and draw it.\n noStroke();\n text(nfc(ax, 2,2), ax, ay - 5);\n text(nfc(bx,1,1), bx, by - 5);\n}\n
Constrains a value between a minimum and maximum value.
\n",itemtype:"method",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"}],return:{description:"constrained number",type:"Number"},example:["\n\nfunction draw() {\n background(200);\n\n var leftWall = 25;\n var rightWall = 75;\n\n // xm is just the mouseX, while\n // xc is the mouseX, but constrained\n // between the leftWall and rightWall!\n var xm = mouseX;\n var xc = constrain(mouseX, leftWall, rightWall);\n\n // Draw the walls.\n stroke(150);\n line(leftWall, 0, leftWall, height);\n line(rightWall, 0, rightWall, height);\n\n // Draw xm and xc as circles.\n noStroke();\n fill(150);\n ellipse(xm, 33, 9,9); // Not Constrained\n fill(0);\n ellipse(xc, 66, 9,9); // Constrained\n}\n
Calculates the distance between two points.
\n",itemtype:"method",name:"dist",return:{description:"distance between the two points",type:"Number"},class:"p5",module:"Math",submodule:"Calculation",overloads:[{line:120,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"}],return:{description:"distance between the two points",type:"Number"}},{line:130,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"}],return:{description:"distance between the two points",type:"Number"}}]},{file:"src/math/calculation.js",line:184,description:"Returns Euler's number e (2.71828...) raised to the power of the n\nparameter. Maps to Math.exp().
\n",itemtype:"method",name:"exp",params:[{name:"n",description:"exponent to raise
\n",type:"Number"}],return:{description:"e^n",type:"Number"},example:['\n\nfunction draw() {\n background(200);\n\n // Compute the exp() function with a value between 0 and 2\n var xValue = map(mouseX, 0, width, 0, 2);\n var yValue = exp(xValue);\n\n var y = map(yValue, 0, 8, height, 0);\n\n var legend = "exp (" + nfc(xValue, 3) +")\\n= " + nf(yValue, 1, 4);\n stroke(150);\n line(mouseX, y, mouseX, height);\n fill(0);\n text(legend, 5, 15);\n noStroke();\n ellipse (mouseX,y, 7, 7);\n\n // Draw the exp(x) curve,\n // over the domain of x from 0 to 2\n noFill();\n stroke(0);\n beginShape();\n for (var x = 0; x < width; x++) {\n xValue = map(x, 0, width, 0, 2);\n yValue = exp(xValue);\n y = map(yValue, 0, 8, height, 0);\n vertex(x, y);\n }\n\n endShape();\n line(0, 0, 0, height);\n line(0, height-1, width, height-1);\n}\n
Calculates the closest int value that is less than or equal to the\nvalue of the parameter. Maps to Math.floor().
\n",itemtype:"method",name:"floor",params:[{name:"n",description:"number to round down
\n",type:"Number"}],return:{description:"rounded down number",type:"Number"},example:["\n\nfunction draw() {\n background(200);\n //map, mouseX between 0 and 5.\n var ax = map(mouseX, 0, 100, 0, 5);\n var ay = 66;\n\n //Get the floor of the mapped number.\n var bx = floor(map(mouseX, 0, 100, 0,5));\n var by = 33;\n\n // Multiply the mapped numbers by 20 to more easily\n // see the changes.\n stroke(0);\n fill(0);\n line(0, ay, ax * 20, ay);\n line(0, by, bx * 20, by);\n\n // Reformat the float returned by map and draw it.\n noStroke();\n text(nfc(ax, 2,2), ax, ay - 5);\n text(nfc(bx,1,1), bx, by - 5);\n}\n
Calculates a number between two numbers at a specific increment. The amt\nparameter is the amount to interpolate between the two values where 0.0\nequal to the first point, 0.1 is very near the first point, 0.5 is\nhalf-way in between, etc. The lerp function is convenient for creating\nmotion along a straight path and for drawing dotted lines.
\n",itemtype:"method",name:"lerp",params:[{name:"start",description:"first value
\n",type:"Number"},{name:"stop",description:"second value
\n",type:"Number"},{name:"amt",description:"number between 0.0 and 1.0
\n",type:"Number"}],return:{description:"lerped value",type:"Number"},example:["\n\nfunction setup() {\n background(200);\n var a = 20;\n var b = 80;\n var c = lerp(a,b, .2);\n var d = lerp(a,b, .5);\n var e = lerp(a,b, .8);\n\n var y = 50\n\n strokeWeight(5);\n stroke(0); // Draw the original points in black\n point(a, y);\n point(b, y);\n\n stroke(100); // Draw the lerp points in gray\n point(c, y);\n point(d, y);\n point(e, y);\n}\n
Calculates the natural logarithm (the base-e logarithm) of a number. This\nfunction expects the n parameter to be a value greater than 0.0. Maps to\nMath.log().
\n",itemtype:"method",name:"log",params:[{name:"n",description:"number greater than 0
\n",type:"Number"}],return:{description:"natural logarithm of n",type:"Number"},example:['\n\nfunction draw() {\n background(200);\n var maxX = 2.8;\n var maxY = 1.5;\n\n // Compute the natural log of a value between 0 and maxX\n var xValue = map(mouseX, 0, width, 0, maxX);\n if (xValue > 0) { // Cannot take the log of a negative number.\n var yValue = log(xValue);\n var y = map(yValue, -maxY, maxY, height, 0);\n\n // Display the calculation occurring.\n var legend = "log(" + nf(xValue, 1, 2) + ")\\n= " + nf(yValue, 1, 3);\n stroke(150);\n line(mouseX, y, mouseX, height);\n fill(0);\n text (legend, 5, 15);\n noStroke();\n ellipse (mouseX, y, 7, 7);\n }\n\n // Draw the log(x) curve,\n // over the domain of x from 0 to maxX\n noFill();\n stroke(0);\n beginShape();\n for(var x=0; x < width; x++) {\n xValue = map(x, 0, width, 0, maxX);\n yValue = log(xValue);\n y = map(yValue, -maxY, maxY, height, 0);\n vertex(x, y);\n }\n endShape();\n line(0,0,0,height);\n line(0,height/2,width, height/2);\n}\n
Calculates the magnitude (or length) of a vector. A vector is a direction\nin space commonly used in computer graphics and linear algebra. Because it\nhas no "start" position, the magnitude of a vector can be thought of as\nthe distance from the coordinate 0,0 to its x,y value. Therefore, mag() is\na shortcut for writing dist(0, 0, x, y).
\n",itemtype:"method",name:"mag",params:[{name:"a",description:"first value
\n",type:"Number"},{name:"b",description:"second value
\n",type:"Number"}],return:{description:"magnitude of vector from (0,0) to (a,b)",type:"Number"},example:['\n\nfunction setup() {\n var x1 = 20;\n var x2 = 80;\n var y1 = 30;\n var y2 = 70;\n\n line(0, 0, x1, y1);\n print(mag(x1, y1)); // Prints "36.05551275463989"\n line(0, 0, x2, y1);\n print(mag(x2, y1)); // Prints "85.44003745317531"\n line(0, 0, x1, y2);\n print(mag(x1, y2)); // Prints "72.80109889280519"\n line(0, 0, x2, y2);\n print(mag(x2, y2)); // Prints "106.3014581273465"\n}\n
Re-maps a number from one range to another.\n
\nIn the first example above, the number 25 is converted from a value in the\nrange of 0 to 100 into a value that ranges from the left edge of the\nwindow (0) to the right edge (width).
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:!0}],return:{description:"remapped number",type:"Number"},example:["\n\n var value = 25;\n var m = map(value, 0, 100, 0, width);\n ellipse(m, 50, 10, 10);\n
\n function setup() {\n noStroke();\n }\n\n function draw() {\n background(204);\n var x1 = map(mouseX, 0, width, 25, 75);\n ellipse(x1, 25, 25, 25);\n //This ellipse is constrained to the 0-100 range\n //after setting withinBounds to true\n var x2 = map(mouseX, 0, width, 0, 100, true);\n ellipse(x2, 75, 25, 25);\n }\n
Determines the largest value in a sequence of numbers, and then returns\nthat value. max() accepts any number of Number parameters, or an Array\nof any length.
\n",itemtype:"method",name:"max",params:[{name:"n0",description:"Numbers to compare
\n",type:"Number|Array"}],return:{description:"maximum Number",type:"Number"},example:['\n\nfunction setup() {\n // Change the elements in the array and run the sketch\n // to show how max() works!\n numArray = new Array(2,1,5,4,8,9);\n fill(0);\n noStroke();\n text("Array Elements", 0, 10);\n // Draw all numbers in the array\n var spacing = 15;\n var elemsY = 25;\n for(var i = 0; i < numArray.length; i++) {\n text(numArray[i], i * spacing, elemsY);\n }\n maxX = 33;\n maxY = 80;\n // Draw the Maximum value in the array.\n textSize(32);\n text(max(numArray), maxX, maxY);\n}\n
Determines the smallest value in a sequence of numbers, and then returns\nthat value. min() accepts any number of Number parameters, or an Array\nof any length.
\n",itemtype:"method",name:"min",params:[{name:"n0",description:"Numbers to compare
\n",type:"Number|Array"}],return:{description:"minimum Number",type:"Number"},example:['\n\nfunction setup() {\n // Change the elements in the array and run the sketch\n // to show how min() works!\n numArray = new Array(2,1,5,4,8,9);\n fill(0);\n noStroke();\n text("Array Elements", 0, 10);\n // Draw all numbers in the array\n var spacing = 15;\n var elemsY = 25;\n for(var i = 0; i < numArray.length; i++) {\n text(numArray[i], i * spacing, elemsY);\n }\n maxX = 33;\n maxY = 80;\n // Draw the Minimum value in the array.\n textSize(32);\n text(min(numArray), maxX, maxY);\n}\n
Normalizes a number from another range into a value between 0 and 1.\nIdentical to map(value, low, high, 0, 1).\nNumbers outside of the range are not clamped to 0 and 1, because\nout-of-range values are often intentional and useful. (See the second\nexample above.)
\n",itemtype:"method",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"}],return:{description:"normalized number",type:"Number"},example:['\n\nfunction draw() {\n background(200);\n currentNum = mouseX;\n lowerBound = 0;\n upperBound = width; //100;\n normalized = norm(currentNum, lowerBound, upperBound);\n lineY = 70\n line(0, lineY, width, lineY);\n //Draw an ellipse mapped to the non-normalized value.\n noStroke();\n fill(50)\n var s = 7; // ellipse size\n ellipse(currentNum, lineY, s, s);\n\n // Draw the guide\n guideY = lineY + 15;\n text("0", 0, guideY);\n textAlign(RIGHT);\n text("100", width, guideY);\n\n // Draw the normalized value\n textAlign(LEFT);\n fill(0);\n textSize(32);\n normalY = 40;\n normalX = 20;\n text(normalized, normalX, normalY);\n}\n
Facilitates exponential expressions. The pow() function is an efficient\nway of multiplying numbers by themselves (or their reciprocals) in large\nquantities. For example, pow(3, 5) is equivalent to the expression\n33333 and pow(3, -5) is equivalent to 1 / 33333. Maps to\nMath.pow().
\n",itemtype:"method",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"}],return:{description:"n^e",type:"Number"},example:["\n\nfunction setup() {\n //Exponentially increase the size of an ellipse.\n eSize = 3; // Original Size\n eLoc = 10; // Original Location\n\n ellipse(eLoc, eLoc, eSize, eSize);\n\n ellipse(eLoc*2, eLoc*2, pow(eSize, 2), pow(eSize, 2));\n\n ellipse(eLoc*4, eLoc*4, pow(eSize, 3), pow(eSize, 3));\n\n ellipse(eLoc*8, eLoc*8, pow(eSize, 4), pow(eSize, 4));\n}\n
Calculates the integer closest to the n parameter. For example,\nround(133.8) returns the value 134. Maps to Math.round().
\n",itemtype:"method",name:"round",params:[{name:"n",description:"number to round
\n",type:"Number"}],return:{description:"rounded number",type:"Number"},example:["\n\nfunction draw() {\n background(200);\n //map, mouseX between 0 and 5.\n var ax = map(mouseX, 0, 100, 0, 5);\n var ay = 66;\n\n // Round the mapped number.\n var bx = round(map(mouseX, 0, 100, 0,5));\n var by = 33;\n\n // Multiply the mapped numbers by 20 to more easily\n // see the changes.\n stroke(0);\n fill(0);\n line(0, ay, ax * 20, ay);\n line(0, by, bx * 20, by);\n\n // Reformat the float returned by map and draw it.\n noStroke();\n text(nfc(ax, 2,2), ax, ay - 5);\n text(nfc(bx,1,1), bx, by - 5);\n}\n
Squares a number (multiplies a number by itself). The result is always a\npositive number, as multiplying two negative numbers always yields a\npositive result. For example, -1 * -1 = 1.
\n",itemtype:"method",name:"sq",params:[{name:"n",description:"number to square
\n",type:"Number"}],return:{description:"squared number",type:"Number"},example:['\n\nfunction draw() {\n background(200);\n eSize = 7;\n x1 = map(mouseX, 0, width, 0, 10);\n y1 = 80;\n x2 = sq(x1);\n y2 = 20;\n\n // Draw the non-squared.\n line(0, y1, width, y1);\n ellipse(x1, y1, eSize, eSize);\n\n // Draw the squared.\n line(0, y2, width, y2);\n ellipse(x2, y2, eSize, eSize);\n\n // Draw dividing line.\n stroke(100)\n line(0, height/2, width, height/2);\n\n // Draw text.\n var spacing = 15;\n noStroke();\n fill(0);\n text("x = " + x1, 0, y1 + spacing);\n text("sq(x) = " + x2, 0, y2 + spacing);\n}\n
Calculates the square root of a number. The square root of a number is\nalways positive, even though there may be a valid negative root. The\nsquare root s of number a is such that s*s = a. It is the opposite of\nsquaring. Maps to Math.sqrt().
\n",itemtype:"method",name:"sqrt",params:[{name:"n",description:"non-negative number to square root
\n",type:"Number"}],return:{description:"square root of number",type:"Number"},example:['\n\nfunction draw() {\n background(200);\n eSize = 7;\n x1 = mouseX;\n y1 = 80;\n x2 = sqrt(x1);\n y2 = 20;\n\n // Draw the non-squared.\n line(0, y1, width, y1);\n ellipse(x1, y1, eSize, eSize);\n\n // Draw the squared.\n line(0, y2, width, y2);\n ellipse(x2, y2, eSize, eSize);\n\n // Draw dividing line.\n stroke(100)\n line(0, height/2, width, height/2);\n\n // Draw text.\n noStroke();\n fill(0);\n var spacing = 15;\n text("x = " + x1, 0, y1 + spacing);\n text("sqrt(x) = " + x2, 0, y2 + spacing);\n}\n
Creates a new p5.Vector (the datatype for storing vectors). This provides a\ntwo or three dimensional vector, specifically a Euclidean (also known as\ngeometric) vector. A vector is an entity that has both magnitude and\ndirection.
\n",itemtype:"method",name:"createVector",params:[{name:"x",description:"x component of the vector
\n",type:"Number",optional:!0},{name:"y",description:"y component of the vector
\n",type:"Number",optional:!0},{name:"z",description:"z component of the vector
\n",type:"Number",optional:!0}],return:{description:"",type:"p5.Vector"},class:"p5",module:"Math",submodule:"Math"},{file:"src/math/noise.js",line:41, description:"Returns the Perlin noise value at specified coordinates. Perlin noise is\na random sequence generator producing a more natural ordered, harmonic\nsuccession of numbers compared to the standard random() function.\nIt was invented by Ken Perlin in the 1980s and been used since in\ngraphical applications to produce procedural textures, natural motion,\nshapes, terrains etc.
The main difference to the\nrandom() function is that Perlin noise is defined in an infinite\nn-dimensional space where each pair of coordinates corresponds to a\nfixed semi-random value (fixed only for the lifespan of the program; see\nthe noiseSeed() function). p5.js can compute 1D, 2D and 3D noise,\ndepending on the number of coordinates given. The resulting value will\nalways be between 0.0 and 1.0. The noise value can be animated by moving\nthrough the noise space as demonstrated in the example above. The 2nd\nand 3rd dimension can also be interpreted as time.
The actual\nnoise is structured similar to an audio signal, in respect to the\nfunction's use of frequencies. Similar to the concept of harmonics in\nphysics, perlin noise is computed over several octaves which are added\ntogether for the final result.
Another way to adjust the\ncharacter of the resulting sequence is the scale of the input\ncoordinates. As the function works within an infinite space the value of\nthe coordinates doesn't matter as such, only the distance between\nsuccessive coordinates does (eg. when using noise() within a\nloop). As a general rule the smaller the difference between coordinates,\nthe smoother the resulting noise sequence will be. Steps of 0.005-0.03\nwork best for most applications, but this will differ depending on use.
x-coordinate in noise space
\n",type:"Number"},{name:"y",description:"y-coordinate in noise space
\n",type:"Number",optional:!0},{name:"z",description:"z-coordinate in noise space
\n",type:"Number",optional:!0}],return:{description:"Perlin noise value (between 0 and 1) at specified\n coordinates",type:"Number"},example:["\nvar xoff = 0.0;\n\nfunction draw() {\n background(204);\n xoff = xoff + .01;\n var n = noise(xoff) * width;\n line(n, 0, n, height);\n}\n
\nvar noiseScale=0.02;\n\nfunction draw() {\n background(0);\n for (var x=0; x < width; x++) {\n var noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale);\n stroke(noiseVal*255);\n line(x, mouseY+noiseVal*80, x, height);\n }\n}\n
\nAdjusts the character and level of detail produced by the Perlin noise\n function. Similar to harmonics in physics, noise is computed over\n several octaves. Lower octaves contribute more to the output signal and\n as such define the overall intensity of the noise, whereas higher octaves\n create finer grained details in the noise sequence.\n
\n By default, noise is computed over 4 octaves with each octave contributing\n exactly half than its predecessor, starting at 50% strength for the 1st\n octave. This falloff amount can be changed by adding an additional function\n parameter. Eg. a falloff factor of 0.75 means each octave will now have\n 75% impact (25% less) of the previous lower octave. Any value between\n 0.0 and 1.0 is valid, however note that values greater than 0.5 might\n result in greater than 1.0 values returned by noise().\n
\n By changing these parameters, the signal created by the noise()\n function can be adapted to fit very specific needs and characteristics.
number of octaves to be used by the noise
\n",type:"Number"},{name:"falloff",description:"falloff factor for each octave
\n",type:"Number"}],example:["\n\nvar noiseVal;\n var noiseScale=0.02;\nfunction setup() {\n createCanvas(100,100);\n }\nfunction draw() {\n background(0);\n for (var y = 0; y < height; y++) {\n for (var x = 0; x < width/2; x++) {\n noiseDetail(2,0.2);\n noiseVal = noise((mouseX+x) * noiseScale,\n (mouseY+y) * noiseScale);\n stroke(noiseVal*255);\n point(x,y);\n noiseDetail(8,0.65);\n noiseVal = noise((mouseX + x + width/2) * noiseScale,\n (mouseY + y) * noiseScale);\n stroke(noiseVal*255);\n point(x + width/2, y);\n }\n }\n }\n
\n Sets the seed value for noise(). By default, noise()\nproduces different results each time the program is run. Set the\nvalue parameter to a constant to return the same pseudo-random\nnumbers each time the software is run.
\n",itemtype:"method",name:"noiseSeed",params:[{name:"seed",description:"the seed value
\n",type:"Number"}],example:["\nvar xoff = 0.0;\n\nfunction setup() {\n noiseSeed(99);\n stroke(0, 10);\n}\n\nfunction draw() {\n xoff = xoff + .01;\n var n = noise(xoff) * width;\n line(n, 0, n, height);\n}\n
\nThe x component of the vector
\n",itemtype:"property",name:"x",type:"Number",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:74,description:"The y component of the vector
\n",itemtype:"property",name:"y",type:"Number",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:79,description:"The z component of the vector
\n",itemtype:"property",name:"z",type:"Number",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:87,description:"Returns a string representation of a vector v by calling String(v)\nor v.toString(). This method is useful for logging vectors in the\nconsole.
\n",itemtype:"method",name:"toString",example:['\n\nfunction setup() {\n var v = createVector(20,30);\n print(String(v)); // prints "p5.Vector Object : [20, 30, 0]"\n}\n
Sets the x, y, and z component of the vector using two or three separate\nvariables, the data from a p5.Vector, or the values from a float array.
\n",itemtype:"method",name:"set",params:[{name:"x",description:"the x component of the vector or a\n p5.Vector or an Array
\n",type:"Number|p5.Vector|Array",optional:!0},{name:"y",description:"the y component of the vector
\n",type:"Number",optional:!0},{name:"z",description:"the z component of the vector
\n",type:"Number",optional:!0}],chainable:1,example:['\n\nfunction setup() {\n var v = createVector(1, 2, 3);\n v.set(4,5,6); // Sets vector to [4, 5, 6]\n\n var v1 = createVector(0, 0, 0);\n var arr = [1, 2, 3];\n v1.set(arr); // Sets vector to [1, 2, 3]\n}\n
\nGets a copy of the vector, returns a p5.Vector object.
\n",itemtype:"method",name:"copy",return:{description:"the copy of the p5.Vector object",type:"p5.Vector"},example:['\n\nvar v1 = createVector(1, 2, 3);\nvar v2 = v1.copy();\nprint(v1.x == v2.x && v1.y == v2.y && v1.z == v2.z);\n// Prints "true"\n
\nAdds x, y, and z components to a vector, adds one vector to another, or\nadds two independent vectors together. The version of the method that adds\ntwo vectors together is a static method and returns a p5.Vector, the others\nacts directly on the vector. See the examples for more context.
\n",itemtype:"method",name:"add",chainable:1,example:['\n\nvar v = createVector(1, 2, 3);\nv.add(4,5,6);\n// v\'s components are set to [5, 7, 9]\n
\n\n// Static method\nvar v1 = createVector(1, 2, 3);\nvar v2 = createVector(2, 3, 4);\n\nvar v3 = p5.Vector.add(v1, v2);\n// v3 has components [3, 5, 7]\n
\nthe x component of the vector to be\n added or a p5.Vector or an Array
\n",type:"Number|p5.Vector|Array"},{name:"y",description:"the y component of the vector to be\n added
\n",type:"Number",optional:!0},{name:"z",description:"the z component of the vector to be\n added
\n",type:"Number",optional:!0}],chainable:1},{line:907,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
\n",type:"p5.Vector"}],static:1},{line:914,params:[{name:"v1",description:"",type:"p5.Vector"},{name:"v2",description:"",type:"p5.Vector"}],static:1,return:{description:"the resulting p5.Vector",type:"p5.Vector"}}]},{file:"src/math/p5.Vector.js",line:222,description:"Subtracts x, y, and z components from a vector, subtracts one vector from\nanother, or subtracts two independent vectors. The version of the method\nthat subtracts two vectors is a static method and returns a p5.Vector, the\nother acts directly on the vector. See the examples for more context.
\n",itemtype:"method",name:"sub",chainable:1,example:['\n\nvar v = createVector(4, 5, 6);\nv.sub(1, 1, 1);\n// v\'s components are set to [3, 4, 5]\n
\n\n// Static method\nvar v1 = createVector(2, 3, 4);\nvar v2 = createVector(1, 2, 3);\n\nvar v3 = p5.Vector.sub(v1, v2);\n// v3 has components [1, 1, 1]\n
\nthe x component of the vector or a\n p5.Vector or an Array
\n",type:"Number|p5.Vector|Array"},{name:"y",description:"the y component of the vector
\n",type:"Number",optional:!0},{name:"z",description:"the z component of the vector
\n",type:"Number",optional:!0}],chainable:1},{line:937,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:"if undefined a new vector will be created
\n",type:"p5.Vector"}],static:1},{line:944,params:[{name:"v1",description:"",type:"p5.Vector"},{name:"v2",description:"",type:"p5.Vector"}],static:1,return:{description:"the resulting p5.Vector",type:"p5.Vector"}}]},{file:"src/math/p5.Vector.js",line:273,description:"Multiply the vector by a scalar. The static version of this method\ncreates a new p5.Vector while the non static version acts on the vector\ndirectly. See the examples for more context.
\n",itemtype:"method",name:"mult",chainable:1,example:['\n\nvar v = createVector(1, 2, 3);\nv.mult(2);\n// v\'s components are set to [2, 4, 6]\n
\n\n// Static method\nvar v1 = createVector(1, 2, 3);\nvar v2 = p5.Vector.mult(v1, 2);\n// v2 has components [2, 4, 6]\n
\nthe number to multiply with the vector
\n",type:"Number"}],chainable:1},{line:966,params:[{name:"v",description:"the vector to multiply
\n",type:"p5.Vector"},{name:"n",description:"",type:"Number"},{name:"target",description:"if undefined a new vector will be created
\n",type:"p5.Vector"}],static:1},{line:973,params:[{name:"v",description:"",type:"p5.Vector"},{name:"n",description:"",type:"Number"}],static:1,return:{description:"the resulting new p5.Vector",type:"p5.Vector"}}]},{file:"src/math/p5.Vector.js",line:306,description:"Divide the vector by a scalar. The static version of this method creates a\nnew p5.Vector while the non static version acts on the vector directly.\nSee the examples for more context.
\n",itemtype:"method",name:"div",chainable:1,example:['\n\nvar v = createVector(6, 4, 2);\nv.div(2); //v\'s components are set to [3, 2, 1]\n
\n\n// Static method\nvar v1 = createVector(6, 4, 2);\nvar v2 = p5.Vector.div(v, 2);\n// v2 has components [3, 2, 1]\n
\nthe number to divide the vector by
\n",type:"Number"}],chainable:1},{line:993,params:[{name:"v",description:"the vector to divide
\n",type:"p5.Vector"},{name:"n",description:"",type:"Number"},{name:"target",description:"if undefined a new vector will be created
\n",type:"p5.Vector"}],static:1},{line:1e3,params:[{name:"v",description:"",type:"p5.Vector"},{name:"n",description:"",type:"Number"}],static:1,return:{description:"the resulting new p5.Vector",type:"p5.Vector"}}]},{file:"src/math/p5.Vector.js",line:338,description:"Calculates the magnitude (length) of the vector and returns the result as\na float (this is simply the equation sqrt(xx + yy + z*z).)
\n",itemtype:"method",name:"mag",return:{description:"magnitude of the vector",type:"Number"},example:['\n\nvar v = createVector(20.0, 30.0, 40.0);\nvar m = v.mag();\nprint(m); // Prints "53.85164807134504"\n
\nthe vector to return the magnitude of
\n",type:"p5.Vector"}],static:1,return:{description:"the magnitude of vecT",type:"Number"}}]},{file:"src/math/p5.Vector.js",line:357,description:"Calculates the squared magnitude of the vector and returns the result\nas a float (this is simply the equation (xx + yy + z*z).)\nFaster if the real length is not required in the\ncase of comparing vectors, etc.
\n",itemtype:"method",name:"magSq",return:{description:"squared magnitude of the vector",type:"Number"},example:['\n\n// Static method\nvar v1 = createVector(6, 4, 2);\nprint(v1.magSq()); // Prints "56"\n
\nCalculates the dot product of two vectors. The version of the method\nthat computes the dot product of two independent vectors is a static\nmethod. See the examples for more context.
\n",itemtype:"method",name:"dot",return:{description:"the dot product",type:"Number"},example:['\n\nvar v1 = createVector(1, 2, 3);\nvar v2 = createVector(2, 3, 4);\n\nprint(v1.dot(v2)); // Prints "20"\n
\n\n//Static method\nvar v1 = createVector(1, 2, 3);\nvar v2 = createVector(3, 2, 1);\nprint (p5.Vector.dot(v1, v2)); // Prints "10"\n
\nx component of the vector or a p5.Vector
\n",type:"Number|p5.Vector"},{name:"y",description:"y component of the vector
\n",type:"Number",optional:!0},{name:"z",description:"z component of the vector
\n",type:"Number",optional:!0}],return:{description:"the dot product",type:"Number"}},{line:1021,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,return:{description:"the dot product",type:"Number"}}]},{file:"src/math/p5.Vector.js",line:419,description:"Calculates and returns a vector composed of the cross product between\ntwo vectors. Both the static and non static methods return a new p5.Vector.\nSee the examples for more context.
\n",itemtype:"method",name:"cross",return:{description:"p5.Vector composed of cross product",type:"p5.Vector"},example:['\n\nvar v1 = createVector(1, 2, 3);\nvar v2 = createVector(1, 2, 3);\n\nv1.cross(v2); // v\'s components are [0, 0, 0]\n
\n\n// Static method\nvar v1 = createVector(1, 0, 0);\nvar v2 = createVector(0, 1, 0);\n\nvar crossProduct = p5.Vector.cross(v1, v2);\n// crossProduct has components [0, 0, 1]\n
\np5.Vector to be crossed
\n",type:"p5.Vector"}],return:{description:"p5.Vector composed of cross product",type:"p5.Vector"}},{line:1035,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,return:{description:"the cross product",type:"Number"}}]},{file:"src/math/p5.Vector.js",line:459,description:"Calculates the Euclidean distance between two points (considering a\npoint as a vector object).
\n",itemtype:"method",name:"dist",return:{description:"the distance",type:"Number"},example:['\n\nvar v1 = createVector(1, 0, 0);\nvar v2 = createVector(0, 1, 0);\n\nvar distance = v1.dist(v2); // distance is 1.4142...\n
\n\n// Static method\nvar v1 = createVector(1, 0, 0);\nvar v2 = createVector(0, 1, 0);\n\nvar distance = p5.Vector.dist(v1,v2);\n// distance is 1.4142...\n
\nthe x, y, and z coordinates of a p5.Vector
\n",type:"p5.Vector"}],return:{description:"the distance",type:"Number"}},{line:1050,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,return:{description:"the distance",type:"Number"}}]},{file:"src/math/p5.Vector.js",line:491,description:"Normalize the vector to length 1 (make it a unit vector).
\n",itemtype:"method",name:"normalize",return:{description:"normalized p5.Vector",type:"p5.Vector"},example:['\n\nvar v = createVector(10, 20, 2);\n// v has components [10.0, 20.0, 2.0]\nv.normalize();\n// v\'s components are set to\n// [0.4454354, 0.8908708, 0.089087084]\n
\nLimit the magnitude of this vector to the value used for the max\nparameter.
\n",itemtype:"method",name:"limit",params:[{name:"max",description:"the maximum magnitude for the vector
\n",type:"Number"}],chainable:1,example:['\n\nvar v = createVector(10, 20, 2);\n// v has components [10.0, 20.0, 2.0]\nv.limit(5);\n// v\'s components are set to\n// [2.2271771, 4.4543543, 0.4454354]\n
\nSet the magnitude of this vector to the value used for the len\nparameter.
\n",itemtype:"method",name:"setMag",params:[{name:"len",description:"the new length for this vector
\n",type:"Number"}],chainable:1,example:['\n\nvar v = createVector(10, 20, 2);\n// v has components [10.0, 20.0, 2.0]\nv.setMag(10);\n// v\'s components are set to [6.0, 8.0, 0.0]\n
\nCalculate the angle of rotation for this vector (only 2D vectors)
\n",itemtype:"method",name:"heading",return:{description:"the angle of rotation",type:"Number"},example:['\n\nfunction setup() {\n var v1 = createVector(30,50);\n print(v1.heading()); // 1.0303768265243125\n\n var v1 = createVector(40,50);\n print(v1.heading()); // 0.8960553845713439\n\n var v1 = createVector(30,70);\n print(v1.heading()); // 1.1659045405098132\n}\n
Rotate the vector by an angle (only 2D vectors), magnitude remains the\nsame
\n",itemtype:"method",name:"rotate",params:[{name:"angle",description:"the angle of rotation
\n",type:"Number"}],chainable:1,example:['\n\nvar v = createVector(10.0, 20.0);\n// v has components [10.0, 20.0, 0.0]\nv.rotate(HALF_PI);\n// v\'s components are set to [-20.0, 9.999999, 0.0]\n
\nCalculates and returns the angle (in radians) between two vectors.
\n",itemtype:"method",name:"angleBetween",params:[{name:"the",description:"x, y, and z components of a p5.Vector
\n",type:"p5.Vector"}],return:{description:"the angle between (in radians)",type:"Number"},example:['\n\nvar v1 = createVector(1, 0, 0);\nvar v2 = createVector(0, 1, 0);\n\nvar angle = v1.angleBetween(v2);\n// angle is PI/2\n
\nLinear interpolate the vector to another vector
\n",itemtype:"method",name:"lerp",chainable:1,class:"p5.Vector",module:"Math",submodule:"Math",overloads:[{line:654,params:[{name:"x",description:"the x component
\n",type:"p5.Vector"},{name:"y",description:"the y component
\n",type:"p5.Vector"},{name:"z",description:"the z component
\n",type:"p5.Vector"},{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},{line:666,params:[{name:"v",description:"the p5.Vector to lerp to
\n",type:"p5.Vector"},{name:"amt",description:"",type:"Number"}],chainable:1},{line:1065,params:[{name:"v1",description:"",type:"p5.Vector"},{name:"v2",description:"",type:"p5.Vector"},{name:"amt",description:"",type:"Number"},{name:"target",description:"if undefined a new vector will be created
\n",type:"p5.Vector"}],static:1},{line:1073,params:[{name:"v1",description:"",type:"p5.Vector"},{name:"v2",description:"",type:"p5.Vector"},{name:"amt",description:"",type:"Number"}],static:1,return:{description:"the lerped value",type:"Number"}}]},{file:"src/math/p5.Vector.js",line:701,description:"Return a representation of this vector as a float array. This is only\nfor temporary use. If used in any other fashion, the contents should be\ncopied by using the p5.Vector.copy() method to copy into your own\narray.
\n",itemtype:"method",name:"array",return:{description:"an Array with the 3 values",type:"Number[]"},example:['\n\nfunction setup() {\n var v = createVector(20,30);\n print(v.array()); // Prints : Array [20, 30, 0]\n}\n
\nvar v = createVector(10.0, 20.0, 30.0);\nvar f = v.array();\nprint(f[0]); // Prints "10.0"\nprint(f[1]); // Prints "20.0"\nprint(f[2]); // Prints "30.0"\n
\nEquality check against a p5.Vector
\n",itemtype:"method",name:"equals",params:[{name:"x",description:"the x component of the vector or a\n p5.Vector or an Array
\n",type:"Number|p5.Vector|Array",optional:!0},{name:"y",description:"the y component of the vector
\n",type:"Number",optional:!0},{name:"z",description:"the z component of the vector
\n",type:"Number",optional:!0}],return:{description:"whether the vectors are equals",type:"Boolean"},example:['\n\nv1 = createVector(5,10,20);\nv2 = createVector(5,10,20);\nv3 = createVector(13,10,19);\n\nprint(v1.equals(v2.x,v2.y,v2.z)); // true\nprint(v1.equals(v3.x,v3.y,v3.z)); // false\n
\nvar v1 = createVector(10.0, 20.0, 30.0);\nvar v2 = createVector(10.0, 20.0, 30.0);\nvar v3 = createVector(0.0, 0.0, 0.0);\nprint (v1.equals(v2)) // true\nprint (v1.equals(v3)) // false\n
\nMake a new 2D unit vector from an angle
\n",itemtype:"method",name:"fromAngle",static:1,params:[{name:"angle",description:"the desired angle
\n",type:"Number"}],return:{description:"the new p5.Vector object",type:"p5.Vector"},example:['\n\nfunction draw() {\n background (200);\n\n // Create a variable, proportional to the mouseX,\n // varying from 0-360, to represent an angle in degrees.\n angleMode(DEGREES);\n var myDegrees = map(mouseX, 0,width, 0,360);\n\n // Display that variable in an onscreen text.\n // (Note the nfc() function to truncate additional decimal places,\n // and the "\\xB0" character for the degree symbol.)\n var readout = "angle = " + nfc(myDegrees,1,1) + "\\xB0"\n noStroke();\n fill (0);\n text (readout, 5, 15);\n\n // Create a p5.Vector using the fromAngle function,\n // and extract its x and y components.\n var v = p5.Vector.fromAngle(radians(myDegrees));\n var vx = v.x;\n var vy = v.y;\n\n push();\n translate (width/2, height/2);\n noFill();\n stroke (150);\n line (0,0, 30,0);\n stroke (0);\n line (0,0, 30*vx, 30*vy);\n pop()\n}\n
\nMake a new 2D unit vector from a random angle
\n",itemtype:"method",name:"random2D",static:1,return:{description:"the new p5.Vector object",type:"p5.Vector"},example:['\n\nvar v = p5.Vector.random2D();\n// May make v\'s attributes something like:\n// [0.61554617, -0.51195765, 0.0] or\n// [-0.4695841, -0.14366731, 0.0] or\n// [0.6091097, -0.22805278, 0.0]\n
\nMake a new random 3D unit vector.
\n",itemtype:"method",name:"random3D",static:1,return:{description:"the new p5.Vector object",type:"p5.Vector"},example:['\n\nvar v = p5.Vector.random3D();\n// May make v\'s attributes something like:\n// [0.61554617, -0.51195765, 0.599168] or\n// [-0.4695841, -0.14366731, -0.8711202] or\n// [0.6091097, -0.22805278, -0.7595902]\n
\nMultiplies a vector by a scalar and returns a new vector.
\n",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:990,description:"Divides a vector by a scalar and returns a new vector.
\n",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:1018,description:"Calculates the dot product of two vectors.
\n",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:1032,description:"Calculates the cross product of two vectors.
\n",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:1046,description:"Calculates the Euclidean distance between two points (considering a\npoint as a vector object).
\n",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/p5.Vector.js",line:1061,description:"Linear interpolate a vector to another vector and return the result as a\nnew vector.
\n",class:"p5.Vector",module:"Math",submodule:"Math"},{file:"src/math/random.js",line:47,description:"Sets the seed value for random().
\nBy default, random() produces different results each time the program\nis run. Set the seed parameter to a constant to return the same\npseudo-random numbers each time the software is run.
\n",itemtype:"method",name:"randomSeed",params:[{name:"seed",description:"the seed value
\n",type:"Number"}],example:["\n\nrandomSeed(99);\nfor (var i=0; i < 100; i++) {\n var r = random(0, 255);\n stroke(r);\n line(i, 0, i, 100);\n}\n
\nReturn a random floating-point number.
\nTakes either 0, 1 or 2 arguments.
\nIf no argument is given, returns a random number from 0\nup to (but not including) 1.
\nIf one argument is given and it is a number, returns a random number from 0\nup to (but not including) the number.
\nIf one argument is given and it is an array, returns a random element from\nthat array.
\nIf two arguments are given, returns a random number from the\nfirst argument up to (but not including) the second argument.
\n",itemtype:"method",name:"random",return:{description:"the random number",type:"Number"},example:['\n\nfor (var i = 0; i < 100; i++) {\n var r = random(50);\n stroke(r*5);\n line(50, i, 50+r, i);\n}\n
\n\nfor (var i = 0; i < 100; i++) {\n var r = random(-50, 50);\n line(50,i,50+r,i);\n}\n
\n\n// Get a random element from an array using the random(Array) syntax\nvar words = [ "apple", "bear", "cat", "dog" ];\nvar word = random(words); // select random word\ntext(word,10,50); // draw the word\n
\nthe lower bound (inclusive)
\n",type:"Number",optional:!0},{name:"max",description:"the upper bound (exclusive)
\n",type:"Number",optional:!0}],return:{description:"the random number",type:"Number"}},{line:132,params:[{name:"choices",description:"the array to choose from
\n",type:"Array"}],return:{description:"the random element from the array",type:"*"}}]},{file:"src/math/random.js",line:168,description:"Returns a random number fitting a Gaussian, or\n normal, distribution. There is theoretically no minimum or maximum\n value that randomGaussian() might return. Rather, there is\n just a very low probability that values far from the mean will be\n returned; and a higher probability that numbers near the mean will\n be returned.\n
\n Takes either 0, 1 or 2 arguments.
\n If no args, returns a mean of 0 and standard deviation of 1.
\n If one arg, that arg is the mean (standard deviation is 1).
\n If two args, first is mean, second is standard deviation.
the mean
\n",type:"Number"},{name:"sd",description:"the standard deviation
\n",type:"Number"}],return:{ description:"the random number",type:"Number"},example:["\nfor (var y = 0; y < 100; y++) {\n var x = randomGaussian(50,15);\n line(50, y, x, y);\n}\n
\n \nvar distribution = new Array(360);\n\nfunction setup() {\n createCanvas(100, 100);\n for (var i = 0; i < distribution.length; i++) {\n distribution[i] = floor(randomGaussian(0,15));\n }\n}\n\nfunction draw() {\n background(204);\n translate(width/2, width/2);\n for (var i = 0; i < distribution.length; i++) {\n rotate(TWO_PI/distribution.length);\n stroke(0);\n var dist = abs(distribution[i]);\n line(0, 0, dist, 0);\n }\n}\n
\n The inverse of cos(), returns the arc cosine of a value. This function\nexpects the values in the range of -1 to 1 and values are returned in\nthe range 0 to PI (3.1415927).
\n",itemtype:"method",name:"acos",params:[{name:"value",description:"the value whose arc cosine is to be returned
\n",type:"Number"}],return:{description:"the arc cosine of the given value",type:"Number"},example:['\n\nvar a = PI;\nvar c = cos(a);\nvar ac = acos(c);\n// Prints: "3.1415927 : -1.0 : 3.1415927"\nprint(a + " : " + c + " : " + ac);\n
\n\nvar a = PI + PI/4.0;\nvar c = cos(a);\nvar ac = acos(c);\n// Prints: "3.926991 : -0.70710665 : 2.3561943"\nprint(a + " : " + c + " : " + ac);\n
\nThe inverse of sin(), returns the arc sine of a value. This function\nexpects the values in the range of -1 to 1 and values are returned\nin the range -PI/2 to PI/2.
\n",itemtype:"method",name:"asin",params:[{name:"value",description:"the value whose arc sine is to be returned
\n",type:"Number"}],return:{description:"the arc sine of the given value",type:"Number"},example:['\n\nvar a = PI + PI/3;\nvar s = sin(a);\nvar as = asin(s);\n// Prints: "1.0471976 : 0.86602545 : 1.0471976"\nprint(a + " : " + s + " : " + as);\n
\n\nvar a = PI + PI/3.0;\nvar s = sin(a);\nvar as = asin(s);\n// Prints: "4.1887903 : -0.86602545 : -1.0471976"\nprint(a + " : " + s + " : " + as);\n
\nThe inverse of tan(), returns the arc tangent of a value. This function\nexpects the values in the range of -Infinity to Infinity (exclusive) and\nvalues are returned in the range -PI/2 to PI/2.
\n",itemtype:"method",name:"atan",params:[{name:"value",description:"the value whose arc tangent is to be returned
\n",type:"Number"}],return:{description:"the arc tangent of the given value",type:"Number"},example:['\n\nvar a = PI + PI/3;\nvar t = tan(a);\nvar at = atan(t);\n// Prints: "1.0471976 : 1.7320509 : 1.0471976"\nprint(a + " : " + t + " : " + at);\n
\n\nvar a = PI + PI/3.0;\nvar t = tan(a);\nvar at = atan(t);\n// Prints: "4.1887903 : 1.7320513 : 1.0471977"\nprint(a + " : " + t + " : " + at);\n
\nCalculates the angle (in radians) from a specified point to the coordinate\norigin as measured from the positive x-axis. Values are returned as a\nfloat in the range from PI to -PI. The atan2() function is most often used\nfor orienting geometry to the position of the cursor.\n
\nNote: The y-coordinate of the point is the first parameter, and the\nx-coordinate is the second parameter, due the the structure of calculating\nthe tangent.
y-coordinate of the point
\n",type:"Number"},{name:"x",description:"x-coordinate of the point
\n",type:"Number"}],return:{description:"the arc tangent of the given point",type:"Number"},example:["\n\nfunction draw() {\n background(204);\n translate(width/2, height/2);\n var a = atan2(mouseY-height/2, mouseX-width/2);\n rotate(a);\n rect(-30, -5, 60, 10);\n}\n
\nCalculates the cosine of an angle. This function takes into account the\ncurrent angleMode. Values are returned in the range -1 to 1.
\n",itemtype:"method",name:"cos",params:[{name:"angle",description:"the angle
\n",type:"Number"}],return:{description:"the cosine of the angle",type:"Number"},example:["\n\nvar a = 0.0;\nvar inc = TWO_PI/25.0;\nfor (var i = 0; i < 25; i++) {\n line(i*4, 50, i*4, 50+cos(a)*40.0);\n a = a + inc;\n}\n
\nCalculates the sine of an angle. This function takes into account the\ncurrent angleMode. Values are returned in the range -1 to 1.
\n",itemtype:"method",name:"sin",params:[{name:"angle",description:"the angle
\n",type:"Number"}],return:{description:"the sine of the angle",type:"Number"},example:["\n\nvar a = 0.0;\nvar inc = TWO_PI/25.0;\nfor (var i = 0; i < 25; i++) {\n line(i*4, 50, i*4, 50+sin(a)*40.0);\n a = a + inc;\n}\n
\nCalculates the tangent of an angle. This function takes into account\nthe current angleMode. Values are returned in the range -1 to 1.
\n",itemtype:"method",name:"tan",params:[{name:"angle",description:"the angle
\n",type:"Number"}],return:{description:"the tangent of the angle",type:"Number"},example:["\n\n var a = 0.0;\n var inc = TWO_PI/50.0;\n for (var i = 0; i < 100; i = i+2) {\n line(i, 50, i, 50+tan(a)*2.0);\n a = a + inc;\n }\n
"],alt:"vertical black lines end down and up from center to form spike pattern",class:"p5",module:"Math",submodule:"Trigonometry"},{file:"src/math/trigonometry.js",line:270,description:"Converts a radian measurement to its corresponding value in degrees.\nRadians and degrees are two ways of measuring the same thing. There are\n360 degrees in a circle and 2*PI radians in a circle. For example,\n90° = PI/2 = 1.5707964.
\n",itemtype:"method",name:"degrees",params:[{name:"radians",description:"the radians value to convert to degrees
\n",type:"Number"}],return:{description:"the converted angle",type:"Number"},example:['\n\nvar rad = PI/4;\nvar deg = degrees(rad);\nprint(rad + " radians is " + deg + " degrees");\n// Prints: 0.7853981633974483 radians is 45 degrees\n
\nConverts a degree measurement to its corresponding value in radians.\nRadians and degrees are two ways of measuring the same thing. There are\n360 degrees in a circle and 2*PI radians in a circle. For example,\n90° = PI/2 = 1.5707964.
\n",itemtype:"method",name:"radians",params:[{name:"degrees",description:"the degree value to convert to radians
\n",type:"Number"}],return:{description:"the converted angle",type:"Number"},example:['\n\nvar deg = 45.0;\nvar rad = radians(deg);\nprint(deg + " degrees is " + rad + " radians");\n// Prints: 45 degrees is 0.7853981633974483 radians\n
\nSets the current mode of p5 to given mode. Default mode is RADIANS.
\n",itemtype:"method",name:"angleMode",params:[{name:"mode",description:"either RADIANS or DEGREES
\n",type:"Constant"}],example:["\n\nfunction draw(){\n background(204);\n angleMode(DEGREES); // Change the mode to DEGREES\n var a = atan2(mouseY-height/2, mouseX-width/2);\n translate(width/2, height/2);\n push();\n rotate(a);\n rect(-20, -5, 40, 10); // Larger rectangle is rotating in degrees\n pop();\n angleMode(RADIANS); // Change the mode to RADIANS\n rotate(a); // var a stays the same\n rect(-40, -5, 20, 10); // Smaller rectangle is rotating in radians\n}\n
\nSets the current alignment for drawing text. Accepts two\narguments: horizAlign (LEFT, CENTER, or RIGHT) and\nvertAlign (TOP, BOTTOM, CENTER, or BASELINE).
\nThe horizAlign parameter is in reference to the x value\nof the text() function, while the vertAlign parameter is\nin reference to the y value.
\nSo if you write textAlign(LEFT), you are aligning the left\nedge of your text to the x value you give in text(). If you\nwrite textAlign(RIGHT, TOP), you are aligning the right edge\nof your text to the x value and the top of edge of the text\nto the y value.
\n",itemtype:"method",name:"textAlign",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:!0}],return:{description:"",type:"Number"},example:['\n\ntextSize(16);\ntextAlign(RIGHT);\ntext("ABCD", 50, 30);\ntextAlign(CENTER);\ntext("EFGH", 50, 50);\ntextAlign(LEFT);\ntext("IJKL", 50, 70);\n
\nSets/gets the spacing, in pixels, between lines of text. This\nsetting will be used in all subsequent calls to the text() function.
\n",itemtype:"method",name:"textLeading",chainable:1,class:"p5",module:"Typography",submodule:"Attributes",overloads:[{line:55,params:[{name:"leading",description:"the size in pixels for spacing between lines
\n",type:"Number"}],chainable:1},{line:63,params:[],return:{description:"",type:"Number"}}]},{file:"src/typography/attributes.js",line:92,description:"Sets/gets the current font size. This size will be used in all subsequent\ncalls to the text() function. Font size is measured in pixels.
\n",itemtype:"method",name:"textSize",chainable:1,class:"p5",module:"Typography",submodule:"Attributes",overloads:[{line:92,params:[{name:"theSize",description:"the size of the letters in units of pixels
\n",type:"Number"}],chainable:1},{line:100,params:[],return:{description:"",type:"Number"}}]},{file:"src/typography/attributes.js",line:123,description:"Sets/gets the style of the text for system fonts to NORMAL, ITALIC, or BOLD.\nNote: this may be is overridden by CSS styling. For non-system fonts\n(opentype, truetype, etc.) please load styled fonts instead.
\n",itemtype:"method",name:"textStyle",chainable:1,class:"p5",module:"Typography",submodule:"Attributes",overloads:[{line:123,params:[{name:"theStyle",description:"styling for text, either NORMAL,\n ITALIC, or BOLD
\n",type:"Constant"}],chainable:1},{line:133,params:[],return:{description:"",type:"String"}}]},{file:"src/typography/attributes.js",line:158,description:"Calculates and returns the width of any character or text string.
\n",itemtype:"method",name:"textWidth",params:[{name:"theText",description:"the String of characters to measure
\n",type:"String"}],return:{description:"",type:"Number"},example:["\n\ntextSize(28);\n\nvar aChar = 'P';\nvar cWidth = textWidth(aChar);\ntext(aChar, 0, 40);\nline(cWidth, 0, cWidth, 50);\n\nvar aString = \"p5.js\";\nvar sWidth = textWidth(aString);\ntext(aString, 0, 85);\nline(sWidth, 50, sWidth, 100);\n
\nReturns the ascent of the current font at its current size. The ascent\nrepresents the distance, in pixels, of the tallest character above\nthe baseline.
\n",itemtype:"method",name:"textAscent",return:{description:"",type:"Number"},example:['\n\nvar base = height * 0.75;\nvar scalar = 0.8; // Different for each font\n\ntextSize(32); // Set initial text size\nvar asc = textAscent() * scalar; // Calc ascent\nline(0, base - asc, width, base - asc);\ntext("dp", 0, base); // Draw text on baseline\n\ntextSize(64); // Increase text size\nasc = textAscent() * scalar; // Recalc ascent\nline(40, base - asc, width, base - asc);\ntext("dp", 40, base); // Draw text on baseline\n
\nReturns the descent of the current font at its current size. The descent\nrepresents the distance, in pixels, of the character with the longest\ndescender below the baseline.
\n",itemtype:"method",name:"textDescent",return:{description:"",type:"Number"},example:['\n\nvar base = height * 0.75;\nvar scalar = 0.8; // Different for each font\n\ntextSize(32); // Set initial text size\nvar desc = textDescent() * scalar; // Calc ascent\nline(0, base+desc, width, base+desc);\ntext("dp", 0, base); // Draw text on baseline\n\ntextSize(64); // Increase text size\ndesc = textDescent() * scalar; // Recalc ascent\nline(40, base + desc, width, base + desc);\ntext("dp", 40, base); // Draw text on baseline\n
\nHelper function to measure ascent and descent.
\n",class:"p5",module:"Typography",submodule:"Attributes"},{file:"src/typography/loading_displaying.js",line:16,description:"Loads an opentype font file (.otf, .ttf) from a file or a URL,\nand returns a PFont Object. This method is asynchronous,\nmeaning it may not finish before the next line in your sketch\nis executed.\n
\nThe path to the font should be relative to the HTML file\nthat links in your sketch. Loading an from a URL or other\nremote location may be blocked due to your browser's built-in\nsecurity.
name of the file or url to load
\n",type:"String"},{name:"callback",description:"function to be executed after\n loadFont()\n completes
\n",type:"Function",optional:!0}],return:{description:"p5.Font object",type:"p5.Font"},example:["\n\nCalling loadFont() inside preload() guarantees that the load\noperation will have completed before setup() and draw() are called.
\n\n\nvar myFont;\nfunction preload() {\n myFont = loadFont('assets/AvenirNextLTPro-Demi.otf');\n}\n\nfunction setup() {\n fill('#ED225D');\n textFont(myFont);\n textSize(36);\n text('p5*js', 10, 50);\n}\n
\nfunction setup() {\n loadFont('assets/AvenirNextLTPro-Demi.otf', drawText);\n}\n\nfunction drawText(font) {\n fill('#ED225D');\n textFont(font, 36);\n text('p5*js', 10, 50);\n}\n\n
You can also use the string name of the font to style other HTML\nelements.
\n\n\nvar myFont;\n\nfunction preload() {\n myFont = loadFont('assets/Avenir.otf');\n}\n\nfunction setup() {\n var myDiv = createDiv('hello there');\n myDiv.style('font-family', 'Avenir');\n}\n
Draws text to the screen. Displays the information specified in the first\nparameter on the screen in the position specified by the additional\nparameters. A default font will be used unless a font is set with the\ntextFont() function and a default size will be used unless a font is set\nwith textSize(). Change the color of the text with the fill() function.\nChange the outline of the text with the stroke() and strokeWeight()\nfunctions.\n
\nThe text displays in relation to the textAlign() function, which gives the\noption to draw to the left, right, and center of the coordinates.\n
\nThe x2 and y2 parameters define a rectangular area to display within and\nmay only be used with string data. When these parameters are specified,\nthey are interpreted based on the current rectMode() setting. Text that\ndoes not fit completely within the rectangle specified will not be drawn\nto the screen.
the alphanumeric symbols to be displayed
\n",type:"String"},{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:!0},{name:"y2",description:"by default, the height of the text box,\n see rectMode() for more info
\n",type:"Number",optional:!0}],return:{description:"this",type:"P5"},example:['\n\ntextSize(32);\ntext("word", 10, 30);\nfill(0, 102, 153);\ntext("word", 10, 60);\nfill(0, 102, 153, 51);\ntext("word", 10, 90);\n
\n\ns = "The quick brown fox jumped over the lazy dog.";\nfill(50);\ntext(s, 10, 10, 70, 80); // Text wraps within text box\n
\nSets the current font that will be drawn with the text() function.
\n",itemtype:"method",name:"textFont",return:{description:"the current font",type:"Object"},class:"p5",module:"Typography",submodule:"Loading & Displaying",overloads:[{line:191,params:[],return:{description:"the current font",type:"Object"}},{line:197,params:[{name:"font",description:'a font loaded via loadFont(), or a String\nrepresenting a web safe font (a font\nthat is generally available across all systems)
\n',type:"Object|String"},{name:"size",description:"the font size to use
\n",type:"Number",optional:!0}],chainable:1}]},{file:"src/typography/p5.Font.js",line:33,description:"Underlying opentype font implementation
\n",itemtype:"property",name:"font",class:"p5.Font",module:"Typography",submodule:"Font"},{file:"src/typography/p5.Font.js",line:47,description:"Returns a tight bounding box for the given text string using this\nfont (currently only supports single lines)
\n",itemtype:"method",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)
\n",type:"Number"},{name:"options",description:"opentype options (optional)
\n",type:"Object"}],return:{description:"a rectangle object with properties: x, y, w, h",type:"Object"},example:["\n\nvar font;\nvar textString = 'Lorem ipsum dolor sit amet.';\nfunction preload() {\n font = loadFont('./assets/Regular.otf');\n};\nfunction setup() {\n background(210);\n\n var bbox = font.textBounds(textString, 10, 30, 12);\n fill(255);\n stroke(0);\n rect(bbox.x, bbox.y, bbox.w, bbox.h);\n fill(0);\n noStroke();\n\n textFont(font);\n textSize(12);\n text(textString, 10, 30);\n};\n
\nComputes an array of points following the path for specified text
\n",itemtype:"method",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=.25); 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
Returns the set of opentype glyphs for the supplied string.
\nNote that there is not a strict one-to-one mapping between characters\nand glyphs, so the list of returned glyphs can be larger or smaller\n than the length of the given string.
\n",params:[{name:"str",description:"the string to be converted
\n",type:"String"}],return:{description:"the opentype glyphs",type:"Array"},class:"p5.Font",module:"Typography",submodule:"Font"},{file:"src/typography/p5.Font.js",line:221,description:"Returns an opentype path for the supplied string and position.
\n",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:"options",description:"opentype options (optional)
\n",type:"Object"}],return:{description:"the opentype path",type:"Object"},class:"p5.Font",module:"Typography",submodule:"Font"},{file:"src/utilities/array_functions.js",line:12,description:"Adds a value to the end of an array. Extends the length of\nthe array by one. Maps to Array.push().
\n",itemtype:"method",name:"append",params:[{name:"array",description:"Array to append
\n",type:"Array"},{name:"value",description:"to be added to the Array
\n",type:"Any"}],example:['\n\nfunction setup() {\n\nvar myArray = new Array("Mango", "Apple", "Papaya")\nprint(myArray) // ["Mango", "Apple", "Papaya"]\n\nappend(myArray, "Peach")\nprint(myArray) // ["Mango", "Apple", "Papaya", "Peach"]\n\n}\n
Copies an array (or part of an array) to another array. The src array is\ncopied to the dst array, beginning at the position specified by\nsrcPosition and into the position specified by dstPosition. The number of\nelements to copy is determined by length. Note that copying values\noverwrites existing values in the destination array. To append values\ninstead of overwriting them, use concat().\n
\nThe simplified version with only two arguments, arrayCopy(src, dst),\ncopies an entire array to another of the same size. It is equivalent to\narrayCopy(src, 0, dst, 0, src.length).\n
\nUsing this function is far more efficient for copying array data than\niterating through a for() loop and copying each element individually.
the source Array
\n",type:"Array"},{name:"srcPosition",description:"starting position in the source Array
\n",type:"Number"},{name:"dst",description:"the destination Array
\n",type:"Array"},{name:"dstPosition",description:"starting position in the destination Array
\n",type:"Number"},{name:"length",description:"number of Array elements to be copied
\n",type:"Number"}]},{line:59,params:[{name:"src",description:"",type:"Array"},{name:"dst",description:"",type:"Array"},{name:"length",description:"",type:"Number",optional:!0}]}]},{file:"src/utilities/array_functions.js",line:124,description:"Concatenates two arrays, maps to Array.concat(). Does not modify the\ninput arrays.
\n",itemtype:"method",name:"concat",params:[{name:"a",description:"first Array to concatenate
\n",type:"Array"},{name:"b",description:"second Array to concatenate
\n",type:"Array"}],return:{description:"concatenated array",type:"Array"},example:['\n\nfunction setup() {\n var arr1 = new Array("A", "B", "C");\n var arr2 = new Array( 1 , 2 , 3 );\n\n print(arr1); // ["A","B","C"]\n print(arr2); // [1,2,3]\n\n var arr3 = concat(arr1, arr2);\n\n print(arr1); // ["A","B","C"]\n print(arr2); // [1,2,3]\n print(arr3); // ["A","B","C",1,2,3]\n\n}\n
Reverses the order of an array, maps to Array.reverse()
\n",itemtype:"method",name:"reverse",params:[{name:"list",description:"Array to reverse
\n",type:"Array"}],example:['\n\nfunction setup() {\n var myArray = new Array("A", "B", "C");\n print(myArray); // ["A","B","C"]\n\n reverse(myArray);\n print(myArray); // ["C","B","A"]\n}\n
Decreases an array by one element and returns the shortened array,\nmaps to Array.pop().
\n",itemtype:"method",name:"shorten",params:[{name:"list",description:"Array to shorten
\n",type:"Array"}],return:{description:"shortened Array",type:"Array"},example:['\n\nfunction setup() {\n var myArray = new Array("A", "B", "C");\n print(myArray); // ["A","B","C"]\n\n var newArray = shorten(myArray);\n print(myArray); // ["A","B","C"]\n print(newArray); // ["A","B"]\n}\n
Randomizes the order of the elements of an array. Implements\n\nFisher-Yates Shuffle Algorithm.
\n',itemtype:"method",name:"shuffle",params:[{name:"array",description:"Array to shuffle
\n",type:"Array"},{name:"bool",description:"modify passed array
\n",type:"Boolean",optional:!0}],return:{description:"shuffled Array",type:"Array"},example:["\n\nfunction setup() {\n var regularArr = ['ABC', 'def', createVector(), TAU, Math.E];\n print(regularArr);\n shuffle(regularArr, true); // force modifications to passed array\n print(regularArr);\n\n // By default shuffle() returns a shuffled cloned array:\n var newArr = shuffle(regularArr);\n print(regularArr);\n print(newArr);\n}\n
Sorts an array of numbers from smallest to largest, or puts an array of\nwords in alphabetical order. The original array is not modified; a\nre-ordered array is returned. The count parameter states the number of\nelements to sort. For example, if there are 12 elements in an array and\ncount is set to 5, only the first 5 elements in the array will be sorted.
\n",itemtype:"method",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:"Number",optional:!0}],example:['\n\nfunction setup() {\n var words = new Array("banana", "apple", "pear","lime");\n print(words); // ["banana", "apple", "pear", "lime"]\n var count = 4; // length of array\n\n words = sort(words, count);\n print(words); // ["apple", "banana", "lime", "pear"]\n}\n
\nfunction setup() {\n var numbers = new Array(2,6,1,5,14,9,8,12);\n print(numbers); // [2,6,1,5,14,9,8,12]\n var count = 5; // Less than the length of the array\n\n numbers = sort(numbers, count);\n print(numbers); // [1,2,5,6,14,9,8,12]\n}\n
Inserts a value or an array of values into an existing array. The first\nparameter specifies the initial array to be modified, and the second\nparameter defines the data to be inserted. The third parameter is an index\nvalue which specifies the array position from which to insert data.\n(Remember that array index numbering starts at zero, so the first position\nis 0, the second position is 1, and so on.)
\n",itemtype:"method",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:"Number"}],example:['\n\nfunction setup() {\n var myArray = new Array(0,1,2,3,4);\n var insArray = new Array("A","B","C");\n print(myArray); // [0,1,2,3,4]\n print(insArray); // ["A","B","C"]\n\n splice(myArray, insArray, 3);\n print(myArray); // [0,1,2,"A","B","C",3,4]\n}\n
Extracts an array of elements from an existing array. The list parameter\ndefines the array from which the elements will be copied, and the start\nand count parameters specify which elements to extract. If no count is\ngiven, elements will be extracted from the start to the end of the array.\nWhen specifying the start, remember that the first array element is 0.\nThis function does not change the source array.
\n",itemtype:"method",name:"subset",params:[{name:"list",description:"Array to extract from
\n",type:"Array"},{name:"start",description:"position to begin
\n",type:"Number"},{name:"count",description:"number of values to extract
\n",type:"Number",optional:!0}],return:{description:"Array of extracted elements",type:"Array"},example:['\n\nfunction setup() {\n var myArray = new Array(1,2,3,4,5);\n print(myArray); // [1,2,3,4,5]\n\n var sub1 = subset(myArray, 0, 3);\n var sub2 = subset(myArray, 2, 2);\n print(sub1); // [1,2,3]\n print(sub2); // [3,4]\n}\n
Converts a string to its floating point representation. The contents of a\nstring must resemble a number, or NaN (not a number) will be returned.\nFor example, float("1234.56") evaluates to 1234.56, but float("giraffe")\nwill return NaN.
\nWhen an array of values is passed in, then an array of floats of the same\nlength is returned.
\n",itemtype:"method",name:"float",params:[{name:"str",description:"float string to parse
\n",type:"String"}],return:{description:"floating point representation of string",type:"Number"},example:["\n\nvar str = '20';\nvar diameter = float(str);\nellipse(width/2, height/2, diameter, diameter);\n
Converts a boolean, string, or float to its integer representation.\nWhen an array of values is passed in, then an int array of the same length\nis returned.
\n",itemtype:"method",name:"int",return:{description:"integer representation of value",type:"Number"},class:"p5",module:"Data",submodule:"Conversion",overloads:[{line:42,params:[{name:"n",description:"value to parse
\n",type:"String|Boolean|Number"}],return:{description:"integer representation of value",type:"Number"}},{line:51,params:[{name:"ns",description:"values to parse
\n",type:"Array"}],return:{description:"integer representation of values",type:"Number[]"}}]},{file:"src/utilities/conversion.js",line:79,description:"Converts a boolean, string or number to its string representation.\nWhen an array of values is passed in, then an array of strings of the same\nlength is returned.
\n",itemtype:"method",name:"str",params:[{name:"n",description:"value to parse
\n",type:"String|Boolean|Number|Array"}],return:{description:"string representation of value",type:"String"},example:['\n\nprint(str("10")); // "10"\nprint(str(10.31)); // "10.31"\nprint(str(-10)); // "-10"\nprint(str(true)); // "true"\nprint(str(false)); // "false"\nprint(str([true, "10.3", 9.8])); // [ "true", "10.3", "9.8" ]\n
Converts a number or string to its boolean representation.\nFor a number, any non-zero value (positive or negative) evaluates to true,\nwhile zero evaluates to false. For a string, the value "true" evaluates to\ntrue, while any other value evaluates to false. When an array of number or\nstring values is passed in, then a array of booleans of the same length is\nreturned.
\n",itemtype:"method",name:"boolean",params:[{name:"n",description:"value to parse
\n",type:"String|Boolean|Number|Array"}],return:{description:"boolean representation of value",type:"Boolean"},example:['\n\nprint(boolean(0)); // false\nprint(boolean(1)); // true\nprint(boolean("true")); // true\nprint(boolean("abcd")); // false\nprint(boolean([0, 12, "true"])); // [false, true, false]\n
Converts a number, string or boolean to its byte representation.\nA byte can be only a whole number between -128 and 127, so when a value\noutside of this range is converted, it wraps around to the corresponding\nbyte representation. When an array of number, string or boolean values is\npassed in, then an array of bytes the same length is returned.
\n",itemtype:"method",name:"byte",return:{description:"byte representation of value",type:"Number"},class:"p5",module:"Data",submodule:"Conversion",overloads:[{line:137,params:[{name:"n",description:"value to parse
\n",type:"String|Boolean|Number"}],return:{description:"byte representation of value",type:"Number"}},{line:148,params:[{name:"ns",description:"values to parse
\n",type:"Array"}],return:{description:"array of byte representation of values",type:"Number[]"}}]},{file:"src/utilities/conversion.js",line:171,description:"Converts a number or string to its corresponding single-character\nstring representation. If a string parameter is provided, it is first\nparsed as an integer and then translated into a single-character string.\nWhen an array of number or string values is passed in, then an array of\nsingle-character strings of the same length is returned.
\n",itemtype:"method",name:"char",return:{description:"string representation of value",type:"String"},class:"p5",module:"Data",submodule:"Conversion",overloads:[{line:171,params:[{name:"n",description:"value to parse
\n",type:"String|Number"}],return:{description:"string representation of value",type:"String"}},{line:182,params:[{name:"ns",description:"values to parse
\n",type:"Array"}],return:{description:"array of string representation of values",type:"String[]"}}]},{file:"src/utilities/conversion.js",line:204,description:"Converts a single-character string to its corresponding integer\nrepresentation. When an array of single-character string values is passed\nin, then an array of integers of the same length is returned.
\n",itemtype:"method",name:"unchar",return:{description:"integer representation of value",type:"Number"},class:"p5",module:"Data",submodule:"Conversion",overloads:[{line:204,params:[{name:"n",description:"value to parse
\n",type:"String"}],return:{description:"integer representation of value",type:"Number"}},{line:213,params:[{name:"ns",description:"values to parse
\n",type:"Array"}],return:{description:"integer representation of values",type:"Number[]"}}]},{file:"src/utilities/conversion.js",line:232,description:"Converts a number to a string in its equivalent hexadecimal notation. If a\nsecond parameter is passed, it is used to set the number of characters to\ngenerate in the hexadecimal notation. When an array is passed in, an\narray of strings in hexadecimal notation of the same length is returned.
\n",itemtype:"method",name:"hex",return:{description:"hexadecimal string representation of value",type:"String"},class:"p5",module:"Data",submodule:"Conversion",overloads:[{line:232,params:[{name:"n",description:"value to parse
\n",type:"Number"},{name:"digits",description:"",type:"Number",optional:!0}],return:{description:"hexadecimal string representation of value",type:"String"}},{line:243,params:[{name:"ns",description:"array of values to parse
\n",type:"Number[]"},{name:"digits",description:"",type:"Number",optional:!0}],return:{description:"hexadecimal string representation of values",type:"String[]"}}]},{file:"src/utilities/conversion.js",line:274,description:"Converts a string representation of a hexadecimal number to its equivalent\ninteger value. When an array of strings in hexadecimal notation is passed\nin, an array of integers of the same length is returned.
\n",itemtype:"method",name:"unhex",return:{description:"integer representation of hexadecimal value",type:"Number"},class:"p5",module:"Data",submodule:"Conversion",overloads:[{line:274,params:[{name:"n",description:"value to parse
\n",type:"String"}],return:{description:"integer representation of hexadecimal value",type:"Number"}},{line:283,params:[{name:"ns",description:"values to parse
\n",type:"Array"}],return:{description:"integer representations of hexadecimal value",type:"Number[]"}}]},{file:"src/utilities/string_functions.js",line:15,description:"Combines an array of Strings into one String, each separated by the\ncharacter(s) used for the separator parameter. To join arrays of ints or\nfloats, it's necessary to first convert them to Strings using nf() or\nnfs().
\n",itemtype:"method",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"}],return:{description:"joined String",type:"String"},example:['\n\nvar array = ["Hello", "world!"]\nvar separator = " "\nvar message = join(array, separator);\ntext(message, 5, 50);\n
\nThis function is used to apply a regular expression to a piece of text,\nand return matching groups (elements found inside parentheses) as a\nString array. If there are no matches, a null value will be returned.\nIf no groups are specified in the regular expression, but the sequence\nmatches, an array of length 1 (with the matched text as the first element\nof the array) will be returned.\n
\nTo use the function, first check to see if the result is null. If the\nresult is null, then the sequence did not match at all. If the sequence\ndid match, an array is returned.\n
\nIf there are groups (specified by sets of parentheses) in the regular\nexpression, then the contents of each will be returned in the array.\nElement [0] of a regular expression match returns the entire matching\nstring, and the match groups start at element [1] (the first group is [1],\nthe second [2], and so on).
the String to be searched
\n",type:"String"},{name:"regexp",description:"the regexp to be used for matching
\n",type:"String"}],return:{description:"Array of Strings found",type:"String[]"},example:['\n\nvar string = "Hello p5js*!"\nvar regexp = "p5js\\\\*"\nvar match = match(string, regexp);\ntext(match, 5, 50);\n
\nThis function is used to apply a regular expression to a piece of text,\nand return a list of matching groups (elements found inside parentheses)\nas a two-dimensional String array. If there are no matches, a null value\nwill be returned. If no groups are specified in the regular expression,\nbut the sequence matches, a two dimensional array is still returned, but\nthe second dimension is only of length one.\n
\nTo use the function, first check to see if the result is null. If the\nresult is null, then the sequence did not match at all. If the sequence\ndid match, a 2D array is returned.\n
\nIf there are groups (specified by sets of parentheses) in the regular\nexpression, then the contents of each will be returned in the array.\nAssuming a loop with counter variable i, element [i][0] of a regular\nexpression match returns the entire matching string, and the match groups\nstart at element [i][1] (the first group is [i][1], the second [i][2],\nand so on).
the String to be searched
\n",type:"String"},{name:"regexp",description:"the regexp to be used for matching
\n",type:"String"}],return:{description:"2d Array of Strings found",type:"String[]"},example:['\n\nvar string = "Hello p5js*! Hello world!"\nvar regexp = "Hello"\nmatchAll(string, regexp);\n
\nUtility function for formatting numbers into strings. There are two\nversions: one for formatting floats, and one for formatting ints.\nThe values for the digits, left, and right parameters should always\nbe positive integers.
\n",itemtype:"method",name:"nf",return:{description:"formatted String",type:"String"},class:"p5",module:"Data",submodule:"String Functions",overloads:[{line:132,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:"Number|String",optional:!0},{name:"right",description:"number of digits to the right of the\n decimal point
\n",type:"Number|String",optional:!0}],return:{description:"formatted String",type:"String"}},{line:146,params:[{name:"nums",description:"the Numbers to format
\n",type:"Array"},{name:"left",description:"",type:"Number|String",optional:!0},{name:"right",description:"",type:"Number|String",optional:!0}],return:{description:"formatted Strings\\",type:"Array"}}]},{file:"src/utilities/string_functions.js",line:245,description:"Utility function for formatting numbers into strings and placing\nappropriate commas to mark units of 1000. There are two versions: one\nfor formatting ints, and one for formatting an array of ints. The value\nfor the right parameter should always be a positive integer.
\n",itemtype:"method",name:"nfc",return:{description:"formatted String",type:"String"},class:"p5",module:"Data",submodule:"String Functions",overloads:[{line:245,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:"Number|String",optional:!0}],return:{description:"formatted String",type:"String"}},{line:257,params:[{name:"nums",description:"the Numbers to format
\n",type:"Array"},{name:"right",description:"",type:"Number|String",optional:!0}],return:{description:"formatted Strings",type:"Array"}}]},{file:"src/utilities/string_functions.js",line:324,description:"Utility function for formatting numbers into strings. Similar to nf() but\nputs a "+" in front of positive numbers and a "-" in front of negative\nnumbers. There are two versions: one for formatting floats, and one for\nformatting ints. The values for left, and right parameters\nshould always be positive integers.
\n",itemtype:"method",name:"nfp",return:{description:"formatted String",type:"String"},class:"p5",module:"Data",submodule:"String Functions",overloads:[{line:324,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:"Number",optional:!0},{name:"right",description:"number of digits to the right of the\n decimal point
\n",type:"Number",optional:!0}],return:{description:"formatted String",type:"String"}},{line:339,params:[{name:"nums",description:"the Numbers to format
\n",type:"Number[]"},{name:"left",description:"",type:"Number",optional:!0},{name:"right",description:"",type:"Number",optional:!0}],return:{description:"formatted Strings",type:"String[]"}}]},{file:"src/utilities/string_functions.js",line:389,description:"Utility function for formatting numbers into strings. Similar to nf() but\nputs a " " (space) in front of positive numbers and a "-" in front of\nnegative numbers. There are two versions: one for formatting floats, and\none for formatting ints. The values for the digits, left, and right\nparameters should always be positive integers.
\n",itemtype:"method",name:"nfs",return:{description:"formatted String",type:"String"},class:"p5",module:"Data",submodule:"String Functions",overloads:[{line:389,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:"Number",optional:!0},{name:"right",description:"number of digits to the right of the\n decimal point
\n",type:"Number",optional:!0}],return:{description:"formatted String",type:"String"}},{line:404,params:[{name:"nums",description:"the Numbers to format
\n",type:"Array"},{name:"left",description:"",type:"Number",optional:!0},{name:"right",description:"",type:"Number",optional:!0}],return:{description:"formatted Strings",type:"Array"}}]},{file:"src/utilities/string_functions.js",line:454,description:"The split() function maps to String.split(), it breaks a String into\npieces using a character or string as the delimiter. The delim parameter\nspecifies the character or characters that mark the boundaries between\neach piece. A String[] array is returned that contains each of the pieces.
\nThe splitTokens() function works in a similar fashion, except that it\nsplits using a range of characters instead of a specific character or\nsequence.
\n",itemtype:"method",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"}],return:{description:"Array of Strings",type:"String[]"},example:['\n\nvar names = "Pat,Xio,Alex"\nvar splitString = split(names, ",");\ntext(splitString[0], 5, 30);\ntext(splitString[1], 5, 50);\ntext(splitString[2], 5, 70);\n
\nThe splitTokens() function splits a String at one or many character\ndelimiters or "tokens." The delim parameter specifies the character or\ncharacters to be used as a boundary.\n
\nIf no delim characters are specified, any whitespace character is used to\nsplit. Whitespace characters include tab (\\t), line feed (\\n), carriage\nreturn (\\r), form feed (\\f), and space.
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:!0}],return:{description:"Array of Strings",type:"String[]"},example:['\n\nfunction setup() {\n var myStr = "Mango, Banana, Lime";\n var myStrArr = splitTokens(myStr, ",");\n\n print(myStrArr); // prints : ["Mango"," Banana"," Lime"]\n}\n
\nRemoves whitespace characters from the beginning and end of a String. In\naddition to standard whitespace characters such as space, carriage return,\nand tab, this function also removes the Unicode "nbsp" character.
\n",itemtype:"method",name:"trim",return:{description:"a trimmed String",type:"String"},class:"p5",module:"Data",submodule:"String Functions",overloads:[{line:541,params:[{name:"str",description:"a String to be trimmed
\n",type:"String"}],return:{description:"a trimmed String",type:"String"}},{line:550,params:[{name:"strs",description:"an Array of Strings to be trimmed
\n",type:"Array"}],return:{description:"an Array of trimmed Strings",type:"Array"}}]},{file:"src/utilities/time_date.js",line:12,description:"p5.js communicates with the clock on your computer. The day() function\nreturns the current day as a value from 1 - 31.
\n",itemtype:"method",name:"day",return:{description:"the current day",type:"Number"},example:['\n\nvar d = day();\ntext("Current day: \\n" + d, 5, 50);\n
\np5.js communicates with the clock on your computer. The hour() function\nreturns the current hour as a value from 0 - 23.
\n",itemtype:"method",name:"hour",return:{description:"the current hour",type:"Number"},example:['\n\nvar h = hour();\ntext("Current hour:\\n" + h, 5, 50);\n
\np5.js communicates with the clock on your computer. The minute() function\nreturns the current minute as a value from 0 - 59.
\n",itemtype:"method",name:"minute",return:{description:"the current minute",type:"Number"},example:['\n\nvar m = minute();\ntext("Current minute: \\n" + m, 5, 50);\n
\nReturns the number of milliseconds (thousandths of a second) since\nstarting the program. This information is often used for timing events and\nanimation sequences.
\n",itemtype:"method",name:"millis",return:{description:"the number of milliseconds since starting the program",type:"Number"},example:['\n\nvar millisecond = millis();\ntext("Milliseconds \\nrunning: \\n" + millisecond, 5, 40);\n
\np5.js communicates with the clock on your computer. The month() function\nreturns the current month as a value from 1 - 12.
\n",itemtype:"method",name:"month",return:{description:"the current month",type:"Number"},example:['\n\nvar m = month();\ntext("Current month: \\n" + m, 5, 50);\n
\np5.js communicates with the clock on your computer. The second() function\nreturns the current second as a value from 0 - 59.
\n",itemtype:"method",name:"second",return:{description:"the current second",type:"Number"},example:['\n\nvar s = second();\ntext("Current second: \\n" + s, 5, 50);\n
\np5.js communicates with the clock on your computer. The year() function\nreturns the current year as an integer (2014, 2015, 2016, etc).
\n",itemtype:"method",name:"year",return:{description:"the current year",type:"Number"},example:['\n\nvar y = year();\ntext("Current year: \\n" + y, 5, 50);\n
\nSets camera position for a 3D sketch. The function behaves similarly\ngluLookAt, except that it replaces the existing modelview matrix instead\nof applying any transformations calculated here on top of the existing\nmodel view.\nWhen called with no arguments, this function\nsets a default camera equivalent to calling\ncamera(0, 0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);
\n",itemtype:"method",name:"camera",params:[{name:"x",description:"camera position value on x axis
\n",type:"Number",optional:!0},{name:"y",description:"camera position value on y axis
\n",type:"Number",optional:!0},{name:"z",description:"camera position value on z axis
\n",type:"Number",optional:!0},{name:"centerX",description:"x coordinate representing center of the sketch
\n",type:"Number",optional:!0},{name:"centerY",description:"y coordinate representing center of the sketch
\n",type:"Number",optional:!0},{name:"centerZ",description:"z coordinate representing center of the sketch
\n",type:"Number",optional:!0},{name:"upX",description:"x component of direction 'up' from camera
\n",type:"Number",optional:!0},{name:"upY",description:"y component of direction 'up' from camera
\n",type:"Number",optional:!0},{name:"upZ",description:"z component of direction 'up' from camera
\n",type:"Number",optional:!0}],return:{description:"the p5 object",type:"P5"},example:["\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\nfunction draw(){\n //move the camera away from the plane by a sin wave\n camera(0, 0, sin(frameCount * 0.01) * 100, 0, 0, 0, 0, 1, 0);\n plane(120, 120);\n}\n
\nSets perspective camera. When called with no arguments, the defaults\nprovided are equivalent to\nperspective(PI/3.0, width/height, cameraZ/10.0, cameraZ10.0)\nwhere cameraZ is ((height/2.0) / tan(PI60.0/360.0));
\n",itemtype:"method",name:"perspective",params:[{name:"fovy",description:"camera frustum vertical field of view,\n from bottom to top of view, in degrees
\n",type:"Number",optional:!0},{name:"aspect",description:"camera frustum aspect ratio
\n",type:"Number",optional:!0},{name:"near",description:"frustum near plane length
\n",type:"Number",optional:!0},{name:"far",description:"frustum far plane length
\n",type:"Number",optional:!0}],return:{description:"the p5 object",type:"P5"},example:["\n\n//drag mouse to toggle the world!\n//you will see there's a vanish point\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n var fov = 60 / 180 * PI;\n var cameraZ = (height/2.0) / tan(fov/2.0);\n perspective(60 / 180 * PI, width/height, cameraZ * 0.1, cameraZ * 10);\n}\nfunction draw(){\n background(200);\n orbitControl();\n for(var i = -1; i < 2; i++){\n for(var j = -2; j < 3; j++){\n push();\n translate(i*160, 0, j*160);\n box(40, 40, 40);\n pop();\n }\n }\n}\n
\nSetup ortho camera
\n",itemtype:"method",name:"ortho",params:[{name:"left",description:"camera frustum left plane
\n",type:"Number"},{name:"right",description:"camera frustum right plane
\n",type:"Number"},{name:"bottom",description:"camera frustum bottom plane
\n",type:"Number"},{name:"top",description:"camera frustum top plane
\n",type:"Number"},{name:"near",description:"camera frustum near plane
\n",type:"Number"},{name:"far",description:"camera frustum far plane
\n",type:"Number"}],return:{description:"the p5 object",type:"P5"},example:["\n\n//drag mouse to toggle the world!\n//there's no vanish point\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n ortho(-width/2, width/2, height/2, -height/2, 0, 500);\n}\nfunction draw(){\n background(200);\n orbitControl();\n for(var i = -1; i < 2; i++){\n for(var j = -2; j < 3; j++){\n push();\n translate(i*160, 0, j*160);\n box(40, 40, 40);\n pop();\n }\n }\n}\n
\nCreates an ambient light with a color
\n",itemtype:"method",name:"ambientLight",chainable:1,class:"p5",module:"Lights, Camera",submodule:"Lights",overloads:[{line:12,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:!0}],chainable:1},{line:26,params:[{name:"value",description:"a color string
\n",type:"String"},{name:"alpha",description:"",type:"Number",optional:!0}],chainable:1},{line:33,params:[{name:"values",description:"an array containing the red,green,blue &\n and alpha components of the color
\n",type:"Number[]"}],chainable:1},{line:40,params:[{name:"color",description:"the ambient light color
\n",type:"p5.Color"},{name:"alpha",description:"",type:"Number",optional:!0}],chainable:1}]},{file:"src/webgl/light.js",line:89,description:"Creates a directional light with a color and a direction
\n",itemtype:"method",name:"directionalLight",params:[{name:"v1",description:"gray value,\nred or hue value (depending on the current color mode),\nor color Array, or CSS color string
\n",type:"Number|Array|String|p5.Color"},{name:"v2",description:"green or saturation value
\n",type:"Number",optional:!0},{name:"v3",description:"blue or brightness value
\n",type:"Number",optional:!0},{name:"a",description:"opacity
\n",type:"Number",optional:!0},{name:"x",description:"x axis direction or a p5.Vector
\n",type:"Number|p5.Vector"},{name:"y",description:"y axis direction
\n",type:"Number",optional:!0},{name:"z",description:"z axis direction
\n",type:"Number",optional:!0}],chainable:1,example:["\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\nfunction draw(){\n background(0);\n //move your mouse to change light direction\n var dirX = (mouseX / width - 0.5) *2;\n var dirY = (mouseY / height - 0.5) *(-2);\n directionalLight(250, 250, 250, dirX, dirY, 0.25);\n ambientMaterial(250);\n sphere(50);\n}\n
\nCreates a point light with a color and a light position
\n",itemtype:"method",name:"pointLight",params:[{name:"v1",description:"gray value,\nred or hue value (depending on the current color mode),\nor color Array, or CSS color string
\n",type:"Number|Array|String|p5.Color"},{name:"v2",description:"green or saturation value
\n",type:"Number",optional:!0},{name:"v3",description:"blue or brightness value
\n",type:"Number",optional:!0},{name:"a",description:"opacity
\n",type:"Number",optional:!0},{name:"x",description:"x axis position or a p5.Vector
\n",type:"Number|p5.Vector"},{name:"y",description:"y axis position
\n",type:"Number",optional:!0},{name:"z",description:"z axis position
\n",type:"Number",optional:!0}],chainable:1,example:["\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\nfunction draw(){\n background(0);\n //move your mouse to change light position\n var locY = (mouseY / height - 0.5) *(-2);\n var locX = (mouseX / width - 0.5) *2;\n //to set the light position,\n //think of the world's coordinate as:\n // -1,1 -------- 1,1\n // | |\n // | |\n // | |\n // -1,-1---------1,-1\n pointLight(250, 250, 250, locX, locY, 0);\n ambientMaterial(250);\n sphere(50);\n}\n
\nLoad a 3d model from an OBJ file.\n
\nOne of the limitations of the OBJ format is that it doesn't have a built-in\nsense of scale. This means that models exported from different programs might\nbe very different sizes. If your model isn't displaying, try calling\nloadModel() with the normalized parameter set to true. This will resize the\nmodel to a scale appropriate for p5. You can also make additional changes to\nthe final size of your model with the scale() function.
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:!0},{name:"failureCallback",description:"called with event error if\n the image fails to load.
\n",type:"Function(Event)",optional:!0}],return:{description:"the p5.Geometry object",type:"p5.Geometry"}},{line:35,params:[{name:"path",description:"",type:"String"},{name:"successCallback",description:"",type:"function(p5.Geometry)",optional:!0},{name:"failureCallback",description:"",type:"Function(Event)",optional:!0}],return:{description:"the p5.Geometry object",type:"p5.Geometry"}}]},{file:"src/webgl/loading.js",line:98,description:"Parse OBJ lines into model. For reference, this is what a simple model of a\nsquare might look like:
\nv -0.5 -0.5 0.5\nv -0.5 -0.5 -0.5\nv -0.5 0.5 -0.5\nv -0.5 0.5 0.5
\nf 4 3 2 1
\n",class:"p5",module:"Shape",submodule:"3D Models"},{file:"src/webgl/loading.js",line:197,description:"Render a 3d model to the screen.
\n",itemtype:"method",name:"model",params:[{name:"model",description:"Loaded 3d model to be rendered
\n",type:"p5.Geometry"}],example:["\n\n//draw a spinning teapot\nvar teapot;\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n\n teapot = loadModel('assets/teapot.obj');\n}\n\nfunction draw(){\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n model(teapot);\n}\n
\nLoads a custom shader from the provided vertex and fragment\nshader paths. The shader files are loaded asynchronously in the\nbackground, so this method should be used in preload().
\nFor now, there are three main types of shaders. p5 will automatically\nsupply appropriate vertices, normals, colors, and lighting attributes\nif the parameters defined in the shader match the names.
\n",itemtype:"method",name:"loadShader",params:[{name:"vertFilename",description:"path to file containing vertex shader\nsource code
\n",type:"String",optional:!0},{name:"fragFilename",description:"path to file containing fragment shader\nsource code
\n",type:"String",optional:!0}],return:{description:"a shader object created from the provided\nvertex and fragment shader files.",type:"p5.Shader"},class:"p5",module:"Lights, Camera",submodule:"Material"},{file:"src/webgl/material.js",line:58,description:"The shader() function lets the user provide a custom shader\nto fill in shapes in WEBGL mode. Users can create their\nown shaders by loading vertex and fragment shaders with\nloadShader().
\n",itemtype:"method",name:"shader",chainable:1,params:[{name:"s",description:"the desired p5.Shader to use for rendering\nshapes.
\n",type:"p5.Shader",optional:!0}],class:"p5",module:"Lights, Camera",submodule:"Material"},{file:"src/webgl/material.js",line:81,description:'Normal material for geometry. You can view all\npossible materials in this\nexample.
\n',itemtype:"method",name:"normalMaterial",chainable:1,example:["\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n normalMaterial();\n sphere(50);\n}\n
\nTexture for geometry. You can view other possible materials in this\nexample.
\n',itemtype:"method",name:"texture",params:[{name:"tex",description:"2-dimensional graphics\n to render as texture
\n",type:"p5.Image|p5.MediaElement|p5.Graphics"}],chainable:1,example:['\n\nvar img;\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n img = loadImage("assets/laDefense.jpg");\n}\n\nfunction draw(){\n background(0);\n rotateZ(frameCount * 0.01);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n //pass image as texture\n texture(img);\n box(200, 200, 200);\n}\n
\n\nvar pg;\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n pg = createGraphics(200, 200);\n pg.textSize(100);\n}\n\nfunction draw(){\n background(0);\n pg.background(255);\n pg.text(\'hello!\', 0, 100);\n //pass image as texture\n texture(pg);\n plane(200);\n}\n
\n\nvar vid;\nfunction preload(){\n vid = createVideo("assets/fingers.mov");\n vid.hide();\n vid.loop();\n}\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(0);\n //pass video frame as texture\n texture(vid);\n plane(200);\n}\n
\nAmbient material for geometry with a given color. You can view all\npossible materials in this\nexample.
\n',itemtype:"method",name:"ambientMaterial",params:[{name:"v1",description:"gray value,\nred or hue value (depending on the current color mode),\nor color Array, or CSS color string
\n",type:"Number|Array|String|p5.Color"},{name:"v2",description:"green or saturation value
\n",type:"Number",optional:!0},{name:"v3",description:"blue or brightness value
\n",type:"Number",optional:!0},{name:"a",description:"opacity
\n",type:"Number",optional:!0}],chainable:1,example:["\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\nfunction draw(){\n background(0);\n ambientLight(100);\n pointLight(250, 250, 250, 100, 100, 0);\n ambientMaterial(250);\n sphere(50);\n}\n
\nSpecular material for geometry with a given color. You can view all\npossible materials in this\nexample.
\n',itemtype:"method",name:"specularMaterial",params:[{name:"v1",description:"gray value,\nred or hue value (depending on the current color mode),\nor color Array, or CSS color string
\n",type:"Number|Array|String|p5.Color"},{name:"v2",description:"green or saturation value
\n",type:"Number",optional:!0},{name:"v3",description:"blue or brightness value
\n",type:"Number",optional:!0},{name:"a",description:"opacity
\n",type:"Number",optional:!0}],chainable:1,example:["\n\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\nfunction draw(){\n background(0);\n ambientLight(100);\n pointLight(250, 250, 250, 100, 100, 0);\n specularMaterial(250);\n sphere(50);\n}\n
\n[description]
\n",type:"Number"},{name:"v2",description:"[description]
\n",type:"Number"},{name:"v3",description:"[description]
\n",type:"Number"},{name:"a",description:"[description]
\n",type:"Number"}],return:{description:"Normalized numbers array",type:"[Number]"},class:"p5",module:"Lights, Camera",submodule:"Material"},{file:"src/webgl/p5.Geometry.js",line:86,description:"computes smooth normals per vertex as an average of each\nface.
\n",chainable:1,class:"p5.Geometry",module:"Lights, Camera"},{file:"src/webgl/p5.Geometry.js",line:111,description:"Averages the vertex normals. Used in curved\nsurfaces
\n",chainable:1,class:"p5.Geometry",module:"Lights, Camera"},{file:"src/webgl/p5.Geometry.js",line:130,description:"Averages pole normals. Used in spherical primitives
\n",chainable:1,class:"p5.Geometry",module:"Lights, Camera"},{file:"src/webgl/p5.Geometry.js",line:161,description:"Create a 2D array for establishing stroke connections
\n",return:{description:"",type:"p5.Geometry"},class:"p5.Geometry",module:"Lights, Camera"},{file:"src/webgl/p5.Geometry.js",line:182,description:"Create 4 vertices for each stroke line, two at the beginning position\nand two at the end position. These vertices are displaced relative to\nthat line's normal on the GPU
\n",return:{description:"",type:"p5.Geometry"},class:"p5.Geometry",module:"Lights, Camera"},{file:"src/webgl/p5.Geometry.js",line:209,description:"Modifies all vertices to be centered within the range -100 to 100.
\n",chainable:1,class:"p5.Geometry",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:1,requires:["constants"],todo:["see methods below needing further implementation.\nfuture consideration: implement SIMD optimizations\nwhen browser compatibility becomes available\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/\n Reference/Global_Objects/SIMD"],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:19,description:"A class to describe a 4x4 matrix\nfor model and view matrix manipulation in the p5js webgl renderer.\nclass p5.Matrix
\n",is_constructor:1,params:[{name:"mat4",description:"array literal of our 4x4 matrix
\n",type:"Array",optional:!0}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:75,description:"Sets the x, y, and z component of the vector using two or three separate\nvariables, the data from a p5.Matrix, or the values from a float array.
\n",params:[{name:"inMatrix",description:"the input p5.Matrix or\n an Array of length 16
\n",type:"p5.Matrix|Float32Array|Array",optional:!0},{name:"n00..n33",description:"16 numbers passed by value to avoid\n array copying.
\n",type:"Number",optional:!0}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:113,description:"Gets a copy of the vector, returns a p5.Matrix object.
\n",return:{description:"the copy of the p5.Matrix object",type:"p5.Matrix"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:122,description:"return a copy of a matrix
\n",return:{description:"the result matrix",type:"p5.Matrix"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:147,description:"return an identity matrix
\n",return:{description:"the result matrix",type:"p5.Matrix"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:155,description:"transpose according to a given matrix
\n",params:[{name:"a",description:"the matrix to be based on to transpose
\n",type:"p5.Matrix|Float32Array|Array"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:215,description:"invert matrix according to a give matrix
\n",params:[{name:"a",description:"the matrix to be based on to invert
\n",type:"p5.Matrix|Float32Array|Array"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:300,description:"Inverts a 3x3 matrix
\n",chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:336,description:"transposes a 3x3 p5.Matrix by a mat3
\n",params:[{name:"mat3",description:"1-dimensional array
\n",type:"[Number]"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:352,description:"converts a 4x4 matrix to its 3x3 inverse tranform\ncommonly used in MVMatrix to NMatrix conversions.
\n",params:[{name:"mat4",description:"the matrix to be based on to invert
\n",type:"p5.Matrix"}],chainable:1,todo:["finish implementation"],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:380,description:"inspired by Toji's mat4 determinant
\n",return:{description:"Determinant of our 4x4 matrix",type:"Number"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:403,description:"multiply two mat4s
\n",params:[{name:"multMatrix",description:"The matrix\n we want to multiply by
\n",type:"p5.Matrix|Float32Array|Array"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:460,description:"scales a p5.Matrix by scalars or a vector
\n",params:[{name:"s",description:"vector to scale by
\n",type:"p5.Vector|Float32Array|Array"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:505,description:"rotate our Matrix around an axis by the given angle.
\n",params:[{name:"a",description:"The angle of rotation in radians
\n",type:"Number"},{name:"axis",description:"the axis(es) to rotate around
\n",type:"p5.Vector|Array"}],chainable:"inspired by Toji's gl-matrix lib, mat4 rotation",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:584,todo:["finish implementing this method!\ntranslates"],params:[{name:"v",description:"vector to translate by
\n",type:"Number[]"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:614,description:"sets the perspective matrix
\n",params:[{name:"fovy",description:"[description]
\n",type:"Number"},{name:"aspect",description:"[description]
\n",type:"Number"},{name:"near",description:"near clipping plane
\n",type:"Number"},{name:"far",description:"far clipping plane
\n",type:"Number"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:648,description:"sets the ortho matrix
\n",params:[{name:"left",description:"[description]
\n",type:"Number"},{name:"right",description:"[description]
\n",type:"Number"},{name:"bottom",description:"[description]
\n",type:"Number"},{name:"top",description:"[description]
\n",type:"Number"},{name:"near",description:"near clipping plane
\n",type:"Number"},{name:"far",description:"far clipping plane
\n",type:"Number"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Matrix.js",line:683,description:"PRIVATE
\n",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Immediate.js",line:1,description:"Welcome to RendererGL Immediate Mode.\nImmediate mode is used for drawing custom shapes\nfrom a set of vertices. Immediate Mode is activated\nwhen you call beginShape() & de-activated when you call endShape().\nImmediate mode is a style of programming borrowed\nfrom OpenGL's (now-deprecated) immediate mode.\nIt differs from p5.js' default, Retained Mode, which caches\ngeometries and buffers on the CPU to reduce the number of webgl\ndraw calls. Retained mode is more efficient & performative,\nhowever, Immediate Mode is useful for sketching quick\ngeometric ideas.
\n",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Immediate.js",line:19,description:"Begin shape drawing. This is a helpful way of generating\ncustom shapes quickly. However in WEBGL mode, application\nperformance will likely drop as a result of too many calls to\nbeginShape() / endShape(). As a high performance alternative,\nplease use p5.js geometry primitives.
\n",params:[{name:"mode",description:"webgl primitives mode. beginShape supports the\n following modes:\n POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES,\n TRIANGLE_STRIP,and TRIANGLE_FAN.
\n",type:"Number"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Immediate.js",line:60,description:"adds a vertex to be drawn in a custom Shape.
\n",params:[{name:"x",description:"x-coordinate of vertex
\n",type:"Number"},{name:"y",description:"y-coordinate of vertex
\n",type:"Number"},{name:"z",description:"z-coordinate of vertex
\n",type:"Number"}],chainable:1,todo:["implement handling of p5.Vector args"],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Immediate.js",line:103,description:"End shape drawing and render vertices to screen.
\n",chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Retained.js",line:8,description:"initializes buffer defaults. runs each time a new geometry is\nregistered
\n",params:[{name:"gId",description:"key of the geometry object
\n",type:"String"}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Retained.js",line:33,description:"createBuffers description
\n",params:[{name:"gId",description:"key of the geometry object
\n",type:"String"},{name:"obj",description:"contains geometry data
\n",type:"p5.Geometry"}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.Retained.js",line:84,description:"Draws buffers given a geometry key ID
\n",params:[{name:"gId",description:"ID in our geom hash
\n",type:"String"}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:69,description:"model view, projection, & normal\nmatrices
\n",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:184,description:"Set attributes for the WebGL Drawing context.\n This is a way of adjusting ways that the WebGL\n renderer works to fine-tune the display and performance.\n This should be put in setup().\n The available attributes are:\n
\n alpha - indicates if the canvas contains an alpha buffer\n default is true\n
\n depth - indicates whether the drawing buffer has a depth buffer\n of at least 16 bits - default is true\n
\n stencil - indicates whether the drawing buffer has a stencil buffer\n of at least 8 bits\n
\n antialias - indicates whether or not to perform anti-aliasing\n default is false\n
\n premultipliedAlpha - indicates that the page compositor will assume\n the drawing buffer contains colors with pre-multiplied alpha\n default is false\n
\n preserveDrawingBuffer - if true the buffers will not be cleared and\n and will preserve their values until cleared or overwritten by author\n (note that p5 clears automatically on draw loop)\n default is true\n
\n function setup() {\n createCanvas(150,150,WEBGL);\n }\n function draw() {\n background(255);\n push();\n rotateZ(frameCount 0.02);\n rotateX(frameCount 0.02);\n rotateY(frameCount 0.02);\n fill(0,0,0);\n box(50);\n pop();\n }\n
\n \n function setup() {\n createCanvas(150,150,WEBGL);\n setAttributes('antialias', true);\n }\n function draw() {\n background(255);\n push();\n rotateZ(frameCount 0.02);\n rotateX(frameCount 0.02);\n rotateY(frameCount 0.02);\n fill(0,0,0);\n box(50);\n pop();\n }\n
\n name of attribute or object with key-value pairs
\n",type:"String|Object"},{name:"New",description:"value of named attribute
\n",type:"Boolean"}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:331,description:"[background description]
\n",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:352,description:"Basic fill material for geometry with a given color
\n",itemtype:"method",name:"fill",params:[{name:"v1",description:"gray value,\nred or hue value (depending on the current color mode),\nor color Array, or CSS color string
\n",type:"Number|Array|String|p5.Color"},{name:"v2",description:"green or saturation value
\n",type:"Number",optional:!0},{name:"v3",description:"blue or brightness value
\n",type:"Number",optional:!0},{name:"a",description:"opacity
\n",type:"Number",optional:!0}],return:{description:"the p5 object",type:"P5"},example:["\n\nfunction setup(){\n createCanvas(200, 200, WEBGL);\n}\n\nfunction draw(){\n background(0);\n noStroke();\n fill(100, 100, 240);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(75, 75, 75);\n}\n
\nDoes not render fill material
\n",itemtype:"method",name:"noFill",example:["\n\nfunction setup(){\n createCanvas(200, 200, WEBGL);\n}\n\nfunction draw(){\n background(0);\n noFill();\n stroke(100, 100, 240);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(75, 75, 75);\n}\n
\nDoes not render stroke
\n",itemtype:"method",name:"noStroke",example:["\n\nfunction setup(){\n createCanvas(200, 200, WEBGL);\n}\n\nfunction draw(){\n background(0);\n noStroke();\n fill(240, 150, 150);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(75, 75, 75);\n}\n
\nBasic stroke material for geometry with a given color
\n",itemtype:"method",name:"stroke",params:[{name:"v1",description:"gray value,\nred or hue value (depending on the current color mode),\nor color Array, or CSS color string
\n",type:"Number|Array|String|p5.Color"},{name:"v2",description:"green or saturation value
\n",type:"Number",optional:!0},{name:"v3",description:"blue or brightness value
\n",type:"Number",optional:!0},{name:"a",description:"opacity
\n",type:"Number",optional:!0}],example:["\n\nfunction setup(){\n createCanvas(200, 200, WEBGL);\n}\n\nfunction draw(){\n background(0);\n stroke(240, 150, 150);\n fill(100, 100, 240);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(75, 75, 75);\n}\n
\nChange weight of stroke
\n",itemtype:"method",name:"strokeWeight",params:[{name:"stroke",description:"weight to be used for drawing
\n",type:"Number"}],example:["\n\nfunction setup(){\n createCanvas(200, 400, WEBGL);\n setAttributes('antialias', true);\n}\n\nfunction draw(){\n background(0);\n noStroke();\n translate(0,-100,0);\n stroke(240,150,150);\n fill(100,100,240);\n push();\n strokeWeight(8);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n sphere(75);\n pop();\n push();\n translate(0,200,0);\n strokeWeight(1);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n sphere(75);\n pop();\n}\n\n
\nReturns an array of [R,G,B,A] values for any pixel or grabs a section of\nan image. If no parameters are specified, the entire image is returned.\nUse the x and y parameters to get the value of one pixel. Get a section of\nthe display window by specifying additional w and h parameters. When\ngetting an image, the x and y parameters define the coordinates for the\nupper-left corner of the image, regardless of the current imageMode().\n
\nIf the pixel requested is outside of the image window, [0,0,0,255] is\nreturned.\n
\nGetting the color of a single pixel with get(x, y) is easy, but not as fast\nas grabbing the data directly from pixels[]. The equivalent statement to\nget(x, y) is using pixels[] with pixel density d
x-coordinate of the pixel
\n",type:"Number",optional:!0},{name:"y",description:"y-coordinate of the pixel
\n",type:"Number",optional:!0},{name:"w",description:"width
\n",type:"Number",optional:!0},{name:"h",description:"height
\n",type:"Number",optional:!0}],return:{description:"color of pixel at x,y in array format\n [R, G, B, A] or p5.Image",type:"Array|Color|p5.Image"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:597,description:"Loads the pixels data for this canvas into the pixels[] attribute.\nNote that updatePixels() and set() do not work.\nAny pixel manipulation must be done directly to the pixels[] array.
\n",itemtype:"method",name:"loadPixels",params:[{name:"x",description:"starting pixel x position, defaults to 0
\n",type:"Number",optional:!0},{name:"y",description:"starting pixel y position, defaults to 0
\n",type:"Number",optional:!0},{name:"w",description:"width of pixels to load, defaults to sketch width
\n",type:"Number",optional:!0},{name:"h",description:"height of pixels to load, defaults to sketch height
\n",type:"Number",optional:!0}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:642,description:"[resize description]
\n",params:[{name:"w",description:"[description]
\n",type:"Number"},{name:"h",description:"[description]
\n",type:"Number"}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:659,description:"clears color and depth buffers\nwith r,g,b,a
\n",params:[{name:"r",description:"normalized red val.
\n",type:"Number"},{name:"g",description:"normalized green val.
\n",type:"Number"},{name:"b",description:"normalized blue val.
\n",type:"Number"},{name:"a",description:"normalized alpha val.
\n",type:"Number"}],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:675,description:"[translate description]
\n",params:[{name:"x",description:"[description]
\n",type:"Number"},{name:"y",description:"[description]
\n",type:"Number"},{name:"z",description:"[description]
\n",type:"Number"}],chainable:1,todo:["implement handle for components or vector as args"],class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:693,description:"Scales the Model View Matrix by a vector
\n",params:[{name:"x",description:"[description]
\n",type:"Number | p5.Vector | Array"},{name:"y",description:"y-axis scalar
\n",type:"Number",optional:!0},{name:"z",description:"z-axis scalar
\n",type:"Number",optional:!0}],chainable:1,class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:725,description:"pushes a copy of the model view matrix onto the\nMV Matrix stack.
\n",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:734,description:"[pop description]
\n",class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:904,description:"turn a two dimensional array into one dimensional array
\n",params:[{name:"arr",description:"2-dimensional array
\n",type:"Array"}],return:{description:"1-dimensional array\n[[1, 2, 3],[4, 5, 6]] -> [1, 2, 3, 4, 5, 6]",type:"Array"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.RendererGL.js",line:918,description:"turn a p5.Vector Array into a one dimensional number array
\n",params:[{name:"arr",description:"an array of p5.Vector
\n",type:"Array"}],return:{description:"a one dimensional array of numbers\n[p5.Vector(1, 2, 3), p5.Vector(4, 5, 6)] ->\n[1, 2, 3, 4, 5, 6]",type:"Array]"},class:"p5.RendererGL",module:"Lights, Camera"},{file:"src/webgl/p5.Shader.js",line:40,description:"Creates, compiles, and links the shader based on its\nsources for the vertex and fragment shaders (provided\nto the constructor). Populates known attributes and\nuniforms from the shader.
\n",itemtype:"method",name:"init",chainable:1,access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:98,description:"Queries the active attributes for this shader and loads\ntheir names and locations into the attributes array.
\n",itemtype:"method",name:"_loadAttributes",access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:130,description:"Queries the active uniforms for this shader and loads\ntheir names and locations into the uniforms array.
\n",itemtype:"method",name:"_loadUniforms",access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:179,description:"initializes (if needed) and binds the shader program.
\n",itemtype:"method",name:"bindShader",access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:202,itemtype:"method",name:"unbindShader",chainable:1,access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:253,itemtype:"method",name:"useProgram",chainable:1,access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:264,description:"Wrapper around gl.uniform functions.\nAs we store uniform info in the shader we can use that\nto do type checking on the supplied data and call\nthe appropriate function.
\n",itemtype:"method",name:"setUniform",chainable:1,params:[{name:"uniformName",description:"the name of the uniform in the\nshader program
\n",type:"String"},{name:"data",description:"the data to be associated with that uniform; type\nvaries (could be a single numerical value, array, matrix, or\ntexture / sampler reference)
\n",type:"Object"}],class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Shader.js",line:394,itemtype:"method",name:"enableAttrib",chainable:1,access:"private",tagname:"",class:"p5.Shader",module:"Lights, Camera",submodule:"Shaders"},{file:"src/webgl/p5.Texture.js",line:66,description:"Initializes common texture parameters, creates a gl texture,\ntries to upload the texture for the first time if data is\nalready available.
\n",access:"private",tagname:"",itemtype:"method",name:"init",class:"p5.Texture",module:"Lights, Camera",submodule:"Material"},{file:"src/webgl/p5.Texture.js",line:98,description:"Checks if the source data for this texture has changed (if it's\neasy to do so) and reuploads the texture if necessary. If it's not\npossible or to expensive to do a calculation to determine wheter or\nnot the data has occurred, this method simply re-uploads the texture.
\n",itemtype:"method",name:"update",class:"p5.Texture",module:"Lights, Camera",submodule:"Material"},{ file:"src/webgl/p5.Texture.js",line:185,description:"Binds the texture to the appropriate GL target.
\n",itemtype:"method",name:"bindTexture",class:"p5.Texture",module:"Lights, Camera",submodule:"Material"},{file:"src/webgl/p5.Texture.js",line:199,description:"Unbinds the texture from the appropriate GL target.
\n",itemtype:"method",name:"unbindTexture",class:"p5.Texture",module:"Lights, Camera",submodule:"Material"},{file:"src/webgl/primitives.js",line:13,description:"Draw a plane with given a width and height
\n",itemtype:"method",name:"plane",params:[{name:"width",description:"width of the plane
\n",type:"Number"},{name:"height",description:"height of the plane
\n",type:"Number"},{name:"detailX",description:"Optional number of triangle\n subdivisions in x-dimension
\n",type:"Number",optional:!0},{name:"detailY",description:"Optional number of triangle\n subdivisions in y-dimension
\n",type:"Number",optional:!0}],return:{description:"the p5 object",type:"P5"},example:["\n\n//draw a plane with width 200 and height 200\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n plane(50, 50);\n}\n
\nDraw a box with given width, height and depth
\n",itemtype:"method",name:"box",params:[{name:"width",description:"width of the box
\n",type:"Number"},{name:"Height",description:"height of the box
\n",type:"Number",optional:!0},{name:"depth",description:"depth of the box
\n",type:"Number",optional:!0},{name:"detailX",description:"Optional number of triangle\n subdivisions in x-dimension
\n",type:"Number",optional:!0},{name:"detailY",description:"Optional number of triangle\n subdivisions in y-dimension
\n",type:"Number",optional:!0}],chainable:1,example:["\n\n//draw a spinning box with width, height and depth 200\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(200, 200, 200);\n}\n
\nDraw a sphere with given radius
\n",itemtype:"method",name:"sphere",params:[{name:"radius",description:"radius of circle
\n",type:"Number"},{name:"detailX",description:"number of segments,\n the more segments the smoother geometry\n default is 24
\n",type:"Number",optional:!0},{name:"detailY",description:"number of segments,\n the more segments the smoother geometry\n default is 16
\n",type:"Number",optional:!0}],chainable:1,example:["\n\n// draw a sphere with radius 200\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n sphere(50);\n}\n
\nDraw a cylinder with given radius and height
\n",itemtype:"method",name:"cylinder",params:[{name:"radius",description:"radius of the surface
\n",type:"Number"},{name:"height",description:"height of the cylinder
\n",type:"Number"},{name:"detailX",description:"number of segments,\n the more segments the smoother geometry\n default is 24
\n",type:"Number",optional:!0},{name:"detailY",description:"number of segments in y-dimension,\n the more segments the smoother geometry\n default is 16
\n",type:"Number",optional:!0}],chainable:1,example:["\n\n//draw a spinning cylinder with radius 200 and height 200\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n rotateX(frameCount * 0.01);\n rotateZ(frameCount * 0.01);\n cylinder(200, 200);\n}\n
\nDraw a cone with given radius and height
\n",itemtype:"method",name:"cone",params:[{name:"radius",description:"radius of the bottom surface
\n",type:"Number"},{name:"height",description:"height of the cone
\n",type:"Number"},{name:"detailX",description:"number of segments,\n the more segments the smoother geometry\n default is 24
\n",type:"Number",optional:!0},{name:"detailY",description:"number of segments,\n the more segments the smoother geometry\n default is 16
\n",type:"Number",optional:!0}],chainable:1,example:["\n\n//draw a spinning cone with radius 200 and height 200\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n rotateX(frameCount * 0.01);\n rotateZ(frameCount * 0.01);\n cone(200, 200);\n}\n
\nDraw an ellipsoid with given radius
\n",itemtype:"method",name:"ellipsoid",params:[{name:"radiusx",description:"xradius of circle
\n",type:"Number"},{name:"radiusy",description:"yradius of circle
\n",type:"Number"},{name:"radiusz",description:"zradius of circle
\n",type:"Number"},{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:"Number",optional:!0},{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:"Number",optional:!0}],chainable:1,example:["\n\n// draw an ellipsoid with radius 20, 30 and 40.\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n ellipsoid(20, 30, 40);\n}\n
\nDraw a torus with given radius and tube radius
\n",itemtype:"method",name:"torus",params:[{name:"radius",description:"radius of the whole ring
\n",type:"Number"},{name:"tubeRadius",description:"radius of the tube
\n",type:"Number"},{name:"detailX",description:"number of segments in x-dimension,\n the more segments the smoother geometry\n default is 24
\n",type:"Number",optional:!0},{name:"detailY",description:"number of segments in y-dimension,\n the more segments the smoother geometry\n default is 16
\n",type:"Number",optional:!0}],chainable:1,example:["\n\n//draw a spinning torus with radius 200 and tube radius 60\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n torus(200, 60);\n}\n
\nDraw a line given two points
\n",params:[{name:"x0",description:"x-coordinate of first vertex
\n",type:"Number"},{name:"y0",description:"y-coordinate of first vertex
\n",type:"Number"},{name:"z0",description:"z-coordinate of first vertex
\n",type:"Number"},{name:"x1",description:"x-coordinate of second vertex
\n",type:"Number"},{name:"y1",description:"y-coordinate of second vertex
\n",type:"Number"},{name:"z1",description:"z-coordinate of second vertex
\n",type:"Number"}],chainable:1,example:["\n\n//draw a line\nfunction setup(){\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw(){\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n // Use fill instead of stroke to change the color of shape.\n fill(255, 0, 0);\n line(10, 10, 0, 60, 60, 20);\n}\n
\nSearches the page for an element with the given ID, class, or tag name (using the '#' or '.'\nprefixes to specify an ID or class respectively, and none for a tag) and returns it as\na p5.Element. If a class or tag name is given with more than 1 element,\nonly the first element will be returned.\nThe DOM node itself can be accessed with .elt.\nReturns null if none found. You can also specify a container to search within.
\n",itemtype:"method",name:"select",params:[{name:"name",description:"id, class, or tag name of element to search for
\n",type:"String"},{name:"container",description:"id, p5.Element, or HTML element to search within
\n",type:"String",optional:!0}],return:{description:"p5.Element containing node found",type:"Object|p5.Element|Null"},example:["\n\nfunction setup() {\n createCanvas(100,100);\n //translates canvas 50px down\n select('canvas').position(100, 100);\n}\n
\n// these are all valid calls to select()\nvar a = select('#moo');\nvar b = select('#blah', '#myContainer');\nvar c = select('#foo', b);\nvar d = document.getElementById('beep');\nvar e = select('p', d);\n
Searches the page for elements with the given class or tag name (using the '.' prefix\nto specify a class and no prefix for a tag) and returns them as p5.Elements\nin an array.\nThe DOM node itself can be accessed with .elt.\nReturns an empty array if none found.\nYou can also specify a container to search within.
\n",itemtype:"method",name:"selectAll",params:[{name:"name",description:"class or tag name of elements to search for
\n",type:"String"},{name:"container",description:"id, p5.Element, or HTML element to search within
\n",type:"String",optional:!0}],return:{description:"Array of p5.Elements containing nodes found",type:"Array"},example:["\n\nfunction setup() {\n createButton('btn');\n createButton('2nd btn');\n createButton('3rd btn');\n var buttons = selectAll('button');\n\n for (var i = 0; i < buttons.length; i++){\n buttons[i].size(100,100);\n }\n}\n
\n// these are all valid calls to selectAll()\nvar a = selectAll('.moo');\nvar b = selectAll('div');\nvar c = selectAll('button', '#myContainer');\nvar d = select('#container');\nvar e = selectAll('p', d);\nvar f = document.getElementById('beep');\nvar g = select('.blah', f);\n
Helper function for select and selectAll
\n",class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:172,description:"Helper function for getElement and getElements.
\n",class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:199,description:"Removes all elements created by p5, except any canvas / graphics\nelements created by createCanvas or createGraphics.\nEvent handlers are removed, and element is removed from the DOM.
\n",itemtype:"method",name:"removeElements",example:["\n\nfunction setup() {\n createCanvas(100, 100);\n createDiv('this is some text');\n createP('this is a paragraph');\n}\nfunction mousePressed() {\n removeElements(); // this will remove the div and p, not canvas\n}\n
Helpers for create methods.
\n",class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:236,description:"Creates a <div></div> element in the DOM with given inner HTML.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",name:"createDiv",params:[{name:"html",description:"inner HTML for element created
\n",type:"String",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar myDiv;\nfunction setup() {\n myDiv = createDiv('this is some text');\n}\n
Creates a <p></p> element in the DOM with given inner HTML. Used\nfor paragraph length text.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",name:"createP",params:[{name:"html",description:"inner HTML for element created
\n",type:"String",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar myP;\nfunction setup() {\n myP = createP('this is some text');\n}\n
Creates a <span></span> element in the DOM with given inner HTML.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",name:"createSpan",params:[{name:"html",description:"inner HTML for element created
\n",type:"String",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar mySpan;\nfunction setup() {\n mySpan = createSpan('this is some text');\n}\n
Creates an <img> element in the DOM with given src and\nalternate text.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",name:"createImg",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
\n",type:"String",optional:!0},{name:"successCallback",description:"callback to be called once image data is loaded
\n",type:"Function",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar img;\nfunction setup() {\n img = createImg('http://p5js.org/img/asterisk-01.png');\n}\n
Creates an <a></a> element in the DOM for including a hyperlink.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",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:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar myLink;\nfunction setup() {\n myLink = createA('http://p5js.org/', 'this is a link');\n}\n
Creates a slider <input></input> element in the DOM.\nUse .size() to set the display length of the slider.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",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:!0},{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:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar slider;\nfunction setup() {\n slider = createSlider(0, 255, 100);\n slider.position(10, 10);\n slider.style('width', '80px');\n}\n\nfunction draw() {\n var val = slider.value();\n background(val);\n}\n
\nvar slider;\nfunction setup() {\n colorMode(HSB);\n slider = createSlider(0, 360, 60, 40);\n slider.position(10, 10);\n slider.style('width', '80px');\n}\n\nfunction draw() {\n var val = slider.value();\n background(val, 100, 100, 1);\n}\n
Creates a <button></button> element in the DOM.\nUse .size() to set the display size of the button.\nUse .mousePressed() to specify behavior on press.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",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:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar button;\nfunction setup() {\n createCanvas(100, 100);\n background(0);\n button = createButton('click me');\n button.position(19, 19);\n button.mousePressed(changeBG);\n}\n\nfunction changeBG() {\n var val = random(255);\n background(val);\n}\n
Creates a checkbox <input></input> element in the DOM.\nCalling .checked() on a checkbox returns if it is checked or not
\n",itemtype:"method",name:"createCheckbox",params:[{name:"label",description:"label displayed after checkbox
\n",type:"String",optional:!0},{name:"value",description:"value of the checkbox; checked is true, unchecked is false.Unchecked if no value given
\n",type:"Boolean",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar checkbox;\n\nfunction setup() {\n checkbox = createCheckbox('label', false);\n checkbox.changed(myCheckedEvent);\n}\n\nfunction myCheckedEvent() {\n if (this.checked()) {\n console.log(\"Checking!\");\n } else {\n console.log(\"Unchecking!\");\n }\n}\n
Creates a dropdown menu <select></select> element in the DOM.\nIt also helps to assign select-box methods to p5.Element when selecting existing select box
\n",itemtype:"method",name:"createSelect",return:{description:"",type:"p5.Element"},example:["\n\nvar sel;\n\nfunction setup() {\n textAlign(CENTER);\n background(200);\n sel = createSelect();\n sel.position(10, 10);\n sel.option('pear');\n sel.option('kiwi');\n sel.option('grape');\n sel.changed(mySelectEvent);\n}\n\nfunction mySelectEvent() {\n var item = sel.value();\n background(200);\n text(\"it's a \"+item+\"!\", 50, 50);\n}\n
true if dropdown should support multiple selections
\n",type:"Boolean",optional:!0}],return:{description:"",type:"p5.Element"}},{line:556,params:[{name:"existing",description:"DOM select element
\n",type:"Object"}],return:{description:"",type:"p5.Element"}}]},{file:"lib/addons/p5.dom.js",line:633,description:"Creates a radio button <input></input> element in the DOM.\nThe .option() method can be used to set options for the radio after it is\ncreated. The .value() method will return the currently selected option.
\n",itemtype:"method",name:"createRadio",params:[{name:"divId",description:"the id and name of the created div and input field respectively
\n",type:"String",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar radio;\n\nfunction setup() {\n radio = createRadio();\n radio.option(\"black\");\n radio.option(\"white\");\n radio.option(\"gray\");\n radio.style('width', '60px');\n textAlign(CENTER);\n fill(255, 0, 0);\n}\n\nfunction draw() {\n var val = radio.value();\n background(val);\n text(val, width/2, height/2);\n}\n
\nvar radio;\n\nfunction setup() {\n radio = createRadio();\n radio.option('apple', 1);\n radio.option('bread', 2);\n radio.option('juice', 3);\n radio.style('width', '60px');\n textAlign(CENTER);\n}\n\nfunction draw() {\n background(200);\n var val = radio.value();\n if (val) {\n text('item cost is $'+val, width/2, height/2);\n }\n}\n
Creates an <input></input> element in the DOM for text input.\nUse .size() to set the display length of the box.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",name:"createInput",params:[{name:"value",description:"default value of the input box
\n",type:"Number",optional:!0},{name:"type",description:"type of text, ie text, password etc. Defaults to text
\n",type:"String",optional:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nfunction setup(){\n var inp = createInput('');\n inp.input(myInputEvent);\n}\n\nfunction myInputEvent(){\n console.log('you are typing: ', this.value());\n}\n\n
Creates an <input></input> element in the DOM of type 'file'.\nThis allows users to select local files for use in a sketch.
\n",itemtype:"method",name:"createFileInput",params:[{name:"callback",description:"callback function for when a file loaded
\n",type:"Function",optional:!0},{name:"multiple",description:"optional to allow multiple files selected
\n",type:"String",optional:!0}],return:{description:"pointer to p5.Element holding created DOM element",type:"Object|p5.Element"},example:["\nvar input;\nvar img;\n\nfunction setup() {\n input = createFileInput(handleFile);\n input.position(0, 0);\n}\n\nfunction draw() {\n if (img) {\n image(img, 0, 0, width, height);\n }\n}\n\nfunction handleFile(file) {\n print(file);\n if (file.type === 'image') {\n img = createImg(file.data);\n img.hide();\n }\n}"],class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:874,class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:911,description:'Creates an HTML5 <video> element in the DOM for simple playback\nof audio/video. Shown by default, can be hidden with .hide()\nand drawn into canvas using video(). Appends to the container\nnode if one is specified, otherwise appends to body. The first parameter\ncan be either a single string path to a video file, or an array of string\npaths to different formats of the same video. This is useful for ensuring\nthat your video can play across different browsers, as each supports\ndifferent formats. See this\npage for further information about supported formats.
\n',itemtype:"method",name:"createVideo",params:[{name:"src",description:"path to a video file, or array of paths for\n supporting different browsers
\n",type:"String|Array"},{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:"Object",optional:!0}],return:{description:"pointer to video p5.Element",type:"p5.MediaElement|p5.Element"},class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:937,class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:939,description:'Creates a hidden HTML5 <audio> element in the DOM for simple audio\nplayback. Appends to the container node if one is specified,\notherwise appends to body. The first parameter\ncan be either a single string path to a audio file, or an array of string\npaths to different formats of the same audio. This is useful for ensuring\nthat your audio can play across different browsers, as each supports\ndifferent formats. See this\npage for further information about supported formats.
\n',itemtype:"method",name:"createAudio",params:[{name:"src",description:"path to an audio file, or array of paths for\n supporting different browsers
\n",type:"String|Array"},{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:"Object",optional:!0}],return:{description:"pointer to audio p5.Element",type:"p5.MediaElement|p5.Element"},class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:965,class:"p5.dom",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:998,description:'Creates a new <video> element that contains the audio/video feed\nfrom a webcam. This can be drawn onto the canvas using video().
\nMore specific properties of the feed can be passing in a Constraints object.\nSee the\n W3C\nspec for possible properties. Note that not all of these are supported\nby all browsers.
\nSecurity note: A new browser security specification requires that getUserMedia,\nwhich is behind createCapture(), only works when you're running the code locally,\nor on HTTPS. Learn more here\nand here.
',itemtype:"method",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"}],return:{description:"capture video p5.Element",type:"Object|p5.Element"},example:["\n\nvar capture;\n\nfunction setup() {\n createCanvas(480, 120);\n capture = createCapture(VIDEO);\n}\n\nfunction draw() {\n image(capture, 0, 0, width, width*capture.height/capture.width);\n filter(INVERT);\n}\n
\nfunction setup() {\n createCanvas(480, 120);\n var constraints = {\n video: {\n mandatory: {\n minWidth: 1280,\n minHeight: 720\n },\n optional: [\n { maxFrameRate: 10 }\n ]\n },\n audio: true\n };\n createCapture(constraints, function(stream) {\n console.log(stream);\n });\n}\n
Creates element with given tag in the DOM with given content.\nAppends to the container node if one is specified, otherwise\nappends to body.
\n",itemtype:"method",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:!0}],return:{description:"pointer to p5.Element holding created node",type:"Object|p5.Element"},example:["\n\nvar h2 = createElement('h2','im an h2 p5.element!');\n
Adds specified class to the element.
\n",itemtype:"method",name:"addClass",params:[{name:"class",description:"name of class to add
\n",type:"String"}],return:{description:"",type:"Object|p5.Element"},example:["\n\n var div = createDiv('div');\n div.addClass('myClass');\n
Removes specified class from the element.
\n",itemtype:"method",name:"removeClass",params:[{name:"class",description:"name of class to remove
\n",type:"String"}],return:{description:"",type:"Object|p5.Element"},class:"p5.Element",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:1179,description:"Attaches the element as a child to the parent specified.\n Accepts either a string ID, DOM node, or p5.Element.\n If no argument is specified, an array of children DOM nodes is returned.
\n",itemtype:"method",name:"child",params:[{name:"child",description:"the ID, DOM node, or p5.Element\n to add to the current element
\n",type:"String|Object|p5.Element",optional:!0}],return:{description:"",type:"p5.Element"}, example:["\n\n var div0 = createDiv('this is the parent');\n var div1 = createDiv('this is the child');\n div0.child(div1); // use p5.Element\n
\n var div0 = createDiv('this is the parent');\n var div1 = createDiv('this is the child');\n div1.id('apples');\n div0.child('apples'); // use id\n
\n var div0 = createDiv('this is the parent');\n var elt = document.getElementById('myChildDiv');\n div0.child(elt); // use element from page\n
Centers a p5 Element either vertically, horizontally,\nor both, relative to its parent or according to\nthe body if the Element has no parent. If no argument is passed\nthe Element is aligned both vertically and horizontally.
\n",params:[{name:"align",description:"passing 'vertical', 'horizontal' aligns element accordingly
\n",type:"String"}],return:{description:"pointer to p5.Element",type:"Object|p5.Element"},example:["\n\nfunction setup() {\n var div = createDiv('').size(10,10);\n div.style('background-color','orange');\n div.center();\n\n}\n
If an argument is given, sets the inner HTML of the element,\n replacing any existing html. If true is included as a second\n argument, html is appended instead of replacing existing html.\n If no arguments are given, returns\n the inner HTML of the element.
\n",itemtype:"method",name:"html",params:[{name:"html",description:"the HTML to be placed inside the element
\n",type:"String",optional:!0},{name:"append",description:"whether to append HTML to existing
\n",type:"Boolean",optional:!0}],return:{description:"",type:"Object|p5.Element|String"},example:["\n\n var div = createDiv('').size(100,100);\n div.html('hi');\n
\n var div = createDiv('Hello ').size(100,100);\n div.html('World', true);\n
Sets the position of the element relative to (0, 0) of the\n window. Essentially, sets position:absolute and left and top\n properties of style. If no arguments given returns the x and y position\n of the element in an object.
\n",itemtype:"method",name:"position",params:[{name:"x",description:"x-position relative to upper left of window
\n",type:"Number",optional:!0},{name:"y",description:"y-position relative to upper left of window
\n",type:"Number",optional:!0}],return:{description:"",type:"Object|p5.Element"},example:["\n\n function setup() {\n var cnv = createCanvas(100, 100);\n // positions canvas 50px to the right and 100px\n // below upper left corner of the window\n cnv.position(50, 100);\n }\n
Sets the given style (css) property (1st arg) of the element with the\ngiven value (2nd arg). If a single argument is given, .style()\nreturns the value of the given property; however, if the single argument\nis given in css syntax ('text-align:center'), .style() sets the css\nappropriatly. .style() also handles 2d and 3d css transforms. If\nthe 1st arg is 'rotate', 'translate', or 'position', the following arguments\naccept Numbers as values. ('translate', 10, 100, 50);
\n",itemtype:"method",name:"style",params:[{name:"property",description:"property to be set
\n",type:"String"},{name:"value",description:"value to assign to property (only String|Number for rotate/translate)
\n",type:"String|Number|p5.Color",optional:!0}],return:{description:"value of property, if no value is specified\nor p5.Element",type:"String|Object|p5.Element"},example:['\n\nvar myDiv = createDiv("I like pandas.");\nmyDiv.style("font-size", "18px");\nmyDiv.style("color", "#ff0000");\n
\nvar col = color(25,23,200,50);\nvar button = createButton("button");\nbutton.style("background-color", col);\nbutton.position(10, 10);\n
\nvar myDiv = createDiv("I like lizards.");\nmyDiv.style("position", 20, 20);\nmyDiv.style("rotate", 45);\n
\nvar myDiv;\nfunction setup() {\n background(200);\n myDiv = createDiv("I like gray.");\n myDiv.position(20, 20);\n}\n\nfunction draw() {\n myDiv.style("font-size", mouseX+"px");\n}\n
Adds a new attribute or changes the value of an existing attribute\n on the specified element. If no value is specified, returns the\n value of the given attribute, or null if attribute is not set.
\n",itemtype:"method",name:"attribute",params:[{name:"attr",description:"attribute to set
\n",type:"String"},{name:"value",description:"value to assign to attribute
\n",type:"String",optional:!0}],return:{description:"value of attribute, if no value is\n specified or p5.Element",type:"String|Object|p5.Element"},example:['\n\n var myDiv = createDiv("I like pandas.");\n myDiv.attribute("align", "center");\n
Removes an attribute on the specified element.
\n",itemtype:"method",name:"removeAttribute",params:[{name:"attr",description:"attribute to remove
\n",type:"String"}],return:{description:"",type:"Object|p5.Element"},example:["\n\n var button;\n var checkbox;\nfunction setup() {\n checkbox = createCheckbox('enable', true);\n checkbox.changed(enableButton);\n button = createButton('button');\n button.position(10, 10);\n }\nfunction enableButton() {\n if( this.checked() ) {\n // Re-enable the button\n button.removeAttribute('disabled');\n } else {\n // Disable the button\n button.attribute('disabled','');\n }\n }\n
Either returns the value of the element if no arguments\ngiven, or sets the value of the element.
\n",itemtype:"method",name:"value",params:[{name:"value",description:"",type:"String|Number",optional:!0}],return:{description:"value of element if no value is specified or p5.Element",type:"String|Object|p5.Element"},example:["\n\n// gets the value\nvar inp;\nfunction setup() {\n inp = createInput('');\n}\n\nfunction mousePressed() {\n print(inp.value());\n}\n
\n// sets the value\nvar inp;\nfunction setup() {\n inp = createInput('myValue');\n}\n\nfunction mousePressed() {\n inp.value(\"myValue\");\n}\n
Shows the current element. Essentially, setting display:block for the style.
\n",itemtype:"method",name:"show",return:{description:"",type:"Object|p5.Element"},example:["\n\n var div = createDiv('div');\n div.style(\"display\", \"none\");\n div.show(); // turns display to block\n
Hides the current element. Essentially, setting display:none for the style.
\n",itemtype:"method",name:"hide",return:{description:"",type:"Object|p5.Element"},example:["\n\nvar div = createDiv('this is a div');\ndiv.hide();\n
Sets the width and height of the element. AUTO can be used to\n only adjust one dimension. If no arguments given returns the width and height\n of the element in an object.
\n",itemtype:"method",name:"size",params:[{name:"w",description:"width of the element
\n",type:"Number",optional:!0},{name:"h",description:"height of the element
\n",type:"Number",optional:!0}],return:{description:"",type:"Object|p5.Element"},example:["\n\n var div = createDiv('this is a div');\n div.size(100, 100);\n
Removes the element and deregisters all listeners.
\n",itemtype:"method",name:"remove",example:["\n\nvar myDiv = createDiv('this is some text');\nmyDiv.remove();\n
Path to the media element source.
\n",itemtype:"property",name:"src",return:{description:"src",type:"String"},example:["\n\nvar ele;\n\nfunction setup() {\n background(250);\n\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n\n //In this example we create\n //a new p5.MediaElement via createAudio().\n ele = createAudio('assets/beat.mp3');\n\n //We'll set up our example so that\n //when you click on the text,\n //an alert box displays the MediaElement's\n //src field.\n textAlign(CENTER);\n text(\"Click Me!\", width/2, height/2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if(mouseX >= 0 && mouseX <= width &&\n mouseY >= 0 && mouseY <= height) {\n //Show our p5.MediaElement's src field\n alert(ele.src);\n }\n}\n\n
Play an HTML5 media element.
\n",itemtype:"method",name:"play",return:{description:"",type:"Object|p5.Element"},example:['\n\nvar ele;\n\nfunction setup() {\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n\n //In this example we create\n //a new p5.MediaElement via createAudio().\n ele = createAudio(\'assets/beat.mp3\');\n\n background(250);\n textAlign(CENTER);\n text("Click to Play!", width/2, height/2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it\'s clicked\n if(mouseX >= 0 && mouseX <= width &&\n mouseY >= 0 && mouseY <= height) {\n\n //Here we call the play() function on\n //the p5.MediaElement we created above.\n //This will start the audio sample.\n ele.play();\n\n background(200);\n text("You clicked Play!", width/2, height/2);\n }\n}\n
Stops an HTML5 media element (sets current time to zero).
\n",itemtype:"method",name:"stop",return:{description:"",type:"Object|p5.Element"},example:['\n\n\n//This example both starts \n//and stops a sound sample\n//when the user clicks the canvas\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n\n//while our audio is playing,\n//this will be set to true\nvar sampleIsPlaying = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio(\'assets/beat.mp3\');\n background(200);\n textAlign(CENTER);\n text("Click to play!", width/2, height/2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it\'s clicked\n if(mouseX >= 0 && mouseX <= width &&\n mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if(sampleIsPlaying) {\n //if the sample is currently playing\n //calling the stop() function on\n //our p5.MediaElement will stop\n //it and reset its current\n //time to 0 (i.e. it will start\n //at the beginning the next time\n //you play it)\n ele.stop();\n\n sampleIsPlaying = false;\n text("Click to play!", width/2, height/2);\n } else {\n //loop our sound element until we\n //call ele.stop() on it.\n ele.loop(); \n\n sampleIsPlaying = true;\n text("Click to stop!", width/2, height/2);\n }\n }\n}\n\n
Pauses an HTML5 media element.
\n",itemtype:"method",name:"pause",return:{description:"",type:"Object|p5.Element"},example:['\n\n//This example both starts\n//and pauses a sound sample\n//when the user clicks the canvas\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n\n//while our audio is playing,\n//this will be set to true\nvar sampleIsPlaying = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio(\'assets/lucky_dragons_-_power_melody.mp3\');\n background(200);\n textAlign(CENTER);\n text("Click to play!", width/2, height/2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it\'s clicked\n if(mouseX >= 0 && mouseX <= width &&\n mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if(sampleIsPlaying) {\n //Calling pause() on our\n //p5.MediaElement will stop it\n //playing, but when we call the\n //loop() or play() functions\n //the sample will start from\n //where we paused it.\n ele.pause();\n\n sampleIsPlaying = false;\n text("Click to resume!", width/2, height/2);\n } else {\n //loop our sound element until we\n //call ele.pause() on it.\n ele.loop(); \n\n sampleIsPlaying = true;\n text("Click to pause!", width/2, height/2);\n }\n }\n}\n\n
Set 'loop' to true for an HTML5 media element, and starts playing.
\n",itemtype:"method",name:"loop",return:{description:"",type:"Object|p5.Element"},example:['\n\n//Clicking the canvas will loop\n//the audio sample until the user\n//clicks again to stop it\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n\n//while our audio is playing,\n//this will be set to true\nvar sampleIsLooping = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio(\'assets/lucky_dragons_-_power_melody.mp3\');\n background(200);\n textAlign(CENTER);\n text("Click to loop!", width/2, height/2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it\'s clicked\n if(mouseX >= 0 && mouseX <= width &&\n mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if(sampleIsLooping == false) {\n //loop our sound element until we\n //call ele.stop() on it.\n ele.loop();\n\n sampleIsLooping = true;\n text("Click to stop!", width/2, height/2);\n } else {\n ele.stop();\n\n sampleIsLooping = false;\n text("Click to loop!", width/2, height/2);\n }\n }\n}\n\n
Set 'loop' to false for an HTML5 media element. Element will stop\nwhen it reaches the end.
\n",itemtype:"method",name:"noLoop",return:{description:"",type:"Object|p5.Element"},class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2077,description:"Set HTML5 media element to autoplay or not.
\n",itemtype:"method",name:"autoplay",params:[{name:"autoplay",description:"whether the element should autoplay
\n",type:"Boolean"}],return:{description:"",type:"Object|p5.Element"},class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2089,description:"Sets volume for this HTML5 media element. If no argument is given,\nreturns the current volume.
\n",params:[{name:"val",description:"volume between 0.0 and 1.0
\n",type:"Number",optional:!0}],return:{description:"current volume or p5.MediaElement",type:"Number|p5.MediaElement"},itemtype:"method",name:"volume",class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2105,description:"If no arguments are given, returns the current playback speed of the\nelement. The speed parameter sets the speed where 2.0 will play the\nelement twice as fast, 0.5 will play at half the speed, and -1 will play\nthe element in normal speed in reverse.(Note that not all browsers support\nbackward playback and even if they do, playback might not be smooth.)
\n",itemtype:"method",name:"speed",params:[{name:"speed",description:"speed multiplier for element playback
\n",type:"Number",optional:!0}],return:{description:"current playback speed or p5.MediaElement",type:"Number|Object|p5.MediaElement"},class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2124,description:"If no arguments are given, returns the current time of the element.\nIf an argument is given the current time of the element is set to it.
\n",itemtype:"method",name:"time",params:[{name:"time",description:"time to jump to (in seconds)
\n",type:"Number",optional:!0}],return:{description:"current time (in seconds)\n or p5.MediaElement",type:"Number|Object|p5.MediaElement"},class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2141,description:"Returns the duration of the HTML5 media element.
\n",itemtype:"method",name:"duration",return:{description:"duration",type:"Number"},class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2201,description:"helper method for web GL mode to figure out if the element\nhas been modified and might need to be re-uploaded to texture\nmemory between frames.
\n",itemtype:"method",name:"isModified",access:"private",tagname:"",return:{description:"a boolean indicating whether or not the\nimage has been updated or modified since last texture upload.",type:"Boolean"},class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2213,description:"helper method for web GL mode to indicate that an element has been\nchanged or unchanged since last upload. gl texture upload will\nset this value to false after uploading the texture; or might set\nit to true if metadata has become available but there is no actual\ntexture data available yet..
\n",itemtype:"method",name:"setModified",params:[{name:"val",description:"sets whether or not the element has been\nmodified.
\n",type:"Boolean"}],access:"private",tagname:"",class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2227,description:"Schedule an event to be called when the audio or video\nelement reaches the end. If the element is looping,\nthis will not be called. The element is passed in\nas the argument to the onended callback.
\n",itemtype:"method",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"}],return:{description:"",type:"Object|p5.MediaElement"},example:["\n\nfunction setup() {\n audioEl = createAudio('assets/beat.mp3');\n audioEl.showControls(true);\n audioEl.onended(sayDone);\n}\n\nfunction sayDone(elt) {\n alert('done playing ' + elt.src );\n}\n
Send the audio output of this element to a specified audioNode or\np5.sound object. If no element is provided, connects to p5's master\noutput. That connection is established when this method is first called.\nAll connections are removed by the .disconnect() method.
\nThis method is meant to be used with the p5.sound.js addon library.
\n",itemtype:"method",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:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2313,description:"Disconnect all Web Audio routing, including to master output.\nThis is useful if you want to re-route the output through\naudio effects, for example.
\n",itemtype:"method",name:"disconnect",class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2329,class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2331,description:"Show the default MediaElement controls, as determined by the web browser.
\n",itemtype:"method",name:"showControls",class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2342,description:"Hide the default mediaElement controls.
\n",itemtype:"method",name:"hideControls",class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2351,class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2353,description:"Schedule events to trigger every time a MediaElement\n(audio/video) reaches a playback cue point.
\nAccepts a callback function, a time (in seconds) at which to trigger\nthe callback, and an optional parameter for the callback.
\nTime will be passed as the first parameter to the callback function,\nand param will be the second parameter.
\n",itemtype:"method",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:!0}],return:{description:"id ID of this cue,\n useful for removeCue(id)",type:"Number"},example:["\n\nfunction setup() {\n background(255,255,255);\n\n audioEl = createAudio('assets/beat.mp3');\n audioEl.showControls();\n\n // schedule three calls to changeBackground\n audioEl.addCue(0.5, changeBackground, color(255,0,0) );\n audioEl.addCue(1.0, changeBackground, color(0,255,0) );\n audioEl.addCue(2.5, changeBackground, color(0,0,255) );\n audioEl.addCue(3.0, changeBackground, color(0,255,255) );\n audioEl.addCue(4.2, changeBackground, color(255,255,0) );\n audioEl.addCue(5.0, changeBackground, color(255,255,0) );\n}\n\nfunction changeBackground(val) {\n background(val);\n}\n
Remove a callback based on its ID. The ID is returned by the\naddCue method.
\n",itemtype:"method",name:"removeCue",params:[{name:"id",description:"ID of the cue, as returned by addCue
\n",type:"Number"}],class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2435,description:"Remove all of the callbacks that had originally been scheduled\nvia the addCue method.
\n",itemtype:"method",name:"clearCues",class:"p5.MediaElement",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2491,description:"Underlying File object. All normal File methods can be called on this.
\n",itemtype:"property",name:"file",class:"p5.File",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2503,description:"File type (image, text, etc.)
\n",itemtype:"property",name:"type",class:"p5.File",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2509,description:"File subtype (usually the file extension jpg, png, xml, etc.)
\n",itemtype:"property",name:"subtype",class:"p5.File",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2515,description:"File name
\n",itemtype:"property",name:"name",class:"p5.File",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2521,description:"File size
\n",itemtype:"property",name:"size",class:"p5.File",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.dom.js",line:2528,description:"URL string containing image data.
\n",itemtype:"property",name:"data",class:"p5.File",module:"p5.dom",submodule:"p5.dom"},{file:"lib/addons/p5.sound.js",line:46,description:'p5.sound \nhttps://p5js.org/reference/#/libraries/p5.sound
\nFrom the Processing Foundation and contributors\nhttps://github.com/processing/p5.js-sound/graphs/contributors
\nMIT License (MIT)\nhttps://github.com/processing/p5.js-sound/blob/master/LICENSE
\nSome of the many audio libraries & resources that inspire p5.sound:
\nWilm Thoben's Sound library for Processing https://github.com/processing/processing/tree/master/java/libraries/sound
\nWeb Audio API: http://w3.org/TR/webaudio/
\nReturns the Audio Context for this sketch. Useful for users\nwho would like to dig deeper into the Web Audio API\n.
",itemtype:"method",name:"getAudioContext",return:{description:"AudioContext for this sketch",type:"Object"},class:"p5.sound",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:226,description:"Determine which filetypes are supported (inspired by buzz.js)\nThe audio element (el) will only be used to test browser support for various audio formats
\n",class:"p5.sound",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:296,description:"Master contains AudioContext and the master sound output.
\n",class:"p5.sound",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:331,description:"Returns a number representing the master amplitude (volume) for sound\nin this sketch.
\n",itemtype:"method",name:"getMasterVolume",return:{description:"Master amplitude (volume) for sound in this sketch.\n Should be between 0.0 (silence) and 1.0.",type:"Number"},class:"p5.sound",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:342,description:"Scale the output of all sound in this sketch
\nScaled between 0.0 (silence) and 1.0 (full volume).\n1.0 is the maximum amplitude of a digital sound, so multiplying\nby greater than 1.0 may cause digital distortion. To\nfade, provide arampTime
parameter. For more\ncomplex fades, see the Env class.\n\nAlternately, you can pass in a signal source such as an\noscillator to modulate the amplitude with an audio signal.\n\nHow This Works: When you load the p5.sound module, it\ncreates a single instance of p5sound. All sound objects in this\nmodule output to p5sound before reaching your computer's output.\nSo if you change the amplitude of p5sound, it impacts all of the\nsound in this module.
\n\nIf no value is provided, returns a Web Audio API Gain Node
",itemtype:"method",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:!0},{name:"timeFromNow",description:"Schedule this event to happen at\n t seconds in the future
\n",type:"Number",optional:!0}],class:"p5.sound",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:384,description:"p5.soundOut
is the p5.sound master output. It sends output to\nthe destination of this window's web audio context. It contains\nWeb Audio API nodes including a dyanmicsCompressor (.limiter
),\nand Gain Nodes for .input
and .output
.
a silent connection to the DesinationNode\nwhich will ensure that anything connected to it\nwill not be garbage collected
\n",access:"private",tagname:"",class:"p5.sound",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:412,description:"Returns a number representing the sample rate, in samples per second,\nof all sound objects in this audio context. It is determined by the\nsampling rate of your operating system's sound card, and it is not\ncurrently possile to change.\nIt is often 44100, or twice the range of human hearing.
\n",itemtype:"method",name:"sampleRate",return:{description:"samplerate samples per second",type:"Number"},class:"p5",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:425,description:"Returns the closest MIDI note value for\na given frequency.
\n",params:[{name:"frequency",description:"A freqeuncy, for example, the "A"\n above Middle C is 440Hz
\n",type:"Number"}],return:{description:"MIDI note value",type:"Number"},class:"p5",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:438, description:"Returns the frequency value of a MIDI note value.\nGeneral MIDI treats notes as integers where middle C\nis 60, C# is 61, D is 62 etc. Useful for generating\nmusical frequencies with oscillators.
\n",itemtype:"method",name:"midiToFreq",params:[{name:"midiNote",description:"The number of a MIDI note
\n",type:"Number"}],return:{description:"Frequency value of the given MIDI note",type:"Number"},example:["\n\nvar notes = [60, 64, 67, 72];\nvar i = 0;\n\nfunction setup() {\n osc = new p5.Oscillator('Triangle');\n osc.start();\n frameRate(1);\n}\n\nfunction draw() {\n var freq = midiToFreq(notes[i]);\n osc.freq(freq);\n i++;\n if (i >= notes.length){\n i = 0;\n }\n}\n
List the SoundFile formats that you will include. LoadSound\nwill search your directory for these extensions, and will pick\na format that is compatable with the client's web browser.\nHere is a free online file\nconverter.
\n',itemtype:"method",name:"soundFormats",params:[{name:"formats",description:"i.e. 'mp3', 'wav', 'ogg'
\n",type:"String",optional:!0,multiple:!0}],example:["\n\nfunction preload() {\n // set the global sound formats\n soundFormats('mp3', 'ogg');\n\n // load either beatbox.mp3, or .ogg, depending on browser\n mySound = loadSound('assets/beatbox.mp3');\n}\n\nfunction setup() {\n mySound.play();\n}\n
Used by Osc and Env to chain signal math
\n",class:"p5",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:869,description:'loadSound() returns a new p5.SoundFile from a specified\npath. If called during preload(), the p5.SoundFile will be ready\nto play in time for setup() and draw(). If called outside of\npreload, the p5.SoundFile will not be ready immediately, so\nloadSound accepts a callback as the second parameter. Using a\n\nlocal server is recommended when loading external files.
\n',itemtype:"method",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:!0},{name:"errorCallback",description:"Name of a function to call if there is\n an error loading the file.
\n",type:"Function",optional:!0},{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:!0}],return:{description:"Returns a p5.SoundFile",type:"SoundFile"},example:["\n\nfunction preload() {\n mySound = loadSound('assets/doorbell.mp3');\n}\n\nfunction setup() {\n mySound.setVolume(0.1);\n mySound.play();\n}\n
This is a helper function that the p5.SoundFile calls to load\nitself. Accepts a callback (the name of another function)\nas an optional parameter.
\n",access:"private",tagname:"",params:[{name:"successCallback",description:"Name of a function to call once file loads
\n",type:"Function",optional:!0},{name:"errorCallback",description:"Name of a function to call if there is an error
\n",type:"Function",optional:!0}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1009,description:"Returns true if the sound file finished loading successfully.
\n",itemtype:"method",name:"isLoaded",return:{description:"",type:"Boolean"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1022,description:"Play the p5.SoundFile
\n",itemtype:"method",name:"play",params:[{name:"startTime",description:"(optional) schedule playback to start (in seconds from now).
\n",type:"Number",optional:!0},{name:"rate",description:"(optional) playback rate
\n",type:"Number",optional:!0},{name:"amp",description:"(optional) amplitude (volume)\n of playback
\n",type:"Number",optional:!0},{name:"cueStart",description:"(optional) cue start time in seconds
\n",type:"Number",optional:!0},{name:"duration",description:"(optional) duration of playback in seconds
\n",type:"Number",optional:!0}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1119,description:"p5.SoundFile has two play modes: restart
and\nsustain
. Play Mode determines what happens to a\np5.SoundFile if it is triggered while in the middle of playback.\nIn sustain mode, playback will continue simultaneous to the\nnew playback. In restart mode, play() will stop playback\nand start over. Sustain is the default mode.
'restart' or 'sustain'
\n",type:"String"}],example:["\n\nfunction setup(){\n mySound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\nfunction mouseClicked() {\n mySound.playMode('sustain');\n mySound.play();\n}\nfunction keyPressed() {\n mySound.playMode('restart');\n mySound.play();\n}\n\n
Pauses a file that is currently playing. If the file is not\nplaying, then nothing will happen.
\nAfter pausing, .play() will resume from the paused\nposition.\nIf p5.SoundFile had been set to loop before it was paused,\nit will continue to loop after it is unpaused with .play().
\n",itemtype:"method",name:"pause",params:[{name:"startTime",description:"(optional) schedule event to occur\n seconds from now
\n",type:"Number",optional:!0}],example:["\n\nvar soundFile;\n\nfunction preload() {\n soundFormats('ogg', 'mp3');\n soundFile = loadSound('assets/Damscray_-_Dancing_Tiger_02.mp3');\n}\nfunction setup() {\n background(0, 255, 0);\n soundFile.setVolume(0.1);\n soundFile.loop();\n}\nfunction keyTyped() {\n if (key == 'p') {\n soundFile.pause();\n background(255, 0, 0);\n }\n}\n\nfunction keyReleased() {\n if (key == 'p') {\n soundFile.play();\n background(0, 255, 0);\n }\n}\n
\nLoop the p5.SoundFile. Accepts optional parameters to set the\nplayback rate, playback volume, loopStart, loopEnd.
\n",itemtype:"method",name:"loop",params:[{name:"startTime",description:"(optional) schedule event to occur\n seconds from now
\n",type:"Number",optional:!0},{name:"rate",description:"(optional) playback rate
\n",type:"Number",optional:!0},{name:"amp",description:"(optional) playback volume
\n",type:"Number",optional:!0},{name:"cueLoopStart",description:"(optional) startTime in seconds
\n",type:"Number",optional:!0},{name:"duration",description:"(optional) loop duration in seconds
\n",type:"Number",optional:!0}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1233,description:"Set a p5.SoundFile's looping flag to true or false. If the sound\nis currently playing, this change will take effect when it\nreaches the end of the current playback.
\n",params:[{name:"Boolean",description:"set looping to true or false
\n",type:"Boolean"}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1253,description:"Returns 'true' if a p5.SoundFile is currently looping and playing, 'false' if not.
\n",return:{description:"",type:"Boolean"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1267,description:"Returns true if a p5.SoundFile is playing, false if not (i.e.\npaused or stopped).
\n",itemtype:"method",name:"isPlaying",return:{description:"",type:"Boolean"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1277,description:"Returns true if a p5.SoundFile is paused, false if not (i.e.\nplaying or stopped).
\n",itemtype:"method",name:"isPaused",return:{description:"",type:"Boolean"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1287,description:"Stop soundfile playback.
\n",itemtype:"method",name:"stop",params:[{name:"startTime",description:"(optional) schedule event to occur\n in seconds from now
\n",type:"Number",optional:!0}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1311,description:"Stop playback on all of this soundfile's sources.
\n",access:"private",tagname:"",class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1333,description:"Multiply the output volume (amplitude) of a sound file\nbetween 0.0 (silence) and 1.0 (full volume).\n1.0 is the maximum amplitude of a digital sound, so multiplying\nby greater than 1.0 may cause digital distortion. To\nfade, provide a rampTime
parameter. For more\ncomplex fades, see the Env class.
Alternately, you can pass in a signal source such as an\noscillator to modulate the amplitude with an audio signal.
\n",itemtype:"method",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:!0},{name:"timeFromNow",description:"Schedule this event to happen at\n t seconds in the future
\n",type:"Number",optional:!0}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1374,description:"Set the stereo panning of a p5.sound object to\na floating point number between -1.0 (left) and 1.0 (right).\nDefault is 0.0 (center).
\n",itemtype:"method",name:"pan",params:[{name:"panValue",description:"Set the stereo panner
\n",type:"Number",optional:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],example:["\n\n\n var ball = {};\n var soundFile;\n\n function setup() {\n soundFormats('ogg', 'mp3');\n soundFile = loadSound('assets/beatbox.mp3');\n }\n\n function draw() {\n background(0);\n ball.x = constrain(mouseX, 0, width);\n ellipse(ball.x, height/2, 20, 20)\n }\n\n function mousePressed(){\n // map the ball's x location to a panning degree\n // between -1.0 (left) and 1.0 (right)\n var panning = map(ball.x, 0., width,-1.0, 1.0);\n soundFile.pan(panning);\n soundFile.play();\n }\n
Returns the current stereo pan position (-1.0 to 1.0)
\n",return:{description:"Returns the stereo pan setting of the Oscillator\n as a number between -1.0 (left) and 1.0 (right).\n 0.0 is center and default.",type:"Number"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1423,description:"Set the playback rate of a sound file. Will change the speed and the pitch.\nValues less than zero will reverse the audio buffer.
\n",itemtype:"method",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:!0}],example:["\n\nvar song;\n\nfunction preload() {\n song = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n song.loop();\n}\n\nfunction draw() {\n background(200);\n\n // Set the rate to a range between 0.1 and 4\n // Changing the rate also alters the pitch\n var speed = map(mouseY, 0.1, height, 0, 2);\n speed = constrain(speed, 0.01, 4);\n song.rate(speed);\n\n // Draw a circle to show what is going on\n stroke(0);\n fill(51, 100);\n ellipse(mouseX, 100, 48, 48);\n}\n\n
\n Returns the duration of a sound file in seconds.
\n",itemtype:"method",name:"duration",return:{description:"The duration of the soundFile in seconds.",type:"Number"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1509,description:"Return the current position of the p5.SoundFile playhead, in seconds.\nNote that if you change the playbackRate while the p5.SoundFile is\nplaying, the results may not be accurate.
\n",itemtype:"method",name:"currentTime",return:{description:"currentTime of the soundFile in seconds.",type:"Number"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1525,description:"Move the playhead of the song to a position, in seconds. Start timing\nand playback duration. If none are given, will reset the file to play\nentire duration from start to finish.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1548,description:"Return the number of channels in a sound file.\nFor example, Mono = 1, Stereo = 2.
\n",itemtype:"method",name:"channels",return:{description:"[channels]",type:"Number"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1558,description:"Return the sample rate of the sound file.
\n",itemtype:"method",name:"sampleRate",return:{description:"[sampleRate]",type:"Number"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1567,description:"Return the number of samples in a sound file.\nEqual to sampleRate * duration.
\n",itemtype:"method",name:"frames",return:{description:"[sampleCount]",type:"Number"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1577,description:"Returns an array of amplitude peaks in a p5.SoundFile that can be\nused to draw a static waveform. Scans through the p5.SoundFile's\naudio buffer to find the greatest amplitudes. Accepts one\nparameter, 'length', which determines size of the array.\nLarger arrays result in more precise waveform visualizations.
\nInspired by Wavesurfer.js.
\n",itemtype:"method",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:!0}],return:{description:"Array of peaks.",type:"Float32Array"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1629,description:"Reverses the p5.SoundFile's buffer source.\nPlayback must be handled separately (see example).
\n",itemtype:"method",name:"reverseBuffer",example:["\n\nvar drum;\n\nfunction preload() {\n drum = loadSound('assets/drum.mp3');\n}\n\nfunction setup() {\n drum.reverseBuffer();\n drum.play();\n}\n\n
\n Schedule an event to be called when the soundfile\nreaches the end of a buffer. If the soundfile is\nplaying through once, this will be called when it\nends. If it is looping, it will be called when\nstop is called.
\n",itemtype:"method",name:"onended",params:[{name:"callback",description:"function to call when the\n soundfile has ended.
\n",type:"Function"}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1717,description:"Connects the output of a p5sound object to input of another\np5.sound object. For example, you may connect a p5.SoundFile to an\nFFT or an Effect. If no parameter is given, it will connect to\nthe master output. Most p5sound objects connect to the master\noutput when they are created.
\n",itemtype:"method",name:"connect",params:[{name:"object",description:"Audio object that accepts an input
\n",type:"Object",optional:!0}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1738,description:"Disconnects the output of this p5sound object.
\n",itemtype:"method",name:"disconnect",class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1746,class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1751,description:"Reset the source for this SoundFile to a\nnew path (URL).
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1764,description:"Replace the current Audio Buffer with a new Buffer.
\n",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:1835,description:"processPeaks returns an array of timestamps where it thinks there is a beat.
\nThis is an asynchronous function that processes the soundfile in an offline audio context,\nand sends the results to your callback function.
\nThe process involves running the soundfile through a lowpass filter, and finding all of the\npeaks above the initial threshold. If the total number of peaks are below the minimum number of peaks,\nit decreases the threshold and re-runs the analysis until either minPeaks or minThreshold are reached.
\n",itemtype:"method",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:!0},{name:"minThreshold",description:"minimum threshold defaults to 0.22
\n",type:"Number",optional:!0},{name:"minPeaks",description:"minimum number of peaks defaults to 200
\n",type:"Number",optional:!0}],return:{description:"Array of timestamped peaks",type:"Array"},class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2026,class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2035,description:"Schedule events to trigger every time a MediaElement\n(audio/video) reaches a playback cue point.
\nAccepts a callback function, a time (in seconds) at which to trigger\nthe callback, and an optional parameter for the callback.
\nTime will be passed as the first parameter to the callback function,\nand param will be the second parameter.
\n",itemtype:"method",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:!0}],return:{description:"id ID of this cue,\n useful for removeCue(id)",type:"Number"},example:['\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n text(\'click to play\', width/2, height/2);\n\n mySound = loadSound(\'assets/beat.mp3\');\n\n // schedule calls to changeText\n mySound.addCue(0.50, changeText, "hello" );\n mySound.addCue(1.00, changeText, "p5" );\n mySound.addCue(1.50, changeText, "what" );\n mySound.addCue(2.00, changeText, "do" );\n mySound.addCue(2.50, changeText, "you" );\n mySound.addCue(3.00, changeText, "want" );\n mySound.addCue(4.00, changeText, "to" );\n mySound.addCue(5.00, changeText, "make" );\n mySound.addCue(6.00, changeText, "?" );\n}\n\nfunction changeText(val) {\n background(0);\n text(val, width/2, height/2);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n if (mySound.isPlaying() ) {\n mySound.stop();\n } else {\n mySound.play();\n }\n }\n}\n
Remove a callback based on its ID. The ID is returned by the\naddCue method.
\n",itemtype:"method",name:"removeCue",params:[{name:"id",description:"ID of the cue, as returned by addCue
\n",type:"Number"}],class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2128,description:"Remove all of the callbacks that had originally been scheduled\nvia the addCue method.
\n",itemtype:"method",name:"clearCues",class:"p5.SoundFile",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2236,description:"Connects to the p5sound instance (master output) by default.\nOptionally, you can pass in a specific source (i.e. a soundfile).
\n",itemtype:"method",name:"setInput",params:[{name:"snd",description:"set the sound source\n (optional, defaults to\n master output)
\n",type:"SoundObject|undefined",optional:!0},{name:"smoothing",description:"a range between 0.0 and 1.0\n to smooth amplitude readings
\n",type:"Number|undefined",optional:!0}],example:["\n\nfunction preload(){\n sound1 = loadSound('assets/beat.mp3');\n sound2 = loadSound('assets/drum.mp3');\n}\nfunction setup(){\n amplitude = new p5.Amplitude();\n sound1.play();\n sound2.play();\n amplitude.setInput(sound2);\n}\nfunction draw() {\n background(0);\n fill(255);\n var level = amplitude.getLevel();\n var size = map(level, 0, 1, 0, 200);\n ellipse(width/2, height/2, size, size);\n}\nfunction mouseClicked(){\n sound1.stop();\n sound2.stop();\n}\n
Returns a single Amplitude reading at the moment it is called.\nFor continuous readings, run in the draw loop.
\n",itemtype:"method",name:"getLevel",params:[{name:"channel",description:"Optionally return only channel 0 (left) or 1 (right)
\n",type:"Number",optional:!0}],return:{description:"Amplitude as a number between 0.0 and 1.0",type:"Number"},example:["\n\nfunction preload(){\n sound = loadSound('assets/beat.mp3');\n}\nfunction setup() {\n amplitude = new p5.Amplitude();\n sound.play();\n}\nfunction draw() {\n background(0);\n fill(255);\n var level = amplitude.getLevel();\n var size = map(level, 0, 1, 0, 200);\n ellipse(width/2, height/2, size, size);\n}\nfunction mouseClicked(){\n sound.stop();\n}\n
Determines whether the results of Amplitude.process() will be\nNormalized. To normalize, Amplitude finds the difference the\nloudest reading it has processed and the maximum amplitude of\n1.0. Amplitude adds this difference to all values to produce\nresults that will reliably map between 0.0 and 1.0. However,\nif a louder moment occurs, the amount that Normalize adds to\nall the values will change. Accepts an optional boolean parameter\n(true or false). Normalizing is off by default.
\n",itemtype:"method",name:"toggleNormalize",params:[{name:"boolean",description:"set normalize to true (1) or false (0)
\n",type:"Boolean",optional:!0}],class:"p5.Amplitude",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2402,description:"Smooth Amplitude analysis by averaging with the last analysis\nframe. Off by default.
\n",itemtype:"method",name:"smooth",params:[{name:"set",description:"smoothing from 0.0 <= 1
\n",type:"Number"}],class:"p5.Amplitude",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2571,description:"Set the input source for the FFT analysis. If no source is\nprovided, FFT will analyze all sound in the sketch.
\n",itemtype:"method",name:"setInput",params:[{name:"source",description:"p5.sound object (or web audio API source node)
\n",type:"Object",optional:!0}],class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2590,description:"Returns an array of amplitude values (between -1.0 and +1.0) that represent\na snapshot of amplitude readings in a single buffer. Length will be\nequal to bins (defaults to 1024). Can be used to draw the waveform\nof a sound.
\n",itemtype:"method",name:"waveform",params:[{name:"bins",description:"Must be a power of two between\n 16 and 1024. Defaults to 1024.
\n",type:"Number",optional:!0},{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:!0}],return:{description:"Array Array of amplitude values (-1 to 1)\n over time. Array length = bins.",type:"Array"},class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2633,description:"Returns an array of amplitude values (between 0 and 255)\nacross the frequency spectrum. Length is equal to FFT bins\n(1024 by default). The array indices correspond to frequencies\n(i.e. pitches), from the lowest to the highest that humans can\nhear. Each value represents amplitude at that slice of the\nfrequency spectrum. Must be called prior to using\ngetEnergy()
.
Must be a power of two between\n 16 and 1024. Defaults to 1024.
\n",type:"Number",optional:!0},{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:!0}],return:{description:"spectrum Array of energy (amplitude/volume)\n values across the frequency spectrum.\n Lowest energy (silence) = 0, highest\n possible is 255.",type:"Array"},example:["\n\nvar osc;\nvar fft;\n\nfunction setup(){\n createCanvas(100,100);\n osc = new p5.Oscillator();\n osc.amp(0);\n osc.start();\n fft = new p5.FFT();\n}\n\nfunction draw(){\n background(0);\n\n var freq = map(mouseX, 0, 800, 20, 15000);\n freq = constrain(freq, 1, 20000);\n osc.freq(freq);\n\n var spectrum = fft.analyze();\n noStroke();\n fill(0,255,0); // spectrum is green\n for (var i = 0; i< spectrum.length; i++){\n var x = map(i, 0, spectrum.length, 0, width);\n var h = -height + map(spectrum[i], 0, 255, height, 0);\n rect(x, height, width / spectrum.length, h );\n }\n\n stroke(255);\n text('Freq: ' + round(freq)+'Hz', 10, 10);\n\n isMouseOverCanvas();\n}\n\n// only play sound when mouse is over canvas\nfunction isMouseOverCanvas() {\n var mX = mouseX, mY = mouseY;\n if (mX > 0 && mX < width && mY < height && mY > 0) {\n osc.amp(0.5, 0.2);\n } else {\n osc.amp(0, 0.2);\n }\n}\n
Returns the amount of energy (volume) at a specific\n\nfrequency, or the average amount of energy between two\nfrequencies. Accepts Number(s) corresponding\nto frequency (in Hz), or a String corresponding to predefined\nfrequency ranges ("bass", "lowMid", "mid", "highMid", "treble").\nReturns a range between 0 (no energy/volume at that frequency) and\n255 (maximum energy).\nNOTE: analyze() must be called prior to getEnergy(). Analyze()\ntells the FFT to analyze frequency data, and getEnergy() uses\nthe results determine the value at a specific frequency or\nrange of frequencies.
\n',itemtype:"method",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:!0}],return:{description:"Energy Energy (volume/amplitude) from\n 0 and 255.",type:"Number"},class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2805,description:'Returns the\n\nspectral centroid of the input signal.\nNOTE: analyze() must be called prior to getCentroid(). Analyze()\ntells the FFT to analyze frequency data, and getCentroid() uses\nthe results determine the spectral centroid.
\n',itemtype:"method",name:"getCentroid",return:{description:"Spectral Centroid Frequency Frequency of the spectral centroid in Hz.",type:"Number"}, example:['\n\n\n\nfunction setup(){\ncnv = createCanvas(800,400);\nsound = new p5.AudioIn();\nsound.start();\nfft = new p5.FFT();\nsound.connect(fft);\n}\n\n\nfunction draw(){\n\nvar centroidplot = 0.0;\nvar spectralCentroid = 0;\n\n\nbackground(0);\nstroke(0,255,0);\nvar spectrum = fft.analyze();\nfill(0,255,0); // spectrum is green\n\n//draw the spectrum\n\nfor (var i = 0; i< spectrum.length; i++){\n var x = map(log(i), 0, log(spectrum.length), 0, width);\n var h = map(spectrum[i], 0, 255, 0, height);\n var rectangle_width = (log(i+1)-log(i))*(width/log(spectrum.length));\n rect(x, height, rectangle_width, -h )\n}\n\nvar nyquist = 22050;\n\n// get the centroid\nspectralCentroid = fft.getCentroid();\n\n// the mean_freq_index calculation is for the display.\nvar mean_freq_index = spectralCentroid/(nyquist/spectrum.length);\n\ncentroidplot = map(log(mean_freq_index), 0, log(spectrum.length), 0, width);\n\n\nstroke(255,0,0); // the line showing where the centroid is will be red\n\nrect(centroidplot, 0, width / spectrum.length, height)\nnoStroke();\nfill(255,255,255); // text is white\ntextSize(40);\ntext("centroid: "+round(spectralCentroid)+" Hz", 10, 40);\n}\n
Smooth FFT analysis by averaging with the last analysis frame.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2906,description:"Returns an array of average amplitude values for a given number\nof frequency bands split equally. N defaults to 16.\nNOTE: analyze() must be called prior to linAverages(). Analyze()\ntells the FFT to analyze frequency data, and linAverages() uses\nthe results to group them into a smaller set of averages.
\n",itemtype:"method",name:"linAverages",params:[{name:"N",description:"Number of returned frequency groups
\n",type:"Number"}],return:{description:"linearAverages Array of average amplitude values for each group",type:"Array"},class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2936,description:'Returns an array of average amplitude values of the spectrum, for a given\nset of \nOctave Bands\nNOTE: analyze() must be called prior to logAverages(). Analyze()\ntells the FFT to analyze frequency data, and logAverages() uses\nthe results to group them into a smaller set of averages.
\n',itemtype:"method",name:"logAverages",params:[{name:"octaveBands",description:"Array of Octave Bands objects for grouping
\n",type:"Array"}],return:{description:"logAverages Array of average amplitude values for each group",type:"Array"},class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:2966,description:'Calculates and Returns the 1/N\nOctave Bands\nN defaults to 3 and minimum central frequency to 15.625Hz.\n(1/3 Octave Bands ~= 31 Frequency Bands)\nSetting fCtr0 to a central value of a higher octave will ignore the lower bands\nand produce less frequency groups.
\n',itemtype:"method",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"}],return:{description:"octaveBands Array of octave band objects with their bounds",type:"Array"},class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:3024,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:3427,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:3448,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:3507,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:3960,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4097,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4130,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4176,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4197,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4217,class:"p5.FFT",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4319,description:"Fade to value, for smooth transitions
\n",itemtype:"method",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:!0}],class:"p5.Signal",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4330,description:"Connect a p5.sound object or Web Audio node to this\np5.Signal so that its amplitude values can be scaled.
\n",params:[{name:"input",description:"",type:"Object"}],class:"p5.Signal",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4343,description:"Add a constant value to this audio signal,\nand return the resulting audio signal. Does\nnot change the value of the original signal,\ninstead it returns a new p5.SignalAdd.
\n",itemtype:"method",name:"add",params:[{name:"number",description:"",type:"Number"}],return:{description:"object",type:"p5.SignalAdd"},class:"p5.Signal",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4362,description:"Multiply this signal by a constant value,\nand return the resulting audio signal. Does\nnot change the value of the original signal,\ninstead it returns a new p5.SignalMult.
\n",itemtype:"method",name:"mult",params:[{name:"number",description:"to multiply
\n",type:"Number"}],return:{description:"object",type:"Tone.Multiply"},class:"p5.Signal",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4381,description:"Scale this signal value to a given range,\nand return the result as an audio signal. Does\nnot change the value of the original signal,\ninstead it returns a new p5.SignalScale.
\n",itemtype:"method",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"}],return:{description:"object",type:"p5.SignalScale"},class:"p5.Signal",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4515,description:"Start an oscillator. Accepts an optional parameter to\ndetermine how long (in seconds from now) until the\noscillator starts.
\n",itemtype:"method",name:"start",params:[{name:"time",description:"startTime in seconds from now.
\n",type:"Number",optional:!0},{name:"frequency",description:"frequency in Hz.
\n",type:"Number",optional:!0}],class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4555,description:"Stop an oscillator. Accepts an optional parameter\nto determine how long (in seconds from now) until the\noscillator stops.
\n",itemtype:"method",name:"stop",params:[{name:"secondsFromNow",description:"Time, in seconds from now.
\n",type:"Number"}],class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4571,description:"Set the amplitude between 0 and 1.0. Or, pass in an object\nsuch as an oscillator to modulate amplitude with an audio signal.
\n",itemtype:"method",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:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],return:{description:"gain If no value is provided,\n returns the Web Audio API\n AudioParam that controls\n this oscillator's\n gain/amplitude/volume)",type:"AudioParam"},class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4606,description:"Set frequency of an oscillator to a value. Or, pass in an object\nsuch as an oscillator to modulate the frequency with an audio signal.
\n",itemtype:"method",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:!0},{name:"timeFromNow",description:"Schedule this event to happen\n at x seconds from now
\n",type:"Number",optional:!0}],return:{description:"Frequency If no value is provided,\n returns the Web Audio API\n AudioParam that controls\n this oscillator's frequency",type:"AudioParam"},example:["\n\nvar osc = new p5.Oscillator(300);\nosc.start();\nosc.freq(40, 10);\n
Set type to 'sine', 'triangle', 'sawtooth' or 'square'.
\n",itemtype:"method",name:"setType",params:[{name:"type",description:"'sine', 'triangle', 'sawtooth' or 'square'.
\n",type:"String"}],class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4677,description:"Connect to a p5.sound / Web Audio object.
\n",itemtype:"method",name:"connect",params:[{name:"unit",description:"A p5.sound or Web Audio object
\n",type:"Object"}],class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4694,description:"Disconnect all outputs
\n",itemtype:"method",name:"disconnect",class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4705,description:"Pan between Left (-1) and Right (1)
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4737,description:"Set the phase of an oscillator between 0.0 and 1.0.\nIn this implementation, phase is a delay time\nbased on the oscillator's current frequency.
\n",itemtype:"method",name:"phase",params:[{name:"phase",description:"float between 0.0 and 1.0
\n",type:"Number"}],class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4791,description:"Add a value to the p5.Oscillator's output amplitude,\nand return the oscillator. Calling this method again\nwill override the initial add() with a new value.
\n",itemtype:"method",name:"add",params:[{name:"number",description:"Constant number to add
\n",type:"Number"}],return:{description:"Oscillator Returns this oscillator\n with scaled output",type:"p5.Oscillator"},class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4808,description:"Multiply the p5.Oscillator's output amplitude\nby a fixed value (i.e. turn it up!). Calling this method\nagain will override the initial mult() with a new value.
\n",itemtype:"method",name:"mult",params:[{name:"number",description:"Constant number to multiply
\n",type:"Number"}],return:{description:"Oscillator Returns this oscillator\n with multiplied output",type:"p5.Oscillator"},class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4824,description:"Scale this oscillator's amplitude values to a given\nrange, and return the oscillator. Calling this method\nagain will override the initial scale() with new values.
\n",itemtype:"method",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"}],return:{description:"Oscillator Returns this oscillator\n with scaled output",type:"p5.Oscillator"},class:"p5.Oscillator",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:4923,class:"p5.SqrOsc",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5109,class:"p5.SqrOsc",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5333,description:"Time until envelope reaches attackLevel
\n",itemtype:"property",name:"attackTime",class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5338,description:"Level once attack is complete.
\n",itemtype:"property",name:"attackLevel",class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5343,description:"Time until envelope reaches decayLevel.
\n",itemtype:"property",name:"decayTime",class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5348,description:"Level after decay. The envelope will sustain here until it is released.
\n",itemtype:"property",name:"decayLevel",class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5353,description:"Duration of the release portion of the envelope.
\n",itemtype:"property",name:"releaseTime",class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5358,description:"Level at the end of the release.
\n",itemtype:"property",name:"releaseLevel",class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5394,description:"Reset the envelope with a series of time/value pairs.
\n",itemtype:"method",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"}],example:["\n\nvar t1 = 0.1; // attack time in seconds\nvar l1 = 0.7; // attack level 0.0 to 1.0\nvar t2 = 0.3; // decay time in seconds\nvar l2 = 0.1; // decay level 0.0 to 1.0\nvar t3 = 0.2; // sustain time in seconds\nvar l3 = dL; // sustain level 0.0 to 1.0\n// release level defaults to zero\n\nvar env;\nvar triOsc;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env(t1, l1, t2, l2, t3, l3);\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env); // give the env control of the triOsc's amp\n triOsc.start();\n}\n\n// mouseClick triggers envelope if over canvas\nfunction mouseClicked() {\n // is mouse over canvas?\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n env.play(triOsc);\n }\n}\n
Set values like a traditional\n\nADSR envelope\n.
\n',itemtype:"method",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:!0},{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:!0}],example:["\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv(){\n env.play();\n}\n
Set max (attackLevel) and min (releaseLevel) of envelope.
\n",itemtype:"method",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"}],example:["\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv(){\n env.play();\n}\n
Assign a parameter to be controlled by this envelope.\nIf a p5.Sound object is given, then the p5.Env will control its\noutput gain. If multiple inputs are provided, the env will\ncontrol all of them.
\n",itemtype:"method",name:"setInput",params:[{name:"inputs",description:"A p5.sound object or\n Web Audio Param.
\n",type:"Object",optional:!0,multiple:!0}],class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5612,description:"Set whether the envelope ramp is linear (default) or exponential.\nExponential ramps can be useful because we perceive amplitude\nand frequency logarithmically.
\n",itemtype:"method",name:"setExp",params:[{name:"isExp",description:"true is exponential, false is linear
\n",type:"Boolean"}],class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:5630,description:'Play tells the envelope to start acting on a given input.\nIf the input is a p5.sound object (i.e. AudioIn, Oscillator,\nSoundFile), then Env will control its output volume.\nEnvelopes can also be used to control any \nWeb Audio Audio Param.
\n',itemtype:"method",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:!0},{name:"sustainTime",description:"time to sustain before releasing the envelope
\n",type:"Number",optional:!0}],example:["\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv(){\n // trigger env on triOsc, 0 seconds from now\n // After decay, sustain for 0.2 seconds before release\n env.play(triOsc, 0, 0.2);\n}\n
Trigger the Attack, and Decay portion of the Envelope.\nSimilar to holding down a key on a piano, but it will\nhold the sustain level until you let go. Input can be\nany p5.sound object, or a \nWeb Audio Param.
\n',itemtype:"method",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"}],example:["\n\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001\nvar decayTime = 0.3;\nvar susPercent = 0.4;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(envAttack);\n}\n\nfunction envAttack(){\n console.log('trigger attack');\n env.triggerAttack();\n\n background(0,255,0);\n text('attack!', width/2, height/2);\n}\n\nfunction mouseReleased() {\n env.triggerRelease();\n\n background(200);\n text('click to play', width/2, height/2);\n}\n
Trigger the Release of the Envelope. This is similar to releasing\nthe key on a piano and letting the sound fade according to the\nrelease level and release time.
\n",itemtype:"method",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"}],example:["\n\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001\nvar decayTime = 0.3;\nvar susPercent = 0.4;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(envAttack);\n}\n\nfunction envAttack(){\n console.log('trigger attack');\n env.triggerAttack();\n\n background(0,255,0);\n text('attack!', width/2, height/2);\n}\n\nfunction mouseReleased() {\n env.triggerRelease();\n\n background(200);\n text('click to play', width/2, height/2);\n}\n
Exponentially ramp to a value using the first two\nvalues from setADSR(attackTime, decayTime)
\nas \ntime constants for simple exponential ramps.\nIf the value is higher than current value, it uses attackTime,\nwhile a decrease uses decayTime.
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:!0}],example:["\n\nvar env, osc, amp, cnv;\n\nvar attackTime = 0.001;\nvar decayTime = 0.2;\nvar attackLevel = 1;\nvar decayLevel = 0;\n\nfunction setup() {\n cnv = createCanvas(100, 100);\n fill(0,255,0);\n noStroke();\n\n env = new p5.Env();\n env.setADSR(attackTime, decayTime);\n\n osc = new p5.Oscillator();\n osc.amp(env);\n osc.start();\n\n amp = new p5.Amplitude();\n\n cnv.mousePressed(triggerRamp);\n}\n\nfunction triggerRamp() {\n env.ramp(osc, 0, attackLevel, decayLevel);\n}\n\nfunction draw() {\n background(20,20,20);\n text('click me', 10, 20);\n var h = map(amp.getLevel(), 0, 0.4, 0, height);;\n\n rect(0, height, width, -h);\n}\n
Add a value to the p5.Oscillator's output amplitude,\nand return the oscillator. Calling this method\nagain will override the initial add() with new values.
\n",itemtype:"method",name:"add",params:[{name:"number",description:"Constant number to add
\n",type:"Number"}],return:{description:"Envelope Returns this envelope\n with scaled output",type:"p5.Env"},class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6020,description:"Multiply the p5.Env's output amplitude\nby a fixed value. Calling this method\nagain will override the initial mult() with new values.
\n",itemtype:"method",name:"mult",params:[{name:"number",description:"Constant number to multiply
\n",type:"Number"}],return:{description:"Envelope Returns this envelope\n with scaled output",type:"p5.Env"},class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6036,description:"Scale this envelope's amplitude values to a given\nrange, and return the envelope. Calling this method\nagain will override the initial scale() with new values.
\n",itemtype:"method",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"}],return:{description:"Envelope Returns this envelope\n with scaled output",type:"p5.Env"},class:"p5.Env",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6140,description:"Set the width of a Pulse object (an oscillator that implements\nPulse Width Modulation).
\n",itemtype:"method",name:"width",params:[{name:"width",description:"Width between the pulses (0 to 1.0,\n defaults to 0)
\n",type:"Number",optional:!0}],class:"p5.Pulse",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6325,description:"Set type of noise to 'white', 'pink' or 'brown'.\nWhite is the default.
\n",itemtype:"method",name:"setType",params:[{name:"type",description:"'white', 'pink' or 'brown'
\n",type:"String",optional:!0}],class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6355,description:"Start the noise
\n",itemtype:"method",name:"start",class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6372,description:"Stop the noise.
\n",itemtype:"method",name:"stop",class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6384,description:"Pan the noise.
\n",itemtype:"method",name:"pan",params:[{name:"panning",description:"Number between -1 (left)\n and 1 (right)
\n",type:"Number"},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number"}],class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6393,description:"Set the amplitude of the noise between 0 and 1.0. Or,\nmodulate amplitude with an audio signal such as an oscillator.
\n",params:[{name:"volume",description:"amplitude between 0 and 1.0\n or modulating signal/oscillator
\n",type:"Number|Object"},{name:"rampTime",description:"create a fade that lasts rampTime
\n",type:"Number",optional:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6403,description:"Send output to a p5.sound or web audio object
\n",itemtype:"method",name:"connect",params:[{name:"unit",description:"",type:"Object"}],class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6409,description:"Disconnect all output.
\n",itemtype:"method",name:"disconnect",class:"p5.Noise",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6481,description:"Client must allow browser to access their microphone / audioin source.\nDefault: false. Will become true when the client enables acces.
\n",itemtype:"property",name:"enabled",type:"Boolean",class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6506,description:"Start processing audio input. This enables the use of other\nAudioIn methods like getLevel(). Note that by default, AudioIn\nis not connected to p5.sound's output. So you won't hear\nanything unless you use the connect() method.
Certain browsers limit access to the user's microphone. For example,\nChrome only allows access from localhost and over https. For this reason,\nyou may want to include an errorCallback—a function that is called in case\nthe browser won't provide mic access.
\n",itemtype:"method",name:"start",params:[{name:"successCallback", description:"Name of a function to call on\n success.
\n",type:"Function",optional:!0},{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:!0}],class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6571,description:"Turn the AudioIn off. If the AudioIn is stopped, it cannot getLevel().\nIf re-starting, the user may be prompted for permission access.
\n",itemtype:"method",name:"stop",class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6583,description:"Connect to an audio unit. If no parameter is provided, will\nconnect to the master output (i.e. your speakers).
An object that accepts audio input,\n such as an FFT
\n",type:"Object",optional:!0}],class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6604,description:"Disconnect the AudioIn from all audio units. For example, if\nconnect() had been called, disconnect() will stop sending\nsignal to your speakers.
Read the Amplitude (volume level) of an AudioIn. The AudioIn\nclass contains its own instance of the Amplitude class to help\nmake it easy to get a microphone's volume level. Accepts an\noptional smoothing value (0.0 < 1.0). NOTE: AudioIn must\n.start() before using .getLevel().
Smoothing is 0.0 by default.\n Smooths values based on previous values.
\n",type:"Number",optional:!0}],return:{description:"Volume level (between 0.0 and 1.0)",type:"Number"},class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6634,description:"Add input sources to the list of available sources.
\n",access:"private",tagname:"",class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6649,description:"Set amplitude (volume) of a mic input between 0 and 1.0.
between 0 and 1.0
\n",type:"Number"},{name:"time",description:"ramp time (optional)
\n",type:"Number",optional:!0}],class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6677,description:'Chrome only. Returns a list of available input sources\nand allows the user to set the media source. Firefox allows\nthe user to choose from input sources in the permissions dialogue\ninstead of enumerating available sources and selecting one.\nNote: in order to have descriptive media names your page must be\nserved over a secure (HTTPS) connection and the page should\nrequest user media before enumerating devices. Otherwise device\nID will be a long device ID number and does not specify device\ntype. For example see\nhttps://simpl.info/getusermedia/sources/index.html vs.\nhttp://simpl.info/getusermedia/sources/index.html
\n',itemtype:"method",name:"getSources",params:[{name:"callback",description:"a callback to handle the sources\n when they have been enumerated
\n",type:"Function"}],example:["\n\n var audiograb;\n\n function setup(){\n //new audioIn\n audioGrab = new p5.AudioIn();\n\n audioGrab.getSources(function(sourceList) {\n //print out the array of available sources\n console.log(sourceList);\n //set the source to the first item in the inputSources array\n audioGrab.setSource(0);\n });\n }\n
Set the input source. Accepts a number representing a\nposition in the array returned by listSources().\nThis is only available in browsers that support\nMediaStreamTrack.getSources(). Instead, some browsers\ngive users the option to set their own media source.
position of input source in the array
\n",type:"Number"}],class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6763,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6779,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6803,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6829,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6858,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6888,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6936,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6959,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:6984,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7005,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7012,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7034,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7063,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7090,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7118,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7146,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7192,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7223,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7241,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7629,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7651,class:"p5.AudioIn",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7721,description:"The p5.Effect class is built\n using Tone.js CrossFade
\n",access:"private",tagname:"",class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7727,description:"In classes that extend\np5.Effect, connect effect nodes\nto the wet parameter
\n",class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7740,description:"Set the output volume of the filter.
\n",itemtype:"method",name:"amp",params:[{name:"vol",description:"amplitude between 0 and 1.0
\n",type:"Number",optional:!0},{name:"rampTime",description:"create a fade that lasts until rampTime
\n",type:"Number",optional:!0},{name:"tFromNow",description:"schedule this event to happen in tFromNow seconds
\n",type:"Number",optional:!0}],class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7757,description:"Link effects together in a chain
Example usage: filter.chain(reverb, delay, panner);\nMay be used with an open-ended number of arguments
Chain together multiple sound objects
\n",type:"Object",optional:!0}],class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7774,description:"Adjust the dry/wet value.
\n",itemtype:"method",name:"drywet",params:[{name:"fade",description:"The desired drywet value (0 - 1.0)
\n",type:"Number",optional:!0}],class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7786,description:"Send output to a p5.js-sound, Web Audio Node, or use signal to\ncontrol an AudioParam
\n",itemtype:"method",name:"connect",params:[{name:"unit",description:"",type:"Object"}],class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7797,description:"Disconnect all output.
\n",itemtype:"method",name:"disconnect",class:"p5.Effect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7904,description:'The p5.Filter is built with a\n\nWeb Audio BiquadFilter Node.
\n',itemtype:"property",name:"biquadFilter",type:"DelayNode",class:"p5.Filter",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7919,description:"Filter an audio signal according to a set\nof filter parameters.
\n",itemtype:"method",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:!0},{name:"res",description:"Resonance/Width of the filter frequency\n from 0.001 to 1000
\n",type:"Number",optional:!0}],class:"p5.Filter",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7933,description:"Set the frequency and the resonance of the filter.
\n",itemtype:"method",name:"set",params:[{name:"freq",description:"Frequency in Hz, from 10 to 22050
\n",type:"Number",optional:!0},{name:"res",description:"Resonance (Q) from 0.001 to 1000
\n",type:"Number",optional:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],class:"p5.Filter",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7950,description:"Set the filter frequency, in Hz, from 10 to 22050 (the range of\nhuman hearing, although in reality most people hear in a narrower\nrange).
\n",itemtype:"method",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:!0}],return:{description:"value Returns the current frequency value",type:"Number"},class:"p5.Filter",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7975,description:"Controls either width of a bandpass frequency,\nor the resonance of a low/highpass cutoff frequency.
\n",itemtype:"method",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:!0}],return:{description:"value Returns the current res value",type:"Number"},class:"p5.Filter",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:7997,description:"Set the type of a p5.Filter. Possible types include:\n"lowpass" (default), "highpass", "bandpass",\n"lowshelf", "highshelf", "peaking", "notch",\n"allpass".
\n",itemtype:"method",name:"setType",params:[{name:"t",description:"",type:"String"}],class:"p5.Filter",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8124,description:'The p5.Delay is built with two\n\nWeb Audio Delay Nodes, one for each stereo channel.
\n',itemtype:"property",name:"leftDelay",type:"DelayNode",class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8132,description:'The p5.Delay is built with two\n\nWeb Audio Delay Nodes, one for each stereo channel.
\n',itemtype:"property",name:"rightDelay",type:"DelayNode",class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8164,description:"Add delay to an audio signal according to a set\nof delay parameters.
\n",itemtype:"method",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:!0},{name:"feedback",description:"sends the delay back through itself\n in a loop that decreases in volume\n each time.
\n",type:"Number",optional:!0},{name:"lowPass",description:"Cutoff frequency. Only frequencies\n below the lowPass will be part of the\n delay.
\n",type:"Number",optional:!0}],class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8199,description:"Set the delay (echo) time, in seconds. Usually this value will be\na floating point number between 0.0 and 1.0.
\n",itemtype:"method",name:"delayTime",params:[{name:"delayTime",description:"Time (in seconds) of the delay
\n",type:"Number"}],class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8218,description:"Feedback occurs when Delay sends its signal back through its input\nin a loop. The feedback amount determines how much signal to send each\ntime through the loop. A feedback greater than 1.0 is not desirable because\nit will increase the overall output each time through the loop,\ncreating an infinite feedback loop. The default value is 0.5
\n",itemtype:"method",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"}],return:{description:"Feedback value",type:"Number"},class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8246,description:"Set a lowpass filter frequency for the delay. A lowpass filter\nwill cut off any frequencies higher than the filter frequency.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8263,description:"Choose a preset type of delay. 'pingPong' bounces the signal\nfrom the left to the right channel to produce a stereo effect.\nAny other parameter will revert to the default delay setting.
\n",itemtype:"method",name:"setType",params:[{name:"type",description:"'pingPong' (1) or 'default' (0)
\n",type:"String|Number"}],class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8296,description:"Set the output level of the delay effect.
\n",itemtype:"method",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:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8305,description:"Send output to a p5.sound or web audio object
\n",itemtype:"method",name:"connect",params:[{name:"unit",description:"",type:"Object"}],class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8311,description:"Disconnect all output.
\n",itemtype:"method",name:"disconnect",class:"p5.Delay",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8390,description:"Connect a source to the reverb, and assign reverb parameters.
\n",itemtype:"method",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:!0},{name:"decayRate",description:"Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.
\n",type:"Number",optional:!0},{name:"reverse",description:"Play the reverb backwards or forwards.
\n",type:"Boolean",optional:!0}],class:"p5.Reverb",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8419,description:"Set the reverb settings. Similar to .process(), but without\nassigning a new input.
\n",itemtype:"method",name:"set",params:[{name:"seconds",description:"Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.
\n",type:"Number",optional:!0},{name:"decayRate",description:"Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.
\n",type:"Number",optional:!0},{name:"reverse",description:"Play the reverb backwards or forwards.
\n",type:"Boolean",optional:!0}],class:"p5.Reverb",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8447,description:"Set the output level of the reverb effect.
\n",itemtype:"method",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:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],class:"p5.Reverb",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8456,description:"Send output to a p5.sound or web audio object
\n",itemtype:"method",name:"connect",params:[{name:"unit",description:"",type:"Object"}],class:"p5.Reverb",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8462,description:"Disconnect all output.
\n",itemtype:"method",name:"disconnect",class:"p5.Reverb",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8467,description:'Inspired by Simple Reverb by Jordan Santell\nhttps://github.com/web-audio-components/simple-reverb/blob/master/index.js
\nUtility function for building an impulse response\nbased on the module parameters.
\n',access:"private",tagname:"",class:"p5.Reverb",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8556,description:'Internally, the p5.Convolver uses the a\n\nWeb Audio Convolver Node.
\n',itemtype:"property",name:"convolverNod",type:"ConvolverNode",class:"p5.Convolver",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8581,description:"Create a p5.Convolver. Accepts a path to a soundfile\nthat will be used to generate an impulse response.
\n",itemtype:"method",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:!0},{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:!0}],return:{description:"",type:"p5.Convolver"},example:["\n\nvar cVerb, sound;\nfunction preload() {\n // We have both MP3 and OGG versions of all sound assets\n soundFormats('ogg', 'mp3');\n\n // Try replacing 'bx-spring' with other soundfiles like\n // 'concrete-tunnel' 'small-plate' 'drum' 'beatbox'\n cVerb = createConvolver('assets/bx-spring.mp3');\n\n // Try replacing 'Damscray_DancingTiger' with\n // 'beat', 'doorbell', lucky_dragons_-_power_melody'\n sound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n // disconnect from master output...\n sound.disconnect();\n\n // ...and process with cVerb\n // so that we only hear the convolution\n cVerb.process(sound);\n\n sound.play();\n}\n
Private method to load a buffer as an Impulse Response,\nassign it to the convolverNode, and add to the Array of .impulses.
\n",params:[{name:"path",description:"",type:"String"},{name:"callback",description:"",type:"Function"},{name:"errorCallback",description:"",type:"Function"}],access:"private",tagname:"",class:"p5.Convolver",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8697,description:"Connect a source to the reverb, and assign reverb parameters.
\n",itemtype:"method",name:"process",params:[{name:"src",description:"p5.sound / Web Audio object with a sound\n output.
\n",type:"Object"}],example:["\n\nvar cVerb, sound;\nfunction preload() {\n soundFormats('ogg', 'mp3');\n\n cVerb = createConvolver('assets/concrete-tunnel.mp3');\n\n sound = loadSound('assets/beat.mp3');\n}\n\nfunction setup() {\n // disconnect from master output...\n sound.disconnect();\n\n // ...and process with (i.e. connect to) cVerb\n // so that we only hear the convolution\n cVerb.process(sound);\n\n sound.play();\n}\n
If you load multiple impulse files using the .addImpulse method,\nthey will be stored as Objects in this Array. Toggle between them\nwith the toggleImpulse(id)
method.
Load and assign a new Impulse Response to the p5.Convolver.\nThe impulse is added to the .impulses
array. Previous\nimpulses can be accessed with the .toggleImpulse(id)
\nmethod.
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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8755,description:"Similar to .addImpulse, except that the .impulses
\nArray is reset to save memory. A new .impulses
\narray is created with this impulse as the only item.
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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:8773,description:'If you have used .addImpulse()
to add multiple impulses\nto a p5.Convolver, then you can use this method to toggle between\nthe items in the .impulses
Array. Accepts a parameter\nto identify which impulse you wish to use, identified either by its\noriginal filename (String) or by its position in the .impulses\n
Array (Number).
\nYou can access the objects in the .impulses Array directly. Each\nObject has two attributes: an .audioBuffer
(type:\nWeb Audio \nAudioBuffer) and a .name
, a String that corresponds\nwith the original filename.
Identify the impulse by its original filename\n (String), or by its position in the\n .impulses
Array (Number).
Set the global tempo, in beats per minute, for all\np5.Parts. This method will impact all active p5.Parts.
\n",params:[{name:"BPM",description:"Beats Per Minute
\n",type:"Number"},{name:"rampTime",description:"Seconds from now
\n",type:"Number"}],class:"p5.Convolver",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9148,description:"Array of values to pass into the callback\nat each step of the phrase. Depending on the callback\nfunction's requirements, these values may be numbers,\nstrings, or an object with multiple parameters.\nZero (0) indicates a rest.
\n",itemtype:"property",name:"sequence",type:"Array",class:"p5.Phrase",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9236,description:"Set the tempo of this part, in Beats Per Minute.
\n",itemtype:"method",name:"setBPM",params:[{name:"BPM",description:"Beats Per Minute
\n",type:"Number"},{name:"rampTime",description:"Seconds from now
\n",type:"Number",optional:!0}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9246,description:"Returns the Beats Per Minute of this currently part.
\n",itemtype:"method",name:"getBPM",return:{description:"",type:"Number"},class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9255,description:"Start playback of this part. It will play\nthrough all of its phrases at a speed\ndetermined by setBPM.
\n",itemtype:"method",name:"start",params:[{name:"time",description:"seconds from now
\n",type:"Number",optional:!0}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9271,description:"Loop playback of this part. It will begin\nlooping through all of its phrases at a speed\ndetermined by setBPM.
\n",itemtype:"method",name:"loop",params:[{name:"time",description:"seconds from now
\n",type:"Number",optional:!0}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9288,description:"Tell the part to stop looping.
\n",itemtype:"method",name:"noLoop",class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9300,description:"Stop the part and cue it to step 0.
\n",itemtype:"method",name:"stop",params:[{name:"time",description:"seconds from now
\n",type:"Number",optional:!0}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9310,description:"Pause the part. Playback will resume\nfrom the current step.
\n",itemtype:"method",name:"pause",params:[{name:"time",description:"seconds from now
\n",type:"Number"}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9322,description:"Add a p5.Phrase to this Part.
\n",itemtype:"method",name:"addPhrase",params:[{name:"phrase",description:"reference to a p5.Phrase
\n",type:"p5.Phrase"}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9343,description:"Remove a phrase from this part, based on the name it was\ngiven when it was created.
\n",itemtype:"method",name:"removePhrase",params:[{name:"phraseName",description:"",type:"String"}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9357,description:"Get a phrase from this part, based on the name it was\ngiven when it was created. Now you can modify its array.
\n",itemtype:"method",name:"getPhrase",params:[{name:"phraseName",description:"",type:"String"}],class:"p5.Part",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9371,description:"Get a phrase from this part, based on the name it was\ngiven when it was created. Now you can modify its array.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9399,description:"Fire a callback function at every step.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9452,description:"Start playback of the score.
\n",itemtype:"method",name:"start",class:"p5.Score",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9461,description:"Stop playback of the score.
\n",itemtype:"method",name:"stop",class:"p5.Score",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9471,description:"Pause playback of the score.
\n",itemtype:"method",name:"pause",class:"p5.Score",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9479,description:"Loop playback of the score.
\n",itemtype:"method",name:"loop",class:"p5.Score",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9488,description:"Stop looping playback of the score. If it\nis currently playing, this will go into effect\nafter the current round of playback completes.
\n",itemtype:"method",name:"noLoop",class:"p5.Score",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9513,description:"Set the tempo for all parts in the score
\n",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9567, description:'The p5.Compressor is built with a Web Audio Dynamics Compressor Node\n
\n',itemtype:"property",name:"compressor",type:"WebAudioNode",class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9578,description:"Performs the same function as .connect, but also accepts\noptional parameters to set compressor's audioParams
\n",itemtype:"method",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:!0},{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:!0},{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:!0},{name:"threshold",description:"The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0
\n",type:"Number",optional:!0},{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:!0}],class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9601,description:"Set the paramters of a compressor.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9633,description:"Get current attack or set value w/ time ramp
\n",itemtype:"method",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:!0},{name:"time",description:"Assign time value to schedule the change in value
\n",type:"Number",optional:!0}],class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9653,description:"Get current knee or set value w/ time ramp
\n",itemtype:"method",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:!0},{name:"time",description:"Assign time value to schedule the change in value
\n",type:"Number",optional:!0}],class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9673,description:"Get current ratio or set value w/ time ramp
\n",itemtype:"method",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:!0},{name:"time",description:"Assign time value to schedule the change in value
\n",type:"Number",optional:!0}],class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9692,description:"Get current threshold or set value w/ time ramp
\n",itemtype:"method",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:!0}],class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9711,description:"Get current release or set value w/ time ramp
\n",itemtype:"method",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:!0}],class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9731,description:"Return the current reduction value
\n",return:{description:"Value of the amount of gain reduction that is applied to the signal",type:"Number"},class:"p5.Compressor",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9828,description:"callback invoked when the recording is over
\n",access:"private",tagname:"",type:"Function(Float32Array)",class:"p5.SoundRecorder",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9841,description:"Connect a specific device to the p5.SoundRecorder.\nIf no parameter is given, p5.SoundRecorer will record\nall audible p5.sound from your sketch.
\n",itemtype:"method",name:"setInput",params:[{name:"unit",description:"p5.sound object or a web audio unit\n that outputs sound
\n",type:"Object",optional:!0}],class:"p5.SoundRecorder",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9862,description:"Start recording. To access the recording, provide\na p5.SoundFile as the first parameter. The p5.SoundRecorder\nwill send its recording to that p5.SoundFile for playback once\nrecording is complete. Optional parameters include duration\n(in seconds) of the recording, and a callback function that\nwill be called once the complete recording has been\ntransfered to the p5.SoundFile.
\n",itemtype:"method",name:"record",params:[{name:"soundFile",description:"p5.SoundFile
\n",type:"p5.SoundFile"},{name:"duration",description:"Time (in seconds)
\n",type:"Number",optional:!0},{name:"callback",description:"The name of a function that will be\n called once the recording completes
\n",type:"Function",optional:!0}],class:"p5.SoundRecorder",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9895,description:"Stop the recording. Once the recording is stopped,\nthe results will be sent to the p5.SoundFile that\nwas given on .record(), and if a callback function\nwas provided on record, that function will be called.
\n",itemtype:"method",name:"stop",class:"p5.SoundRecorder",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9914,description:"internal method called on audio process
\n",access:"private",tagname:"",params:[{name:"event",description:"",type:"AudioProcessorEvent"}],class:"p5.SoundRecorder",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:9968,description:"Save a p5.SoundFile as a .wav audio file.
\n",itemtype:"method",name:"saveSound",params:[{name:"soundFile",description:"p5.SoundFile that you wish to save
\n",type:"p5.SoundFile"},{name:"name",description:"name of the resulting .wav file.
\n",type:"String"}],class:"p5.SoundRecorder",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10144,description:"isDetected is set to true when a peak is detected.
\n",itemtype:"attribute",name:"isDetected",type:"Boolean",default:"false",class:"p5.PeakDetect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10157,description:"The update method is run in the draw loop.
\nAccepts an FFT object. You must call .analyze()\non the FFT object prior to updating the peakDetect\nbecause it relies on a completed FFT analysis.
\n",itemtype:"method",name:"update",params:[{name:"fftObject",description:"A p5.FFT object
\n",type:"p5.FFT"}],class:"p5.PeakDetect",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10188,description:"onPeak accepts two arguments: a function to call when\na peak is detected. The value of the peak,\nbetween 0.0 and 1.0, is passed to the callback.
\n",itemtype:"method",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:!0}],example:["\n\nvar cnv, soundFile, fft, peakDetect;\nvar ellipseWidth = 0;\n\nfunction setup() {\n cnv = createCanvas(100,100);\n textAlign(CENTER);\n\n soundFile = loadSound('assets/beat.mp3');\n fft = new p5.FFT();\n peakDetect = new p5.PeakDetect();\n\n setupSound();\n\n // when a beat is detected, call triggerBeat()\n peakDetect.onPeak(triggerBeat);\n}\n\nfunction draw() {\n background(0);\n fill(255);\n text('click to play', width/2, height/2);\n\n fft.analyze();\n peakDetect.update(fft);\n\n ellipseWidth *= 0.95;\n ellipse(width/2, height/2, ellipseWidth, ellipseWidth);\n}\n\n// this function is called by peakDetect.onPeak\nfunction triggerBeat() {\n ellipseWidth = 50;\n}\n\n// mouseclick starts/stops sound\nfunction setupSound() {\n cnv.mouseClicked( function() {\n if (soundFile.isPlaying() ) {\n soundFile.stop();\n } else {\n soundFile.play();\n }\n });\n}\n
Connect a source to the gain node.
\n",itemtype:"method",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",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10344,description:"Send output to a p5.sound or web audio object
\n",itemtype:"method",name:"connect",params:[{name:"unit",description:"",type:"Object"}],class:"p5.Gain",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10354,description:"Disconnect all output.
\n",itemtype:"method",name:"disconnect",class:"p5.Gain",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10362,description:"Set the output level of the gain node.
\n",itemtype:"method",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:!0},{name:"timeFromNow",description:"schedule this event to happen\n seconds from now
\n",type:"Number",optional:!0}],class:"p5.Gain",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10443,description:'The p5.Distortion is built with a\n\nWeb Audio WaveShaper Node.
\n',itemtype:"property",name:"WaveShaperNode",type:"AudioNode",class:"p5.Distortion",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10458,description:"Process a sound source, optionally specify amount and oversample values.
\n",itemtype:"method",name:"process",params:[{name:"amount",description:"Unbounded distortion amount.\n Normal values range from 0-1.
\n",type:"Number",optional:!0,optdefault:"0.25"},{name:"oversample",description:"'none', '2x', or '4x'.
\n",type:"String",optional:!0,optdefault:"'none'"}],class:"p5.Distortion",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10470,description:"Set the amount and oversample of the waveshaper distortion.
\n",itemtype:"method",name:"set",params:[{name:"amount",description:"Unbounded distortion amount.\n Normal values range from 0-1.
\n",type:"Number",optional:!0,optdefault:"0.25"},{name:"oversample",description:"'none', '2x', or '4x'.
\n",type:"String",optional:!0,optdefault:"'none'"}],class:"p5.Distortion",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10488,description:"Return the distortion amount, typically between 0-1.
\n",itemtype:"method",name:"getAmount",return:{description:"Unbounded distortion amount.\n Normal values range from 0-1.",type:"Number"},class:"p5.Distortion",module:"p5.sound",submodule:"p5.sound"},{file:"lib/addons/p5.sound.js",line:10498,description:"Return the oversampling.
\n",itemtype:"method",name:"getOversample",return:{description:"Oversample can either be 'none', '2x', or '4x'.",type:"String"},class:"p5.Distortion",module:"p5.sound",submodule:"p5.sound"}],warnings:[{message:"unknown tag: alt",line:" src/color/creating_reading.js:16"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:60"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:89"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:118"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:326"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:356"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:392"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:489"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:518"},{message:"unknown tag: alt",line:" src/color/creating_reading.js:557"},{message:"unknown tag: alt",line:" src/color/p5.Color.js:447"},{message:"unknown tag: alt",line:" src/color/setting.js:15"},{message:"unknown tag: alt",line:" src/color/setting.js:178"},{message:"unknown tag: alt",line:" src/color/setting.js:235"},{message:"unknown tag: alt",line:" src/color/setting.js:373"},{message:"unknown tag: alt",line:" src/color/setting.js:489"},{message:"unknown tag: alt",line:" src/color/setting.js:514"},{message:"unknown tag: alt",line:" src/color/setting.js:581"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:16"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:132"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:187"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:262"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:313"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:393"},{message:"unknown tag: alt",line:" src/core/2d_primitives.js:477"},{message:"unknown tag: alt",line:" src/core/attributes.js:14"},{message:"unknown tag: alt",line:" src/core/attributes.js:80"},{message:"unknown tag: alt",line:" src/core/attributes.js:108"},{message:"unknown tag: alt",line:" src/core/attributes.js:174"},{message:"unknown tag: alt",line:" src/core/attributes.js:203"},{message:"unknown tag: alt",line:" src/core/attributes.js:237"},{message:"unknown tag: alt",line:" src/core/attributes.js:301"},{message:"unknown tag: alt",line:" src/core/constants.js:33"},{message:"unknown tag: alt",line:" src/core/constants.js:52"},{message:"unknown tag: alt",line:" src/core/constants.js:71"},{message:"unknown tag: alt",line:" src/core/constants.js:90"},{message:"unknown tag: alt",line:" src/core/constants.js:109"},{message:"unknown tag: alt",line:" src/core/core.js:49"},{message:"unknown tag: alt",line:" src/core/core.js:85"},{message:"unknown tag: alt",line:" src/core/core.js:116"},{message:"unknown tag: alt",line:" src/core/core.js:393"},{message:"unknown tag: alt",line:" src/core/curves.js:16"},{message:"unknown tag: alt",line:" src/core/curves.js:99"},{message:"unknown tag: alt",line:" src/core/curves.js:124"},{message:"unknown tag: alt",line:" src/core/curves.js:175"},{message:"unknown tag: alt",line:" src/core/curves.js:256"},{message:"unknown tag: alt",line:" src/core/curves.js:308"},{message:"unknown tag: alt",line:" src/core/curves.js:353"},{message:"unknown tag: alt",line:" src/core/curves.js:378"},{message:"unknown tag: alt",line:" src/core/curves.js:476"},{message:"unknown tag: alt",line:" src/core/environment.js:22"},{message:"unknown tag: alt",line:" src/core/environment.js:51"},{message:"unknown tag: alt",line:" src/core/environment.js:79"},{message:"unknown tag: alt",line:" src/core/environment.js:110"},{message:"unknown tag: alt",line:" src/core/environment.js:188"},{message:"unknown tag: alt",line:" src/core/environment.js:262"},{message:"unknown tag: alt",line:" src/core/environment.js:288"},{message:"unknown tag: alt",line:" src/core/environment.js:305"},{message:"unknown tag: alt",line:" src/core/environment.js:322"},{message:"unknown tag: alt",line:" src/core/environment.js:338"},{message:"unknown tag: alt",line:" src/core/environment.js:354"},{message:"unknown tag: alt",line:" src/core/environment.js:428"},{message:"replacing incorrect tag: returns with return",line:" src/core/environment.js:475"},{message:"unknown tag: alt",line:" src/core/environment.js:475"},{message:"replacing incorrect tag: returns with return",line:" src/core/environment.js:520"},{message:"unknown tag: alt",line:" src/core/environment.js:520"},{message:"unknown tag: alt",line:" src/core/environment.js:577"},{message:"unknown tag: alt",line:" src/core/environment.js:608"},{message:"unknown tag: alt",line:" src/core/environment.js:629"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:53"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:112"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:163"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:213"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:263"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:329"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:383"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:437"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:496"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:541"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:608"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:643"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:686"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:735"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:776"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:828"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:866"},{message:"unknown tag: alt",line:" src/core/p5.Element.js:904"},{message:"unknown tag: alt",line:" src/core/rendering.js:14"},{message:"unknown tag: alt",line:" src/core/rendering.js:112"},{message:"unknown tag: alt",line:" src/core/rendering.js:162"},{message:"unknown tag: alt",line:" src/core/rendering.js:185"},{message:"unknown tag: alt",line:" src/core/rendering.js:223"},{message:"unknown tag: alt",line:" src/core/structure.js:15"},{message:"unknown tag: alt",line:" src/core/structure.js:77"},{message:"unknown tag: alt",line:" src/core/structure.js:119"},{message:"unknown tag: alt",line:" src/core/structure.js:194"},{message:"unknown tag: alt",line:" src/core/structure.js:266"},{message:"unknown tag: alt",line:" src/core/transform.js:15"},{message:"unknown tag: alt",line:" src/core/transform.js:137"},{message:"unknown tag: alt",line:" src/core/transform.js:163"},{message:"unknown tag: alt",line:" src/core/transform.js:263"},{message:"unknown tag: alt",line:" src/core/transform.js:345"},{message:"unknown tag: alt",line:" src/core/transform.js:386"},{message:"unknown tag: alt",line:" src/core/transform.js:427"},{message:"unknown tag: alt",line:" src/core/vertex.js:22"},{message:"unknown tag: alt",line:" src/core/vertex.js:70"},{message:"unknown tag: alt",line:" src/core/vertex.js:267"},{message:"unknown tag: alt",line:" src/core/vertex.js:332"},{message:"unknown tag: alt",line:" src/core/vertex.js:374"},{message:"unknown tag: alt",line:" src/core/vertex.js:434"},{message:"unknown tag: alt",line:" src/core/vertex.js:502"},{message:"unknown tag: alt",line:" src/core/vertex.js:579"},{message:"unknown tag: alt",line:" src/events/acceleration.js:91"},{message:"unknown tag: alt",line:" src/events/acceleration.js:125"},{message:"unknown tag: alt",line:" src/events/acceleration.js:158"},{message:"unknown tag: alt",line:" src/events/acceleration.js:194"},{message:"unknown tag: alt",line:" src/events/acceleration.js:237"},{message:"unknown tag: alt",line:" src/events/acceleration.js:280"},{message:"unknown tag: alt",line:" src/events/acceleration.js:372"},{message:"unknown tag: alt",line:" src/events/acceleration.js:403"},{message:"unknown tag: alt",line:" src/events/acceleration.js:462"},{message:"unknown tag: alt",line:" src/events/keyboard.js:18"},{message:"unknown tag: alt",line:" src/events/keyboard.js:46"},{message:"unknown tag: alt",line:" src/events/keyboard.js:75"},{message:"unknown tag: alt",line:" src/events/keyboard.js:108"},{message:"unknown tag: alt",line:" src/events/keyboard.js:198"},{message:"unknown tag: alt",line:" src/events/keyboard.js:254"},{message:"unknown tag: alt",line:" src/events/keyboard.js:317"},{message:"unknown tag: alt",line:" src/events/mouse.js:23"},{message:"unknown tag: alt",line:" src/events/mouse.js:49"},{message:"unknown tag: alt",line:" src/events/mouse.js:75"},{message:"unknown tag: alt",line:" src/events/mouse.js:107"},{message:"unknown tag: alt",line:" src/events/mouse.js:137"},{message:"unknown tag: alt",line:" src/events/mouse.js:175"},{message:"unknown tag: alt",line:" src/events/mouse.js:213"},{message:"unknown tag: alt",line:" src/events/mouse.js:255"},{message:"unknown tag: alt",line:" src/events/mouse.js:298"},{message:"unknown tag: alt",line:" src/events/mouse.js:334"},{message:"unknown tag: alt",line:" src/events/mouse.js:416"},{message:"unknown tag: alt",line:" src/events/mouse.js:460"},{message:"unknown tag: alt",line:" src/events/mouse.js:531"},{message:"unknown tag: alt",line:" src/events/mouse.js:597"},{message:"unknown tag: alt",line:" src/events/mouse.js:664"},{message:"unknown tag: alt",line:" src/events/mouse.js:723"},{message:"unknown tag: alt",line:" src/events/mouse.js:781"},{message:"unknown tag: alt",line:" src/events/touch.js:53"},{message:"unknown tag: alt",line:" src/events/touch.js:116"},{message:"unknown tag: alt",line:" src/events/touch.js:178"},{message:"unknown tag: alt",line:" src/image/image.js:24"},{message:"unknown tag: alt",line:" src/image/image.js:115"},{message:"unknown tag: alt",line:" src/image/image.js:233"},{message:"unknown tag: alt",line:" src/image/loading_displaying.js:17"},{message:"replacing incorrect tag: returns with return",line:" src/image/loading_displaying.js:107"},{message:"unknown tag: alt",line:" src/image/loading_displaying.js:125"},{message:"unknown tag: alt",line:" src/image/loading_displaying.js:325"},{message:"unknown tag: alt",line:" src/image/loading_displaying.js:384"},{message:"unknown tag: alt",line:" src/image/loading_displaying.js:449"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:45"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:72"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:106"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:186"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:236"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:270"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:315"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:353"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:435"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:480"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:543"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:577"},{message:"unknown tag: alt",line:" src/image/p5.Image.js:684"},{message:"unknown tag: alt",line:" src/image/pixels.js:14"},{message:"unknown tag: alt",line:" src/image/pixels.js:83"},{message:"unknown tag: alt",line:" src/image/pixels.js:165"},{message:"unknown tag: alt",line:" src/image/pixels.js:212"},{message:"unknown tag: alt",line:" src/image/pixels.js:390"},{message:"unknown tag: alt",line:" src/image/pixels.js:461"},{message:"unknown tag: alt",line:" src/image/pixels.js:498"},{message:"unknown tag: alt",line:" src/image/pixels.js:572"},{message:"unknown tag: alt",line:" src/io/files.js:19"},{message:"unknown tag: alt",line:" src/io/files.js:145"},{message:"unknown tag: alt",line:" src/io/files.js:237"},{message:"unknown tag: alt",line:" src/io/files.js:558"},{message:"unknown tag: alt",line:" src/io/files.js:1194"},{message:"unknown tag: alt",line:" src/io/files.js:1248"},{message:"unknown tag: alt",line:" src/io/files.js:1306"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:58"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:121"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:170"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:215"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:263"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:329"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:498"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:551"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:593"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:757"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:826"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:875"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:937"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:984"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:1029"},{message:"unknown tag: alt",line:" src/io/p5.Table.js:1077"},{message:"unknown tag: alt",line:" src/io/p5.XML.js:11"},{message:"unknown tag: alt",line:" src/math/calculation.js:12"},{message:"unknown tag: alt",line:" src/math/calculation.js:36"},{message:"unknown tag: alt",line:" src/math/calculation.js:76"},{message:"unknown tag: alt",line:" src/math/calculation.js:130"},{message:"unknown tag: alt",line:" src/math/calculation.js:184"},{message:"unknown tag: alt",line:" src/math/calculation.js:234"},{message:"unknown tag: alt",line:" src/math/calculation.js:273"},{message:"unknown tag: alt",line:" src/math/calculation.js:317"},{message:"unknown tag: alt",line:" src/math/calculation.js:371"},{message:"unknown tag: alt",line:" src/math/calculation.js:409"},{message:"unknown tag: alt",line:" src/math/calculation.js:464"},{message:"unknown tag: alt",line:" src/math/calculation.js:507"},{message:"unknown tag: alt",line:" src/math/calculation.js:550"},{message:"unknown tag: alt",line:" src/math/calculation.js:602"},{message:"unknown tag: alt",line:" src/math/calculation.js:636"},{message:"unknown tag: alt",line:" src/math/calculation.js:675"},{message:"unknown tag: alt",line:" src/math/calculation.js:720"},{message:"unknown tag: alt",line:" src/math/noise.js:41"},{message:"unknown tag: alt",line:" src/math/noise.js:171"},{message:"unknown tag: alt",line:" src/math/noise.js:233"},{message:"unknown tag: alt",line:" src/math/p5.Vector.js:13"},{message:"unknown tag: alt",line:" src/math/random.js:47"},{message:"unknown tag: alt",line:" src/math/random.js:78"},{message:"unknown tag: alt",line:" src/math/random.js:168"},{message:"unknown tag: alt",line:" src/math/trigonometry.js:134"},{message:"unknown tag: alt",line:" src/math/trigonometry.js:174"},{message:"unknown tag: alt",line:" src/math/trigonometry.js:206"},{message:"unknown tag: alt",line:" src/math/trigonometry.js:238"},{message:"unknown tag: alt",line:" src/math/trigonometry.js:320"},{message:"unknown tag: alt",line:" src/typography/attributes.js:13"},{message:"unknown tag: alt",line:" src/typography/attributes.js:63"},{message:"unknown tag: alt",line:" src/typography/attributes.js:100"},{message:"unknown tag: alt",line:" src/typography/attributes.js:133"},{message:"unknown tag: alt",line:" src/typography/attributes.js:158"},{message:"unknown tag: alt",line:" src/typography/loading_displaying.js:16"},{message:"unknown tag: alt",line:" src/typography/loading_displaying.js:135"},{message:"unknown tag: alt",line:" src/typography/loading_displaying.js:197"},{message:"unknown tag: alt",line:" src/typography/p5.Font.js:47"},{message:"unknown tag: alt",line:" src/utilities/conversion.js:12"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:15"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:44"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:146"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:257"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:339"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:404"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:454"},{message:"unknown tag: alt",line:" src/utilities/string_functions.js:550"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:12"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:34"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:56"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:78"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:101"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:123"},{message:"unknown tag: alt",line:" src/utilities/time_date.js:145"},{message:"unknown tag: alt",line:" src/webgl/camera.js:12"},{message:"unknown tag: alt",line:" src/webgl/camera.js:160"},{message:"unknown tag: alt",line:" src/webgl/camera.js:232"},{message:"unknown tag: alt",line:" src/webgl/light.js:40"},{message:"unknown tag: alt",line:" src/webgl/light.js:89"},{message:"unknown tag: alt",line:" src/webgl/light.js:168"},{message:"unknown tag: alt",line:" src/webgl/loading.js:35"},{message:"unknown tag: alt",line:" src/webgl/loading.js:197"},{message:"unknown tag: alt",line:" src/webgl/material.js:81"},{message:"unknown tag: alt",line:" src/webgl/material.js:113"},{message:"unknown tag: alt",line:" src/webgl/material.js:210"},{message:"unknown tag: alt",line:" src/webgl/material.js:253"},{message:"unknown tag: alt",line:" src/webgl/p5.RendererGL.js:352"},{message:"unknown tag: alt",line:" src/webgl/p5.RendererGL.js:400"},{message:"unknown tag: alt",line:" src/webgl/p5.RendererGL.js:431"},{message:"unknown tag: alt",line:" src/webgl/p5.RendererGL.js:460"},{message:"unknown tag: alt",line:" src/webgl/p5.RendererGL.js:505"},{message:"unknown tag: alt",line:" src/webgl/primitives.js:13"},{message:"replacing incorrect tag: params with param",line:" lib/addons/p5.sound.js:1577"},{message:"replacing incorrect tag: returns with return",line:" lib/addons/p5.sound.js:1577"},{message:"replacing incorrect tag: returns with return",line:" lib/addons/p5.sound.js:8218"},{ message:"Missing item type\nConversions adapted fromGeneric class for handling tabular data, typically from a\nCSV, TSV, or other sort of spreadsheet file.
\nCSV files are\n\ncomma separated values, often with the data in quotes. TSV\nfiles use tabs as separators, and usually don\'t bother with the\nquotes.
\nFile names should end with .csv if they\'re comma separated.
\nA rough "spec" for CSV can be found\nhere.
\nTo load files, use the loadTable method.
\nTo save tables to your computer, use the save method\n or the saveTable method.
\n\nPossible options include:\n