Skip to content

Commit 8cf4009

Browse files
author
Derek Kinsman
committed
Added Typography references.
1 parent b8056b0 commit 8cf4009

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-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/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)