-
Notifications
You must be signed in to change notification settings - Fork 153
/
functions.ts
71 lines (59 loc) · 2.13 KB
/
functions.ts
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
// =============================================================================
// Angles and Polygons
// (c) Mathigon
// =============================================================================
import {hover} from '@mathigon/boost';
import {Point} from '@mathigon/fermat';
import {Geopad, Step} from '../shared/types';
function round(a: Point, b: Point) {
return Math.round(Point.distance(a, b) / 25) / 2;
}
export function triangleInequality($step: Step) {
$step.model.set('roundD', round);
const $items = $step.$$('.item');
const targets = $items.map(
$el => $el.$$('.t-num').map($el => ({$el, val: +$el.text})));
$step.one('score', () => {
$step.delayedHint(() => $step.addHint('inequality-impossible'), 20000);
});
$step.model.watch(s => {
const active = [round(s.a, s.b), round(s.b, s.c), round(s.a, s.c)].sort();
targets.forEach((t, i) => {
let correctCount = 0;
for (let x = 0; x < 3; ++x) {
const isCorrect = t[x].val === active[x];
t[x].$el.setClass('correct', isCorrect);
if (isCorrect) correctCount += 1;
}
if (correctCount === 3 && !$step.scores.has('s' + i)) {
$step.addHint('correct');
$step.score('s' + i);
$items[i].addClass('correct');
}
});
});
}
export function triangleInequality3($step: Step) {
const $targets = $step.$$('.hover-target');
const $geopad = $step.$('x-geopad') as Geopad;
hover($targets[0], {
enter() {
$geopad.animatePoint('a', $geopad.model.point(90, 110), 1200);
$geopad.animatePoint('b', $geopad.model.point(165, 105), 1200);
$geopad.animatePoint('c', $geopad.model.point(210, 110), 1200);
$step.score('target-0');
}
});
hover($targets[1], {
enter() {
$geopad.animatePoint('b', $geopad.model.point(50, 105), 1200);
$geopad.animatePoint('a', $geopad.model.point(130, 110), 1200);
$geopad.animatePoint('c', $geopad.model.point(250, 105), 1200);
$step.score('target-1');
}
});
const $rubber = $step.$('.rubber')!;
$geopad.model.watch(state => {
$rubber.css('stroke-width', 350 / Point.distance(state.b, state.c) + 'px');
});
}