-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.js
More file actions
70 lines (59 loc) · 1.73 KB
/
tree.js
File metadata and controls
70 lines (59 loc) · 1.73 KB
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
(function() {
var Tree, averageColors;
console.log("Remember to compile!");
Tree = (function() {
function Tree(properties) {
this.properties = properties;
this.jqSelector = this.properties.jqSelector;
this.canvas = this.jqSelector.get(0);
this.ctx = this.canvas.getContext("2d");
this.trunk = new Branch({
position: [this.canvas.width / 2, this.canvas.height * .8],
velocity: [0, -1],
color: "#000000"
});
console.log(this.trunk);
}
Tree.prototype.step = function(count) {
if (count == null) {
count = 1;
}
this.trunk.step(count);
return this.trunk.draw(this.ctx);
};
Tree.prototype.clearScreen = function() {
this.ctx.save();
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
return this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
};
return Tree;
})();
window.Tree = Tree;
averageColors = function(col1, col2, weight1, weight2) {
var c1, c2, c3;
if (weight1 == null) {
weight1 = 1;
}
if (weight2 == null) {
weight2 = 1;
}
col1 = parseInt(col1.replace("#", ""), 16);
col2 = parseInt(col2.replace("#", ""), 16);
c1 = {
r: col1 >> 16 & 0xFF,
g: col1 >> 8 & 0xFF,
b: col1 & 0xFF
};
c2 = {
r: col2 >> 16 & 0xFF,
g: col2 >> 8 & 0xFF,
b: col2 & 0xFF
};
c3 = new Object();
c3.r = (c1.r * weight1 + c2.r * weight2) / (weight1 + weight2);
c3.g = (c1.g * weight1 + c2.g * weight2) / (weight1 + weight2);
c3.b = (c1.b * weight1 + c2.b * weight2) / (weight1 + weight2);
return "#" + ((c3.r << 16) | (c3.g << 8) | c3.b).toString(16);
};
window.averageColors = averageColors;
}).call(this);