Skip to content

Commit ac89370

Browse files
committed
start over creating a Node prototype for our animations
1 parent bc9b329 commit ac89370

File tree

1 file changed

+15
-54
lines changed

1 file changed

+15
-54
lines changed

our_script.js

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,19 @@
1-
function makeNodes() {
2-
var paper = new Raphael(document.getElementById('canvas_container'), 1000, 500);
3-
HORIZON = 200; // the y coordinate which gives us the x-axis, e.g. y=200px;
4-
LINE_ATTRS = {stroke: '#aaa', 'stroke-width': 5};
5-
NODE_ATTRS = {stroke: '#aaa', 'stroke-width': 2, fill: 'white'};
6-
NODE_RADIUS = 50;
7-
8-
function makeLine(start, len) {
9-
var lparams = ['M', start, HORIZON, 'l', len, 0];
10-
return paper.path(lparams.join(' ')).attr(LINE_ATTRS);
11-
};
12-
13-
function makeCircle(x, y) {
14-
return paper.circle(x, y, NODE_RADIUS).attr(NODE_ATTRS);
15-
};
16-
17-
function segment(start_x) {
18-
var ARM_LEN = 50;
19-
var left_l = makeLine(start_x, ARM_LEN);
20-
var circle_x = start_x + ARM_LEN + NODE_RADIUS;
21-
var circle = makeCircle(circle_x, HORIZON);
22-
var right_l = makeLine(start_x + ARM_LEN + NODE_RADIUS*2, ARM_LEN);
23-
return paper.set(left_l, circle, right_l);
24-
};
25-
26-
function animateRequest(){
27-
var speed = 500;
28-
var req = paper.circle(0, HORIZON, 5).attr({fill: 'red'});
29-
30-
function highlightNode(){
31-
req.attr({'stroke-width': 0});
32-
redden(node[0].items[1]);
33-
paper.text(100, HORIZON, "Node 1").attr({"font-size": 12});
34-
};
35-
36-
var node1 = Raphael.animation({cx: 100, cy: HORIZON}, speed, highlightNode);
37-
req.animate(node1);
38-
};
39-
40-
function redden(node) {
41-
node.attr({fill: 'red'});
42-
};
43-
44-
function main() {
45-
for(var i = 0; i < 5; i+=1) {
46-
node[i] = segment(200*i);
47-
};
48-
};
1+
var Node = {
2+
nname: 'default',
3+
category: 'default',
4+
ndescription: 'something',
5+
color: function() {
6+
return 'tangerine';
7+
}
8+
};
499

50-
var node = [];
51-
main();
10+
var first = Object.create(Node, {
11+
nname: { value: 'first node' },
12+
category: { value: 'filter' }
13+
});
5214

53-
// events
54-
$('#canvas_container').on("click", animateRequest);
15+
var second = Object.create(Node, {nname: {value: 'second node'}})
5516

56-
};
17+
console.log(first);
18+
console.log(second);
5719

58-
$(document).ready(makeNodes);

0 commit comments

Comments
 (0)