-
Notifications
You must be signed in to change notification settings - Fork 0
/
g2_SVG.html
72 lines (61 loc) · 2.87 KB
/
g2_SVG.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
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kurbelschleife-exzentrisch g2 SVG</title>
</head>
<body>
<h1 style="text-align:center;width:98vw">Kurbelschleife-exzentrisch</h1>
<pre id="out">?</pre>
<button onclick="c.correct();g.exe(ctx);c.log()">correct</button><br>
<canvas id="c" width="601" height="401" style="border:1px solid black;background-color:transparent"></canvas><br>
<span id="out"></span>
<span id="svg" data-width="200" data-height="100"></span>
<script src="./../g2-ng/g2.js"></script>
<script src="./../cstr2/cstr.js"></script>
<script src="./lib/g2.svg.min.js"></script>
<script>
const ctx = document.getElementById('c').getContext('2d');
const interactor = canvasInteractor.create(ctx, { x: 200, y: 200, cartesian: true });
const selector = g2.selectorHdl(interactor.evt); // sharing 'evt' object ... !
const e = 60;
const A0 = { x: 0, y: 0, base: true, label: 'A0', lbloc: 's', lbloc: 's' };
const B0 = { x: 3 * e, y: 0, base: true, label: 'B0', lbloc: 's', lbloc: 's' };
const A = { x: e, y: 0, m: 10, label: 'A', lbloc: 'n' };
const B = { x: e, y: -e, m: 1 };
const C = { x: 5 * e, y: e, m: 1 };
const g = g2().clr() // important with 'interaction'
.view(interactor.view) // important also !
// .grid()
.lin({ p1: A0, p2: A, ls: 'navy', lw: 3 })
.ply({ pts: [A, B, C], ls: 'navy', lw: 3 })
.gnd(A0) // grounds, joints
.gnd(B0) // grounds, joints
.hdl(A)
const c = cstr().n2({ id: 'A0A', n1: A0, n2: A, len: 'const' })
.n2({ id: 'AB', n1: A, n2: B, len: 'const' })
.n2({ id: 'BC', n1: B, n2: C, len: 'const' })
.n2({ id: 'AC', n1: A, n2: C, len: 'const' })
// .n3({id:'BAC',n1:B,n2:A,n3:C,ang:'const'})
.n3({ id: 'BB0C', n1: B, n2: B0, n3: C, ang: 0 })
let itrpeak = 0;
interactor
.on('tick', (e) => {
const itr = c.correct();
document.getElementById('out').innerHTML = `max/itr= ${itrpeak = Math.max(itr, itrpeak)} / ${itr}`;
g.exe(selector).exe(ctx);
})
.on('pan', (e) => { interactor.view.x += e.dx; interactor.view.y += e.dy; })
.on('drag', (e) => {
if (selector.selection && selector.selection.drag) {
selector.selection.drag({ x: e.xusr, y: e.yusr, dx: e.dxusr, dy: e.dyusr, mode: 'drag' });
}
})
.startTimer();
function exportSVG(){
g.exe(document.getElementById("svg"));
}
</script>
</body>
</html>