File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff 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);
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments