Skip to content

Commit d90ae72

Browse files
author
lauren mccarthy
committed
fixing text to account for nostroke and nofill
1 parent e039523 commit d90ae72

File tree

4 files changed

+65
-38
lines changed

4 files changed

+65
-38
lines changed
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
var canvas, input, button, greeting;
1+
var input, button, greeting;
22

33
function setup() {
44

55
// create canvas
6-
canvas = createCanvas(400, 150);
7-
canvas.position(0, 0);
6+
createCanvas(710, 400);
87

9-
input = createInput('enter your name');
10-
input.position(10, 10);
8+
input = createInput();
9+
input.position(20, 65);
1110

1211
button = createButton('submit');
13-
button.position(140, 10);
12+
button.position(150, 65);
1413
button.mousePressed(greet);
1514

16-
greeting = createElement('h1');
17-
greeting.position(10, 15);
18-
greeting.size(380, 300);
19-
noStroke();
15+
greeting = createElement('h2', 'what is your name?');
16+
greeting.position(20, 5);
2017

18+
textAlign(CENTER)
19+
textSize(50);
2120
}
2221

2322
function greet() {
2423
var name = input.value();
2524
greeting.html('hello '+name+'!');
26-
27-
background(random(255), random(255), random(255));
28-
for (var i=0; i<name.length; i++) {
29-
ellipse(random(width), random(height), 20, 20);
25+
input.value('');
26+
27+
for (var i=0; i<200; i++) {
28+
push();
29+
fill(random(255), 255, 255);
30+
translate(random(width), random(height));
31+
rotate(random(2*PI));
32+
text(name, 0, 0);
33+
pop();
3034
}
3135
}

lib/p5.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,8 +4198,12 @@ var typographyloading_displaying = function (require, core, canvas) {
41984198
p5.prototype.text = function () {
41994199
this.canvas.getContext('2d').font = this._textStyle + ' ' + this._textSize + 'px ' + this._textFont;
42004200
if (arguments.length === 3) {
4201-
this.canvas.getContext('2d').fillText(arguments[0], arguments[1], arguments[2]);
4202-
this.canvas.getContext('2d').strokeText(arguments[0], arguments[1], arguments[2]);
4201+
if (this._doFill) {
4202+
this.canvas.getContext('2d').fillText(arguments[0], arguments[1], arguments[2]);
4203+
}
4204+
if (this._doStroke) {
4205+
this.canvas.getContext('2d').strokeText(arguments[0], arguments[1], arguments[2]);
4206+
}
42034207
} else if (arguments.length === 5) {
42044208
var words = arguments[0].split(' ');
42054209
var line = '';
@@ -4212,17 +4216,25 @@ var typographyloading_displaying = function (require, core, canvas) {
42124216
if (vals.y > vals.h) {
42134217
break;
42144218
} else if (testWidth > vals.w && n > 0) {
4215-
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
4216-
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
4219+
if (this._doFill) {
4220+
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
4221+
}
4222+
if (this._doStroke) {
4223+
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
4224+
}
42174225
line = words[n] + ' ';
42184226
vals.y += this._textLeading;
42194227
} else {
42204228
line = testLine;
42214229
}
42224230
}
42234231
if (vals.y <= vals.h) {
4224-
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
4225-
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
4232+
if (this._doFill) {
4233+
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
4234+
}
4235+
if (this._doStroke) {
4236+
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
4237+
}
42264238
}
42274239
}
42284240
};

lib/p5.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/typography/loading_displaying.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,20 @@ define(function (require) {
6363

6464
if (arguments.length === 3) {
6565

66-
this.canvas.getContext('2d').fillText(
67-
arguments[0],
68-
arguments[1],
69-
arguments[2]
70-
);
71-
this.canvas.getContext('2d').strokeText(
72-
arguments[0],
73-
arguments[1],
74-
arguments[2]
75-
);
66+
if (this._doFill) {
67+
this.canvas.getContext('2d').fillText(
68+
arguments[0],
69+
arguments[1],
70+
arguments[2]
71+
);
72+
}
73+
if (this._doStroke) {
74+
this.canvas.getContext('2d').strokeText(
75+
arguments[0],
76+
arguments[1],
77+
arguments[2]
78+
);
79+
}
7680

7781
} else if (arguments.length === 5) {
7882

@@ -100,8 +104,12 @@ define(function (require) {
100104

101105
} else if (testWidth > vals.w && n > 0) {
102106

103-
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
104-
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
107+
if (this._doFill) {
108+
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
109+
}
110+
if (this._doStroke) {
111+
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
112+
}
105113
line = words[n] + ' ';
106114
vals.y += this._textLeading;
107115

@@ -113,9 +121,12 @@ define(function (require) {
113121
}
114122

115123
if (vals.y <= vals.h) {
116-
117-
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
118-
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
124+
if (this._doFill) {
125+
this.canvas.getContext('2d').fillText(line, vals.x, vals.y);
126+
}
127+
if (this._doStroke) {
128+
this.canvas.getContext('2d').strokeText(line, vals.x, vals.y);
129+
}
119130
}
120131
}
121132
};

0 commit comments

Comments
 (0)