Skip to content

Commit 9608625

Browse files
author
Lauren McCarthy
committed
Merge pull request #264 from derekkinsman/master
Yuidoc reference examples for Transform & Image
2 parents e61be22 + 26cea01 commit 9608625

File tree

4 files changed

+208
-0
lines changed

4 files changed

+208
-0
lines changed

src/image/image.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ define(function (require) {
2929
* @param {Integer} width width in pixels
3030
* @param {Integer} height height in pixels
3131
* @return {p5.Image} the p5.Image object
32+
* @example
33+
* <div>
34+
* <code>
35+
* img = createImage(66, 66, RGB);
36+
* img.loadPixels();
37+
* for (i = 0; i < img.pixels.length; i++) {
38+
* img.pixels[i] = color(0, 90, 102);
39+
* }
40+
* img.updatePixels();
41+
* image(img, 17, 17);
42+
* </code>
43+
* </div>
44+
*
45+
* <div>
46+
* <code>
47+
* img = createImage(66, 66, RGB);
48+
* img.loadPixels();
49+
* for (i = 0; i < img.pixels.length; i++) {
50+
* img.pixels[i] = color(0, 90, 102, i % img.width * 2);
51+
* }
52+
* img.updatePixels();
53+
* image(img, 17, 17);
54+
* image(img, 34, 34);
55+
* </code>
56+
* </div>
3257
*/
3358
p5.prototype.createImage = function(width, height) {
3459
return new p5.Image(width, height);

src/transform/transform.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ define(function (require) {
3030
* @param {Number} n11 numbers which define the 3x2 matrix to be multiplied
3131
* @param {Number} n12 numbers which define the 3x2 matrix to be multiplied
3232
* @return {p5} the p5 object
33+
* @example
34+
* <div>
35+
* <code>
36+
* // Example in the works.
37+
* </code>
38+
* </div>
3339
*/
3440
p5.prototype.applyMatrix = function(n00, n01, n02, n10, n11, n12) {
3541
this.canvas.getContext('2d').transform(n00, n01, n02, n10, n11, n12);
@@ -48,6 +54,12 @@ define(function (require) {
4854
*
4955
* @method printMatrix
5056
* @return {p5} the p5 object
57+
* @example
58+
* <div>
59+
* <code>
60+
* // Example in the works.
61+
* </code>
62+
* </div>
5163
*/
5264
p5.prototype.printMatrix = function() {
5365
throw new Error('printMatrix() not implemented');
@@ -62,6 +74,12 @@ define(function (require) {
6274
*
6375
* @method resetMatrix
6476
* @return {p5} the p5 object
77+
* @example
78+
* <div>
79+
* <code>
80+
* // Example in the works.
81+
* </code>
82+
* </div>
6583
*/
6684
p5.prototype.resetMatrix = function() {
6785
this.canvas.getContext('2d').setTransform();
@@ -90,6 +108,14 @@ define(function (require) {
90108
* @param {Number} angle the angle of rotation, specified in radians
91109
* or degrees, depending on current angleMode
92110
* @return {p5} the p5 object
111+
* @example
112+
* <div>
113+
* <code>
114+
* translate(width/2, height/2);
115+
* rotate(PI/3.0);
116+
* rect(-26, -26, 52, 52);
117+
* </code>
118+
* </div>
93119
*/
94120
p5.prototype.rotate = function(r) {
95121
if (this._angleMode === constants.DEGREES) {
@@ -143,6 +169,22 @@ define(function (require) {
143169
* are given
144170
* @param {Number} [y] percentage to scale the object in the y-axis
145171
* @return {p5} the p5 object
172+
* @example
173+
* <div>
174+
* <code>
175+
* translate(width/2, height/2);
176+
* rotate(PI/3.0);
177+
* rect(-26, -26, 52, 52);
178+
* </code>
179+
* </div>
180+
*
181+
* <div>
182+
* <code>
183+
* rect(30, 20, 50, 50);
184+
* scale(0.5, 1.3);
185+
* rect(30, 20, 50, 50);
186+
* </code>
187+
* </div>
146188
*/
147189
p5.prototype.scale = function() {
148190
var x = 1.0, y = 1.0;
@@ -182,6 +224,14 @@ define(function (require) {
182224
* @param {Number} angle angle of shear specified in radians or degrees,
183225
* depending on current angleMode
184226
* @return {p5} the p5 object
227+
* @example
228+
* <div>
229+
* <code>
230+
* translate(width/4, height/4);
231+
* shearX(PI/4.0);
232+
* rect(0, 0, 30, 30);
233+
* </code>
234+
* </div>
185235
*/
186236
p5.prototype.shearX = function(angle) {
187237
if (this._angleMode === constants.DEGREES) {
@@ -214,6 +264,14 @@ define(function (require) {
214264
* @param {Number} angle angle of shear specified in radians or degrees,
215265
* depending on current angleMode
216266
* @return {p5} the p5 object
267+
* @example
268+
* <div>
269+
* <code>
270+
* translate(width/4, height/4);
271+
* shearY(PI/4.0);
272+
* rect(0, 0, 30, 30);
273+
* </code>
274+
* </div>
217275
*/
218276
p5.prototype.shearY = function(angle) {
219277
if (this._angleMode === constants.DEGREES) {
@@ -242,6 +300,23 @@ define(function (require) {
242300
* @param {Number} x left/right translation
243301
* @param {Number} y up/down translation
244302
* @return {p5} the p5 object
303+
* @example
304+
* <div>
305+
* <code>
306+
* translate(30, 20);
307+
* rect(0, 0, 55, 55);
308+
* </code>
309+
* </div>
310+
*
311+
* <div>
312+
* <code>
313+
* rect(0, 0, 55, 55); // Draw rect at original 0,0
314+
* translate(30, 20);
315+
* rect(0, 0, 55, 55); // Draw rect at new 0,0
316+
* translate(14, 14);
317+
* rect(0, 0, 55, 55); // Draw rect at new 0,0
318+
* </code>
319+
* </div>
245320
*/
246321
p5.prototype.translate = function(x, y) {
247322
this.canvas.getContext('2d').translate(x, y);

src/typography/attributes.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/typography/loading_displaying.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ define(function (require) {
3434
* see rectMode() for more info
3535
* @param {Number} y2 by default, the height of the text box,
3636
* see rectMode() for more info
37+
* @example
38+
* <div>
39+
* <code>
40+
* textSize(32);
41+
* text("word", 10, 30);
42+
* fill(0, 102, 153);
43+
* text("word", 10, 60);
44+
* fill(0, 102, 153, 51);
45+
* text("word", 10, 90);
46+
* </code>
47+
* </div>
48+
* <div>
49+
* <code>
50+
* s = "The quick brown fox jumped over the lazy dog.";
51+
* fill(50);
52+
* text(s, 10, 10, 70, 80); // Text wraps within text box
53+
* </code>
54+
* </div>
3755
*/
3856
p5.prototype.text = function() {
3957

@@ -107,6 +125,17 @@ define(function (require) {
107125
*
108126
* @method textFont
109127
* @param {String} str name of font
128+
* @example
129+
* <div>
130+
* <code>
131+
* fill(0);
132+
* textSize(36);
133+
* textFont("Georgia");
134+
* text("Georgia", 12, 40);
135+
* textFont("Helvetica");
136+
* text("Helvetica", 12, 90);
137+
* </code>
138+
* </div>
110139
*/
111140
p5.prototype.textFont = function(str) {
112141
this._setProperty('_textFont', str); //pend temp?

0 commit comments

Comments
 (0)