Skip to content

Commit 64edaa0

Browse files
authored
Merge pull request #552 from Rahulhanje/patch-2
Update liveSketch.js for Characters Strings example
2 parents 542cc58 + c5f040b commit 64edaa0

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

content/examples/Basics/Data/CharactersStrings/liveSketch.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
function runLiveSketch(s) {
2020
var letter = '';
2121
var words = 'Begin...';
22-
var lineHeight = 36;
23-
var bottomPadding = 5;
2422

2523
s.setup = () => {
2624
s.createCanvas(640, 360);
2725
s.textFont('Source Code Pro', 36);
28-
s.textWrap(s.CHAR);
26+
s.textWrap(s.CHAR); // Added text wrap modification
2927
};
3028

3129
s.draw = () => {
@@ -39,28 +37,15 @@ function runLiveSketch(s) {
3937
s.text('Current key: ' + letter, 50, 70);
4038
s.text('The String is ' + words.length + ' characters long', 50, 90);
4139

42-
// Calculate the number of lines of text
4340
s.textSize(36);
44-
let textWidth = 540;
45-
let textHeight = s.textAscent() + s.textDescent();
46-
47-
// Calculate the number of lines needed for the text
48-
let numLines = s.ceil(s.textWidth(words) / textWidth);
49-
let contentHeight = numLines * textHeight + 120 + bottomPadding;
50-
51-
// Resize canvas if the content height exceeds the current canvas height
52-
if (contentHeight > s.height) {
53-
s.resizeCanvas(640, contentHeight);
54-
}
55-
s.text(words, 50, 120, textWidth, s.height);
41+
s.text(words, 50, 120, 540, 300);
5642
};
5743

5844
s.keyPressed = () => {
59-
6045
if ((s.key >= 'A' && s.key <= 'z') || s.key == ' ') {
6146
letter = s.key;
6247
words = words + s.key;
6348
}
6449
};
50+
6551
}
66-

0 commit comments

Comments
 (0)