-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
133 lines (94 loc) · 3.25 KB
/
Copy pathjs.js
File metadata and controls
133 lines (94 loc) · 3.25 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
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
/**
* @author GRNan
* @date Aug 2013
* @version 1.0
* @framework kinetic-v4.5.5.min.js
*
* */
fb = function( text ){
if ( console.debug )
console.debug( text );
else if( console.log )
console.log( text );
}
$(document).ready(function(){
kinect.init();
var tree = new Tree( 20, 60, 1.5, 1.5 );
tree.init( [200,240] );
var tree = new Tree( 20 ,60, 1.05, 1.5 );
tree.init( [600,240] );
/*
var tree = new Tree( 20, 20, 1.05, 1.5 );
tree.init( [420,200] );
var tree = new Tree( 20, 80, 1.05, 1.5 );
tree.init( [460,200] );
var tree = new Tree( 20, 40, 1.05, 1.5 );
tree.init( [499,200] );*/
});
kinect = {
stage: null,
layer: null,
init: function(){
this.stage = new Kinetic.Stage({
container: 'container',
width: 800,
height: 240
});
this.layer = new Kinetic.Layer();
}
}
/**
* @param m pendiente de crecimiento
* @param long longitud de ramas
* @param mDegradient factor de decrecimiento de m
* @param lDegradient factor de decrecimiento de l
*
* */
function Tree( m, long, mDegradient, lDegradient ){
var global = this;
this.m = m;
this.long = long;
this.mDegradient = mDegradient;
this.lDegradient = lDegradient;
this.maxIterations = 60;
this.iterations = 0;
this.draw = function( ele ){
kinect.layer.add( ele );
kinect.stage.add( kinect.layer );
}
this.drawLine = function( points, color ){
var ele = new Kinetic.Line({
points: points,
stroke: color,
strokeWidth: 0.5,
lineCap: 'round',
lineJoin: 'round'
});
this.draw( ele );
}
this.init = function( initPoints ){
if( this.iterations == this.maxIterations ) return false;
fb(this.iterations);
this.iterations++;
var id = setTimeout( function(){
var destinyPointsUp = global.getDestinyPoints( true, initPoints, global.long, global.m );
var destinyPointsDown = global.getDestinyPoints( false, initPoints, global.long, global.m );
if(destinyPointsUp === false || destinyPointsDown === false)
ret = true;
global.drawLine( initPoints.concat( destinyPointsUp ), 'red' );
global.drawLine( initPoints.concat( destinyPointsDown ), 'black' );
global.init( destinyPointsUp );
global.init( destinyPointsDown );
global.m = global.mDegradient > 0 ? global.m / global.mDegradient : global.m;
global.long = global.lDegradient > 0 ? global.long / global.lDegradient : global.long;
}, 1000);
if(this.m < 0.01){
clearTimeout(id);
}
}
this.getDestinyPoints = function( up, startPoint, long, m ){
var y = startPoint[1] - long;
var x = up ? startPoint[0] - m : startPoint[0] + m ;
return [ x , y ];
}
}