Skip to content

Commit e2046b1

Browse files
committed
Added code examples to tutorial
1 parent fa1e024 commit e2046b1

File tree

2 files changed

+135
-9
lines changed

2 files changed

+135
-9
lines changed

src/data/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ learn:
418418
labeling-canvases-best-practices-using-labels-simple-1: >-
419419
For canvases without any changing, moving, or interactive elements, you may use either the <a class = "code" href="https://p5js.org/reference/#/p5/describeElement">describeElement()</a>,
420420
<a class = "code" href="https://p5js.org/reference/#/p5/gridOutput">gridOutput()</a>, or <a class = "code" href="https://p5js.org/reference/#/p5/textOutput">textOutput()</a>
421-
functions to label the canvas’ visual content. However, keep in mind that <a class = "code" href="https://p5js.org/reference/#/p5/gridOutput">gridOutput()</a> and textOutput() generate their information based on
421+
functions to label the canvas’ visual content. However, keep in mind that <a class = "code" href="https://p5js.org/reference/#/p5/gridOutput">gridOutput()</a> and <a class = "code" href="https://p5js.org/reference/#/p5/textOutput">textOutput()</a> generate their information based on
422422
the rudimentary code of the visual element, such as its size, color, and shape-- these functions won’t be able to interpret your
423423
intention in using such a shape within a larger visual built using multiple shapes.
424424
labeling-canvases-best-practices-using-labels-simple-2: >-

src/templates/pages/learn/labeling-canvases.hbs

