This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
forked from sebmarkbage/art
-
Notifications
You must be signed in to change notification settings - Fork 1
/
objectmodel.js
90 lines (70 loc) · 1.71 KB
/
objectmodel.js
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
require('../mode');
var ART = require('../../index');
var art = ART.Surface(1000, 600);
var group = ART.Group()
.inject(art);
var text = ART.Text('DOM', 'bold 60px "Arial"')
.move(0, 0)
.fill('red')
.inject(group);
var green = ART.Rectangle(100, 100)
.move(10, 10)
.fill('green')
.inject(group);
var group2 = ART.Group()
.move(10,10)
.rotate(5)
.inject(group);
var blue = ART.Rectangle(100, 100)
.move(10,10)
.rotate(-5)
.fill('blue')
.inject(group2);
function eq(){
var a = arguments[0];
for (var i = 1; i < arguments.length; i++){
var b = arguments[i];
if (a !== b){ debugger; throw new Error('Assertion failed'); }
}
}
function verifyState(){
// art
// group
// text
// green
// group2
// blue
eq(art.firstChild, art.lastChild, group);
eq(group.nextSibling, group.previousSibling, null);
eq(group.firstChild, text);
eq(group.lastChild, group2);
eq(text.previousSibling, group2.nextSibling, null);
eq(text.nextSibling, green);
eq(green.previousSibling, text);
eq(green.nextSibling, group2);
eq(group2.previousSibling, green);
eq(group2.firstChild, group2.lastChild, blue);
eq(blue.nextSibling, blue.previousSibling, null);
eq(blue.parentNode, group2);
eq(text.parentNode, green.parentNode, group2.parentNode, group);
eq(group.parentNode, art);
}
verifyState();
var alt = true;
var timer = setInterval(function(){
alt = !alt;
if (alt)
green.eject();
else {
green.injectBefore(group2);
verifyState();
}
group2.rotate(1, 50, 50);
}, 500);
group2.subscribe('click', function(){
clearInterval(timer);
group.empty();
art.empty();
blue.inject(art);
});
art.inject(document.body);