Skip to content

Commit a7d11e5

Browse files
author
lauren mccarthy
committed
docs
1 parent 6981688 commit a7d11e5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/addons/p5.dom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ var p5DOM = (function(){
7575
* elements created by createCanvas or createGraphics.
7676
* Event handlers are removed, and element is removed from the DOM.
7777
* @method removeElements
78+
* @example
7879
* <div class='norender'><code>
7980
* function setup() {
8081
* createCanvas(100, 100);

src/objects/p5.Element.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,36 @@ define(function(require) {
106106
*
107107
* @method mousePressed
108108
* @param {Function} fxn function to be fired when mouse is
109-
* pressed over the element.
109+
* pressed over the element.
110+
* @example
111+
* <div class='norender'><code>
112+
* var cnv;
113+
* var d;
114+
* var g;
115+
* function setup() {
116+
* cnv = createCanvas(100, 100);
117+
* cnv.mousePressed(changeGray); // attach listener for
118+
* // canvas click only
119+
* d = 10;
120+
* g = 100;
121+
* }
122+
*
123+
* function draw() {
124+
* background(g);
125+
* ellipse(width/2, height/2, d, d);
126+
* }
127+
*
128+
* // this function fires with any click anywhere
129+
* function mousePressed() {
130+
* d = d + 10;
131+
* }
132+
*
133+
* // this function fires only when cnv is clicked
134+
* function changeGray() {
135+
* g = random(0, 255);
136+
* }
137+
* </code></div>
138+
*
110139
*/
111140
p5.Element.prototype.mousePressed = function (fxn) {
112141
attachListener('mousedown', fxn, this);

0 commit comments

Comments
 (0)