/
longfur.js
executable file
·60 lines (47 loc) · 1.21 KB
/
longfur.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
function longfur( context )
{
this.init( context );
}
longfur.prototype =
{
context: null,
points: null, count: null,
init: function( context )
{
this.context = context;
this.context.lineWidth = 1;
this.context.globalCompositeOperation = 'source-over';
this.points = new Array();
this.count = 0;
},
destroy: function()
{
},
strokeStart: function( mouseX, mouseY )
{
this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )";
},
stroke: function( mouseX, mouseY )
{
var i, size, dx, dy, d;
this.points.push( [ mouseX, mouseY ] );
for (i = 0; i < this.points.length; i++)
{
size = -Math.random();
dx = this.points[i][0] - this.points[this.count][0];
dy = this.points[i][1] - this.points[this.count][1];
d = dx * dx + dy * dy;
if (d < 4000 && Math.random() > d / 4000)
{
this.context.beginPath();
this.context.moveTo( this.points[this.count][0] + (dx * size), this.points[this.count][1] + (dy * size));
this.context.lineTo( this.points[i][0] - (dx * size) + Math.random() * 2, this.points[i][1] - (dy * size) + Math.random() * 2);
this.context.stroke();
}
}
this.count ++;
},
strokeEnd: function()
{
}
}