-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweight.html
53 lines (47 loc) · 1.75 KB
/
weight.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
<!DOCTYPE html>
<meta charset=UTF-8>
<title>Node Weight Demo</title>
<canvas id=canvas width=800 height=600>No <canvas> support</canvas>
<input id=monitor>
<script src=splines.js></script>
<script>"use strict";
/*
Node weight demo
Copyright (C) 2015 Jona Stubbe
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
var ctx = document.getElementById('canvas').getContext('2d');
var monitor = document.getElementById('monitor');
var cpoints = [[0,600,1],[400,0,1],[800,600,1]];
var knots = [0,0,0,1,1,1];
var step = 0.01;
var pos = 0;
var controlMesh = function(ctx, cpoints) {
ctx.beginPath();
ctx.moveTo(cpoints[0][0],cpoints[0][1]);
var len = cpoints.length|0;
for (var i = 0; i<len; i = i+1|0)
ctx.lineTo(cpoints[i][0],cpoints[i][1]);
ctx.stroke();
};
animation(function(pos) {
ctx.clearRect(0,0,800,600);
var cp_cp = cpoints.slice();
var weight = .5 + 1.5*pos;
monitor.value = weight;
cp_cp[1] = [cpoints[1][0]*weight,cpoints[1][1]*weight,cpoints[1][2]*weight];
ctx.strokeStyle = "black";
bSpline(ctx, 2, cp_cp, knots);
ctx.strokeStyle = "red";
controlMesh(ctx, cpoints);
});
</script>