This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 863
/
graphing_points.html
378 lines (342 loc) · 19.5 KB
/
graphing_points.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE html>
<html data-require="math interactive graphie">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Graphing points</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="problems">
<div id="plot-point" data-weight="2">
<div class="vars">
<var id="ORIGIN">rand(3) === 0</var>
<var id="X, Y">ORIGIN ? [0, 0] : [randRange(0, 10), randRange(0, 10)]</var>
</div>
<div class="question">
<p data-if="ORIGIN">Plot a point on the <b>origin</b> by clicking on the graph.</p>
<p data-else="">Plot <code>(<var>X</var>, <var>Y</var>)</code> by clicking on the graph.</p>
</div>
<div class="problem">
<div class="graphie" id="grid">
graphInit({
range: [ [-1, 11], [-1, 11] ],
scale: 30,
axisArrows: "<->",
tickStep: 1,
labelStep: 1,
gridOpacity: 0.05,
axisOpacity: 0.2,
tickOpacity: 0.4,
labelOpacity: 0.5
});
//label( [ 0, 11 ], "y", "above" );
//label( [ 11, 0 ], "x", "right" );
graph.guess = [-1, -1];
graph.addPoint = function(coord) {
if (graph.point) {
graph.point.remove();
}
var pos = _.map(coord, function(i) { return round(max(0, i) * 2) * 0.5; })
graph.point = circle(pos, 0.2, { fill: ORANGE, stroke: null });
graph.guess = pos;
}
addMouseLayer({ onClick: graph.addPoint });
graph.showCorrect = function() {
graph.addPoint([X, Y]);
};
</div>
</div>
<div class="solution" data-type="custom">
<div class="instruction">
Click on the graph to plot a point.
</div>
<div class="guess">graph.guess</div>
<div class="validator-function">
if (guess[0] === -1 && guess[1] === -1) {
return "You need to click on the graph.";
}
return (guess[0] === X && guess[1] === Y);
</div>
<div class="show-guess">
graph.addPoint(guess);
</div>
</div>
<div class="hints">
<p data-if="ORIGIN">
The origin is at point <code>(0, 0)</code>, where the <code>x</code>-axis and <code>y</code>-axis intersect.
</p>
<div data-else="" data-unwrap="">
<p>Coordinates are listed as <code>(\blue{x},\green{y})</code>.</p>
<p>
So, for <code>( \blue{<var>X</var>}, \green{<var>Y</var>} )</code> our
<span class="hint_blue"><code>x</code>-coordinate</span> is <code class="hint_blue"><var>X</var></code> and our
<span class="hint_green"><code>y</code>-coordinate</span> is <code class="hint_green"><var>Y</var></code>.</p>
<p>
The <span class="hint_blue"><code>x</code>-coordinate</span> tells how far we move to the right from the origin and
the <span class="hint_green"><code>y</code>-coordinate</span> tells us how far we move up from the origin.
</p>
<div>
<div data-if="X === 0">
Since our <span class="hint_blue"><code>x</code>-coordinate</span>
is equal to <code class="hint_blue">0</code>, we don't need to move to the right of the origin.
</div>
<div data-else="">
<p>
Since our <span class="hint_blue"><code>x</code>-coordinate</span>
is equal to <code class="hint_blue"><var>X</var></code>,
we move <code class="hint_blue"><var>X</var></code> to the right of the origin.
</p>
<div class="graphie" data-update="grid">
style({
stroke: BLUE,
strokeWidth: 3,
arrows: "->"
}, function() {
line( [ 0, 0 ], [ X, 0 ]);
});
</div>
</div>
</div>
<div>
<div data-if="Y === 0">
Since our <span class="hint_green"><code>y</code>-coordinate</span>
is equal to <code class="hint_green">0</code>, we don't need to move up from the origin.
</div>
<div data-else="">
<p>
Since our <span class="hint_green"><code>y</code>-coordinate</span>
is equal to <code class="hint_green"><var>Y</var></code>,
we move up <code class="hint_green"><var>Y</var></code> from the origin.
</p>
<div class="graphie" data-update="grid">
style({
stroke: GREEN,
strokeWidth: 3,
arrows: "->"
}, function() {
line( [ X, 0 ], [ X, Y ] );
});
if (graph.point) {
graph.point.toFront();
}
</div>
</div>
</div>
</div>
<div>
<p>
Plot a point at <code>(\blue{<var>X</var>}, \green{<var>Y</var>})</code>, marked above.
<input onclick="javascript:KhanUtil.currentGraph.graph.showCorrect();" type="button" value="Show me">
</p>
<div class="graphie" data-update="grid">
style({
stroke: PINK,
strokeWidth: 3
}, function() {
line( [ X - 0.25, Y - 0.25 ], [ X + 0.25, Y + 0.25 ] );
line( [ X + 0.25, Y - 0.25 ], [ X - 0.25, Y + 0.25 ] );
});
if (graph.point) {
graph.point.toFront();
}
</div>
</div>
</div>
</div>
<div id="plot-axis" data-type="plot-point" data-weight="1">
<div class="vars">
<var id="X, Y">shuffle([0, randRange(1, 10)])</var>
<var id="X_AXIS">Y === 0</var>
</div>
<div class="question">
<p data-if="X_AXIS">Plot a point on the <code>x</code>-axis by clicking on the graph.</p>
<p data-else="">Plot a point on the <code>y</code>-axis by clicking on the graph.</p>
</div>
<div class="solution" data-type="custom">
<div class="instruction">
Click on the graph to plot a point.
</div>
<div class="guess">graph.guess</div>
<div class="validator-function">
if (guess[0] === -1 && guess[1] === -1) {
return "You need to click on the graph.";
}
return (X_AXIS && guess[1] === 0) || (!X_AXIS && guess[0] === 0);
</div>
<div class="show-guess">
graph.addPoint(guess);
</div>
</div>
<div class="hints">
<div data-if="X_AXIS" data-unwrap="">
<p>The <code>x</code>-axis is the horizontal axis.</p>
<div>
<p>The <code>x</code>-axis includes all the points where <code>y = 0</code>.</p>
<div class="graphie" data-update="grid">
style({
stroke: BLUE,
strokeWidth: 3,
arrows: "->"
}, function() {
line([-0.8, 0], [11, 0]);
line([10.8, 0], [-1, 0]);
});
</div>
</div>
</div>
<div data-else="" data-unwrap="">
<p>The <code>y</code>-axis is the vertical axis.</p>
<div>
<p>The <code>y</code>-axis includes all the points where <code>x = 0</code>.</p>
<div class="graphie" data-update="grid">
style({
stroke: BLUE,
strokeWidth: 3,
arrows: "->"
}, function() {
line([0, -0.8], [0, 11]);
line([0, 10.8], [0, -1]);
});
</div>
</div>
</div>
<p>
Plot a point to anywhere on the blue line.
<input onclick="javascript:KhanUtil.currentGraph.graph.showCorrect();" type="button" value="Show me">
</p>
</div>
</div>
<div id="give-coord">
<div class="vars">
<var id="X">randRange(0, 10)</var>
<var id="Y">randRange(0, 10)</var>
<var id="COORD">randFromArray(["x", "y"])</var>
<var id="ANSWER">COORD === "x" ? X : Y</var>
</div>
<div class="question">
<p>What is the <code><var>COORD</var></code>-coordinate of the point plotted below?</p>
</div>
<div class="render-answer-area-here"></div>
<div class="problem">
<div class="graphie" id="grid">
graphInit({
range: [ [-1, 12], [-1, 12] ],
gridRange: [ [-1, 11], [-1, 11] ],
scale: 30,
axisArrows: "<->",
tickStep: 1,
labelStep: 1,
gridOpacity: 0.05,
axisOpacity: 0.2,
tickOpacity: 0.4,
labelOpacity: 0.5
});
label( [ 0, 11 ], "y", "above" );
label( [ 11, 0 ], "x", "right" );
graph.point = circle([X, Y], 0.2, { fill: BLUE, stroke: null });
</div>
</div>
<div class="solution" data-form="integer"><var>ANSWER</var></div>
<div class="hints">
<div data-if="COORD === 'x'" data-unwrap="">
<p>The <code>x</code>-coordinate tells how far we move to the right from the origin.</p>
<div>
<p data-if="X === 1">The point is <code><var>X</var></code> unit to the right of the origin.</p>
<p data-else="">The point is <code><var>X</var></code> units to the right of the origin.</p>
<div data-if="X !== 0" class="graphie" data-update="grid">
style({
stroke: PINK,
strokeWidth: 3,
arrows: "->"
}, function() {
line([0, Y], [X, Y]);
});
graph.point.toFront();
</div>
</div>
</div>
<div data-else="" data-unwrap="">
<p>The <code>y</code>-coordinate tells how far we move up from the origin.</p>
<div>
<p data-if="Y === 1">The point is <code><var>Y</var></code> unit up from the origin.</p>
<p data-else="">The point is <code><var>Y</var></code> units up from the origin.</p>
<div data-if="Y !== 0" class="graphie" data-update="grid">
style({
stroke: PINK,
strokeWidth: 3,
arrows: "->"
}, function() {
line([X, 0], [X, Y]);
});
graph.point.toFront();
</div>
</div>
</div>
<p>So the <code><var>COORD</var></code>-coordinate is <code><var>ANSWER</var></code>.</p>
</div>
</div>
<div id="give-coord-both" data-type="give-coord">
<div class="vars">
<var id="X">randRange(0, 10)</var>
<var id="Y">randRange(0, 10)</var>
</div>
<div class="question">
<p>What are the coordinates of the point plotted below?</p>
</div>
<div class="render-answer-area-here"></div>
<div class="solution" data-type="multiple">
<code>(\ </code><span class="sol short32"><var>X</var></span>
<code>, \ </code><span class="sol short32"><var>Y</var></span><code>\ )</code>
</div>
<div class="hints">
<p>Coordinates are listed as <code>(\pink{x},\green{y})</code>.</p>
<p>
The <span class="hint_pink"><code>x</code>-coordinate</span> tells how far we move to the right from the origin and
the <span class="hint_green"><code>y</code>-coordinate</span> tells us how far we move up from the origin.
</p>
<div>
<p data-if="X === 1">
Since the point is <code>\pink{<var>X</var>}</code> unit to the right of the origin,
the <span class="hint_pink"><code>x</code>-coordinate</span> is equal to <code>\pink{<var>X</var>}</code>.
</p><p data-else="">
Since the point is <code>\pink{<var>X</var>}</code> units to the right of the origin,
the <span class="hint_pink"><code>x</code>-coordinate</span> is equal to <code>\pink{<var>X</var>}</code>.
</p>
<div class="graphie" data-update="grid">
style({
stroke: PINK,
strokeWidth: 3,
arrows: "->"
}, function() {
line([0, Y], [X, Y]);
});
graph.point.toFront();
</div>
</div>
<div>
<p data-if="Y === 1">
Since the point is <code>\green{<var>Y</var>}</code> unit up from the origin,
the <span class="hint_green"><code>y</code>-coordinate</span> is equal to <code>\green{<var>Y</var>}</code>.
</p><p data-else="">
Since the point is <code>\green{<var>Y</var>}</code> units up from the origin,
the <span class="hint_green"><code>y</code>-coordinate</span> is equal to <code>\green{<var>Y</var>}</code>.
</p>
<div class="graphie" data-update="grid">
style({
stroke: GREEN,
strokeWidth: 3,
arrows: "->"
}, function() {
line([X,0], [X, Y]);
});
graph.point.toFront();
</div>
</div>
<p>So the coordinates are <code>(\pink{<var>X</var>}, \green{<var>Y</var>})</code>.</p>
</div>
</div>
</div>
</div>
</body>
</html>