Lines changed: 134 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,47 @@ slug: learn/
3636
<h3>{{#i18n "labeling-canvases-best-practices-what-requires-labeling"}}{{/i18n}}</h3>
3737
<p>{{#i18n "labeling-canvases-best-practices-what-requires-labeling-1"}}{{/i18n}}</p>
3838
<p>{{#i18n "labeling-canvases-best-practices-what-requires-labeling-2"}}{{/i18n}}</p>
39+
40+
41+
<!-- Code example below copied from Reference page: https://p5js.org/reference/#/p5/describe-->
42+
43+
<script type="text/p5" data-p5-version="{{ version }}">
44+
function setup() {
45+
createCanvas(100, 100);
46+
}
47+
48+
function draw() {
49+
background(255,192,203);
50+
noStroke();
51+
fill(200,0,0);
52+
53+
describeElement("Heart","Red heart in the bottom right corner.");
54+
ellipse(67, 67, 20, 20);
55+
ellipse(83, 67, 20, 20);
56+
triangle(91, 73, 75, 95, 59, 73);
57+
}
58+
</script>
59+
3960
<p>{{#i18n "labeling-canvases-best-practices-what-requires-labeling-3"}}{{/i18n}}</p>
4061
<p>{{#i18n "labeling-canvases-best-practices-what-requires-labeling-4"}}{{/i18n}}</p>
62+
63+
<script type="text/p5" data-p5-version="{{ version }}">
64+
function setup() {
65+
createCanvas(100, 100);
66+
}
67+
68+
function draw() {
69+
background(255,192,203);
70+
noStroke();
71+
fill(200,0,0);
72+
73+
textSize(12);
74+
textStyle(NORMAL);
75+
describeElement("Text", "The text 'Hello world!' in the upper left corner of a pink canvas.'");
76+
text('Hello world!', 5, 30);
77+
}
78+
</script>
79+
4180
<p><i>{{#i18n "labeling-canvases-best-practices-what-requires-labeling-5"}}{{/i18n}}</i></p>
4281

4382
<h3>{{#i18n "labeling-canvases-best-practices-dont-label"}}{{/i18n}}</h3>
@@ -48,15 +87,92 @@ slug: learn/
4887

4988
<h4>{{#i18n "labeling-canvases-best-practices-using-labels-all-canvases"}}{{/i18n}}</h4>
5089
<p>{{#i18n "labeling-canvases-best-practices-using-labels-all-canvases-1"}}{{/i18n}}</p>
90+
91+
<script type="text/p5" data-p5-version="{{ version }}">
92+
function setup() {
93+
createCanvas(100, 100);
94+
}
95+
96+
function draw() {
97+
background(250);
98+
noStroke();
99+
100+
describe("Flower with red petals and a green stem on a white canvas.");
101+
102+
fill("#0DCC23");
103+
rect(48, 50, 5, 50);
104+
105+
fill(200,0,0);
106+
ellipse(40, 55, 18);
107+
ellipse(40, 45, 18);
108+
ellipse(50, 40, 18);
109+
ellipse(60, 55, 18);
110+
ellipse(60, 45, 18);
111+
ellipse(50, 60, 18);
112+
113+
fill("#FFE200");
114+
ellipse(50,50,15);
115+
}
116+
</script>
117+
51118
<p>{{#i18n "labeling-canvases-best-practices-using-labels-all-canvases-2"}}{{/i18n}}</p>
52119

53120
<h4>{{#i18n "labeling-canvases-best-practices-using-labels-simple"}}{{/i18n}}</h4>
54121
<p>{{#i18n "labeling-canvases-best-practices-using-labels-simple-1"}}{{/i18n}}</p>
122+
123+
<script type="text/p5" data-p5-version="{{ version }}">
124+
function setup() {
125+
createCanvas(100, 100);
126+
}
127+
128+
function draw() {
129+
background(250);
130+
noStroke();
131+
132+
textOutput(LABEL);
133+
134+
fill("#0DCC23");
135+
rect(48, 50, 5, 50);
136+
137+
fill(200,0,0);
138+
ellipse(40, 55, 18);
139+
ellipse(40, 45, 18);
140+
ellipse(50, 40, 18);
141+
ellipse(60, 55, 18);
142+
ellipse(60, 45, 18);
143+
ellipse(50, 60, 18);
144+
145+
fill("#FFE200");
146+
ellipse(50,50,15);
147+
}
148+
</script>
149+
55150
<p>{{#i18n "labeling-canvases-best-practices-using-labels-simple-2"}}{{/i18n}}</p>
56151
<p>{{#i18n "labeling-canvases-best-practices-using-labels-simple-3"}}{{/i18n}}</p>
57152

58153
<h4>{{#i18n "labeling-canvases-best-practices-using-labels-interactive"}}{{/i18n}}</h4>
59154
<p>{{#i18n "labeling-canvases-best-practices-using-labels-interactive-1"}}{{/i18n}}</p>
155+
156+
<!-- Code example below copied from Reference page: https://p5js.org/reference/#/p5/describe-->
157+
158+
<script type="text/p5" data-p5-version="{{ version }}">
159+
function setup() {
160+
createCanvas(100, 100);
161+
}
162+
163+
let x = 0;
164+
function draw() {
165+
if (x > 100) {
166+
x = 0;
167+
}
168+
background(220);
169+
fill(0, 255, 0);
170+
ellipse(x, 50, 40, 40);
171+
x = x + 0.1;
172+
describe('green circle at x pos ' + round(x) + ' moving to the right', LABEL);
173+
}
174+
</script>
175+
60176
<p>{{#i18n "labeling-canvases-best-practices-using-labels-interactive-2"}}{{/i18n}}</p>
61177
<p>{{#i18n "labeling-canvases-best-practices-using-labels-interactive-3"}}{{/i18n}}</p>
62178

@@ -82,23 +198,33 @@ slug: learn/
82198

83199
<h2>{{#i18n "labeling-canvases-testing-labels"}}{{/i18n}}</h2>
84200
<p>{{#i18n "labeling-canvases-testing-labels-1"}}{{/i18n}}</p>
85-
<p>{{#i18n "labeling-canvases-testing-labels-2"}}{{/i18n}}</p>
86-
<p>{{#i18n "labeling-canvases-testing-labels-3"}}{{/i18n}}</p>
87-
<br>
88-
<p>{{#i18n "labeling-canvases-note"}}{{/i18n}}</p>
89201

90-
<!-- this script only needs to get added once even if there are multiple widget instances -->
91-
<script src="//toolness.github.io/p5.js-widget/p5-widget.js"></script>
92-
<script type="text/p5" data-p5-version="{{ version }}">
202+
<script type="text/p5" data-p5-version="{{ version }}">
93203
function setup() {
94204
createCanvas(100, 100);
95205
}
96206
97207
function draw() {
98-
background(255, 0, 200);
208+
gridOutput(LABEL);
209+
210+
background(255,192,203);
211+
noStroke();
212+
fill(200,0,0);
213+
214+
ellipse(67, 67, 20, 20);
215+
ellipse(83, 67, 20, 20);
216+
triangle(91, 73, 75, 95, 59, 73);
99217
}
100218
</script>
101219

220+
<p>{{#i18n "labeling-canvases-testing-labels-2"}}{{/i18n}}</p>
221+
<p>{{#i18n "labeling-canvases-testing-labels-3"}}{{/i18n}}</p>
222+
<br>
223+
<p>{{#i18n "labeling-canvases-note"}}{{/i18n}}</p>
224+
225+
<!-- this script only needs to get added once even if there are multiple widget instances -->
226+
<script src="//toolness.github.io/p5.js-widget/p5-widget.js"></script>
227+
102228
</main>
103229

104230
{{> footer}}

0 commit comments

Comments
 (0)