-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbezierStupen.html
144 lines (132 loc) · 5.65 KB
/
bezierStupen.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
<!DOCTYPE html>
<html lang="cs-cz">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Zvýšení stupně Bézierovy křivky beze změny jejího tvaru</title>
<script charset="UTF-8" src="jsxgraphcore.js" type="text/javascript"></script>
<link href="jsxgraph.css" rel="stylesheet" type="text/css"/>
<link href="darkModeStyle.css" rel="stylesheet" type="text/css"/>
<link href="appletStyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<header>
<div class="header1"><h1>Zvýšení stupně Bézierovy křivky beze změny jejího tvaru</h1></div>
<div class="user-toggle">
<div class="[ visually-hidden ][ js-mode-status ]" role="status"></div>
<button class="[ toggle-button ] [ js-mode-toggle ]">
<span class="[ toggle-button__text ] [ js-mode-toggle-text ]">Tmavý režim</span>
<span aria-hidden="true" class="toggle-button__icon"></span>
</button>
</div>
<script charset="UTF-8" src="darkMode.js" type="text/javascript"></script>
</header>
<p>
<form>
<input onClick="clean();" type="button" value="Kreslit znovu">
<input onClick="zvysitStupen();" type="button" value="Zvýšit stupeň">
</form>
<div class='jxgbox' id='jxgbox' style='width:400px; height:400px;'></div>
<script type='text/javascript'>
//ZAPNUTÍ A VYPNUTÍ TESTOVACÍHCH BODŮ
var test = false;
var p = [], l = [];
var poleSouradnic = [];
var c;
var poradiBodu = 0;
var getMouseCoords = function (e, i) {
var cPos = board.getCoordsTopLeftCorner(e, i),
absPos = JXG.getPosition(e, i),
dx = absPos[0] - cPos[0],
dy = absPos[1] - cPos[1];
return new JXG.Coords(JXG.COORDS_BY_SCREEN, [dx, dy], board);
},
down = function (e) {
var canCreate, i, coords, el;
if (p.length < 4) {
canCreate = true;
} else {
canCreate = false;
}
if (e[JXG.touchProperty]) {
// index of the finger that is used to extract the coordinates
i = 0;
}
coords = getMouseCoords(e, i);
for (el in board.objects) {
if (JXG.isPoint(board.objects[el]) && board.objects[el].hasPoint(coords.scrCoords[1], coords.scrCoords[2])) {
canCreate = false;
break;
}
}
if (canCreate) {
//TESTOVACÍ BODY NEBO BOD KLIKNUTÍM
if (test) {
p.push(board.create('point', [-3, 3]));
p.push(board.create('point', [-3, -3]));
l.push(board.create('segment', [p[0], p[1]], {strokeOpacity: 0.5}));
p.push(board.create('point', [3, -3]));
l.push(board.create('segment', [p[1], p[2]], {strokeOpacity: 0.5}));
p.push(board.create('point', [3, 3]));
l.push(board.create('segment', [p[2], p[3]], {strokeOpacity: 0.5}));
} else {
poleSouradnic.push([coords.usrCoords[1], coords.usrCoords[2]]);
p.push(board.create('point', [coords.usrCoords[1], coords.usrCoords[2]], {name: 'P_{' + (poradiBodu) + '}'}));
poradiBodu++;
if (p.length > 1) {
l.push(board.create('segment', [p[(p.length - 2)], p[p.length - 1]], {strokeOpacity: 0.5}));
}
}
if (p.length !== 0 && (p.length % 4) === 0) {
c = board.create('curve', JXG.Math.Numerics.bezier(p),
{strokecolor: 'blue', strokeOpacity: 0.6, strokeWidth: 5});
}
}
},
board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5], keepaspectratio: true,
showCopyright: false, axis: true
});
board.on('down', down);
var clean = function () {
board.suspendUpdate();
var i = p.length;
while (i >= 0) {
board.removeObject(p[p.length - i]);
i--;
}
board.removeObject(c);
p = [];
poradiBodu = 0;
board.unsuspendUpdate();
};
var zvysitStupen = function () {
if (p.length >= 4) {
board.suspendUpdate();
board.removeObject(p);
board.removeObject(l);
var q = [];
q.push(board.create('point', [p[0].X(), p[0].Y()], {fixed: true, name: 'P_0'}));
for (var i = 0; i < p.length - 1; i++) {
var t = 1 - ((i + 1) / p.length);
var vzdalenost_x = p[i + 1].X() - p[i].X();
var vzdalenost_y = p[i].Y() - p[i + 1].Y();
var pos_x = p[i].X() + vzdalenost_x * t;
var pos_y = p[i].Y() - vzdalenost_y * t;
q.push(board.create('point', [pos_x, pos_y], {fixed: true, name: 'P_{' + (i + 1) + '}'}));
l.push(board.create('segment', [q[q.length - 2], q[q.length - 1]], {strokeOpacity: 0.5}));
}
q.push(board.create('point', [p[p.length - 1].X(), p[p.length - 1].Y()], {
fixed: true,
name: 'P_{' + (i + 1) + '}'
}));
l.push(board.create('segment', [q[q.length - 2], q[q.length - 1]], {strokeOpacity: 0.5}));
p = [];
p = q.slice();
board.unsuspendUpdate();
}
};
</script>
</p>
</body>
</html>