@@ -2,12 +2,12 @@ function Particle(point,velocity){
22 this . position = point ;
33 this . velocity = velocity ;
44 this . acceleration = new Vector ( 0 , 0 ) ;
5- this . size = 3 ;
65 this . ttl = - 1 ;
76 this . lived = 0 ;
87}
98
10- Particle . globalDrawColor = "#437EDE" ;
9+ Particle . GLOBAL_DRAW_COLOR = [ 66 , 167 , 222 , 255 ] ;
10+ //Particle.GLOBAL_DRAW_COLOR = [166,67,0,255];
1111
1212Particle . prototype . submitToFields = function ( fields ) {
1313 var totalAccelerationX = 0 ;
@@ -33,14 +33,75 @@ Particle.prototype.move = function() {
3333 this . position . y += this . velocity . y ;
3434} ;
3535
36- Particle . prototype . drawSize = function ( display ) {
37- var halfSize = this . size / 2 ;
38- display . context . fillRect ( this . position . x - halfSize , this . position . y - halfSize , this . size , this . size ) ;
36+ Particle . prototype . drawVariable = function ( pixels , width , height ) {
37+ var baseIndex = 4 * ( ~ ~ this . position . y * width + ~ ~ this . position . x ) ;
38+ var velocity = this . velocity . getMagnitude ( ) ;
39+ var r = Particle . GLOBAL_DRAW_COLOR [ 0 ] * velocity ;
40+ var g = Particle . GLOBAL_DRAW_COLOR [ 1 ] ;
41+ var b = Particle . GLOBAL_DRAW_COLOR [ 2 ] * .5 / velocity ;
42+ var a = Particle . GLOBAL_DRAW_COLOR [ 3 ] ;
43+ pixels [ baseIndex ] += r ;
44+ pixels [ baseIndex + 1 ] += g ;
45+ pixels [ baseIndex + 2 ] += b ;
46+ pixels [ baseIndex + 3 ] = a ;
3947}
4048
41- Particle . prototype . drawQuick = function ( display ) {
42- display . context . moveTo ( this . position . x , this . position . y ) ;
43- display . context . lineTo ( this . position . x + .8 , this . position . y + .8 ) ;
49+ Particle . prototype . drawBasic = function ( pixels , width , height ) {
50+ var baseIndex = 4 * ( ~ ~ this . position . y * width + ~ ~ this . position . x ) ;
51+ var r = Particle . GLOBAL_DRAW_COLOR [ 0 ] ;
52+ var g = Particle . GLOBAL_DRAW_COLOR [ 1 ] ;
53+ var b = Particle . GLOBAL_DRAW_COLOR [ 2 ] ;
54+ var a = Particle . GLOBAL_DRAW_COLOR [ 3 ] ;
55+ pixels [ baseIndex ] += r ;
56+ pixels [ baseIndex + 1 ] += g ;
57+ pixels [ baseIndex + 2 ] += b ;
58+ pixels [ baseIndex + 3 ] = a ;
4459}
4560
46- Particle . prototype . draw = Particle . prototype . drawQuick ;
61+ Particle . prototype . drawSoft = function ( pixels , width , height ) {
62+ var baseIndex = 4 * ( ~ ~ this . position . y * width + ~ ~ this . position . x ) ;
63+ var r = Particle . GLOBAL_DRAW_COLOR [ 0 ] ;
64+ var g = Particle . GLOBAL_DRAW_COLOR [ 1 ] ;
65+ var b = Particle . GLOBAL_DRAW_COLOR [ 2 ] ;
66+ var a = Particle . GLOBAL_DRAW_COLOR [ 3 ] ;
67+ pixels [ baseIndex - 4 ] += r * .80 ;
68+ pixels [ baseIndex - 3 ] += g * .80 ;
69+ pixels [ baseIndex - 2 ] += b * .80 ;
70+ pixels [ baseIndex - 1 ] = a ;
71+ pixels [ baseIndex ] += r * .80 ;
72+ pixels [ baseIndex + 1 ] += g * .80 ;
73+ pixels [ baseIndex + 2 ] += b * .80 ;
74+ pixels [ baseIndex + 3 ] = a ;
75+ pixels [ baseIndex + 4 ] += r * .80 ;
76+ pixels [ baseIndex + 5 ] += g * .80 ;
77+ pixels [ baseIndex + 6 ] += b * .80 ;
78+ pixels [ baseIndex + 7 ] = a ;
79+ baseIndex += width * 4 ;
80+ pixels [ baseIndex - 4 ] += r * .80 ;
81+ pixels [ baseIndex - 3 ] += g * .80 ;
82+ pixels [ baseIndex - 2 ] += b * .80 ;
83+ pixels [ baseIndex - 1 ] = a ;
84+ pixels [ baseIndex ] += r ;
85+ pixels [ baseIndex + 1 ] += g ;
86+ pixels [ baseIndex + 2 ] += b ;
87+ pixels [ baseIndex + 3 ] = a ;
88+ pixels [ baseIndex + 4 ] += r * .80 ;
89+ pixels [ baseIndex + 5 ] += g * .80 ;
90+ pixels [ baseIndex + 6 ] += b * .80 ;
91+ pixels [ baseIndex + 7 ] = a ;
92+ baseIndex += width * 4 ;
93+ pixels [ baseIndex - 4 ] += r * .80 ;
94+ pixels [ baseIndex - 3 ] += g * .80 ;
95+ pixels [ baseIndex - 2 ] += b * .80 ;
96+ pixels [ baseIndex - 1 ] = a ;
97+ pixels [ baseIndex ] += r * .80 ;
98+ pixels [ baseIndex + 1 ] += g * .80 ;
99+ pixels [ baseIndex + 2 ] += b * .80 ;
100+ pixels [ baseIndex + 3 ] = a ;
101+ pixels [ baseIndex + 4 ] += r * .80 ;
102+ pixels [ baseIndex + 5 ] += g * .80 ;
103+ pixels [ baseIndex + 6 ] += b * .80 ;
104+ pixels [ baseIndex + 7 ] = a ;
105+ }
106+
107+ Particle . prototype . draw = Particle . prototype . drawBasic ;
0 commit comments