@@ -25,6 +25,18 @@ define(function (require) {
2525 * @method textAlign
2626 * @param {Number/Constant } a horizontal alignment, either LEFT,
2727 * CENTER, or RIGHT
28+ * @example
29+ * <div>
30+ * <code>
31+ * textSize(16);
32+ * textAlign(RIGHT);
33+ * text("ABCD", 50, 30);
34+ * textAlign(CENTER);
35+ * text("EFGH", 50, 50);
36+ * textAlign(LEFT);
37+ * text("IJKL", 50, 70);
38+ * </code>
39+ * </div>
2840 */
2941 p5 . prototype . textAlign = function ( a ) {
3042 if ( a === constants . LEFT ||
@@ -39,6 +51,17 @@ define(function (require) {
3951 *
4052 * @method textHeight
4153 * @param {String } s the String of characters to measure
54+ * @example
55+ * <div>
56+ * <code>
57+ * background(0);
58+ * fill(255);
59+ * textSize(14);
60+ * s = "String.";
61+ * text(s, 10, 23);
62+ * console.log(textHeight(s));
63+ * </code>
64+ * </div>
4265 */
4366 p5 . prototype . textHeight = function ( s ) {
4467 return this . canvas . getContext ( '2d' ) . measureText ( s ) . height ;
@@ -50,6 +73,24 @@ define(function (require) {
5073 *
5174 * @method textLeading
5275 * @param {Number } l the size in pixels for spacing between lines
76+ * @example
77+ * <div>
78+ * <code>
79+ * // Text to display. The "\n" is a "new line" character
80+ * lines = "L1\nL2\nL3";
81+ * textSize(12);
82+ * fill(0); // Set fill to black
83+ *
84+ * textLeading(10); // Set leading to 10
85+ * text(lines, 10, 25);
86+ *
87+ * textLeading(20); // Set leading to 20
88+ * text(lines, 40, 25);
89+ *
90+ * textLeading(30); // Set leading to 30
91+ * text(lines, 70, 25);
92+ * </code>
93+ * </div>
5394 */
5495 p5 . prototype . textLeading = function ( l ) {
5596 this . _setProperty ( '_textLeading' , l ) ;
@@ -61,6 +102,17 @@ define(function (require) {
61102 *
62103 * @method textSize
63104 * @param {Number } s the size of the letters in units of pixels
105+ * @example
106+ * <div>
107+ * <code>
108+ * background(0);
109+ * fill(255);
110+ * textSize(26);
111+ * text("WORD", 10, 50);
112+ * textSize(14);
113+ * text("WORD", 10, 70);
114+ * </code>
115+ * </div>
64116 */
65117 p5 . prototype . textSize = function ( s ) {
66118 this . _setProperty ( '_textSize' , s ) ;
@@ -73,6 +125,22 @@ define(function (require) {
73125 * @method textStyle
74126 * @param {Number/Constant } s styling for text, either NORMAL,
75127 * ITALIC, or BOLD
128+ * @example
129+ * <div>
130+ * <code>
131+ * background(0);
132+ * fill(255);
133+ * textStyle(NORMAL);
134+ * textSize(14);
135+ * text("WORD", 10, 23);
136+ * textStyle(ITALIC);
137+ * textSize(14);
138+ * text("WORD", 10, 45);
139+ * textStyle(BOLD);
140+ * textSize(14);
141+ * text("WORD", 10, 67);
142+ * </code>
143+ * </div>
76144 */
77145 p5 . prototype . textStyle = function ( s ) {
78146 if ( s === constants . NORMAL ||
@@ -87,6 +155,17 @@ define(function (require) {
87155 *
88156 * @method textWidth
89157 * @param {String } s the String of characters to measure
158+ * @example
159+ * <div>
160+ * <code>
161+ * background(0);
162+ * fill(255);
163+ * textSize(14);
164+ * s = "String.";
165+ * text(s, 10, 23);
166+ * console.log(textWidth(s));
167+ * </code>
168+ * </div>
90169 */
91170 p5 . prototype . textWidth = function ( s ) {
92171 return this . canvas . getContext ( '2d' ) . measureText ( s ) . width ;
0 commit comments