@@ -23,8 +23,8 @@ function draw() {
2323 background ( 51 ) ;
2424
2525 for ( let i = 0 ; i < num ; i ++ ) {
26- springs [ i ] . update ( ) ;
27- springs [ i ] . display ( ) ;
26+ springs [ i ] . update ( ) ;
27+ springs [ i ] . display ( ) ;
2828 }
2929}
3030
@@ -36,7 +36,7 @@ function mousePressed() {
3636
3737function mouseReleased ( ) {
3838 for ( let i = 0 ; i < num ; i ++ ) {
39- springs [ i ] . released ( ) ;
39+ springs [ i ] . released ( ) ;
4040 }
4141}
4242
@@ -55,94 +55,94 @@ function Spring (_x, _y, _s, _d, _m, _k_in, _others, _id) {
5555 this . over = false ;
5656 this . move = false ;
5757
58- // Spring simulation constants
58+ // Spring simulation constants
5959 this . mass = _m ; // Mass
60- this . k = 0.2 ; // Spring constant
60+ this . k = 0.2 ; // Spring constant
6161 this . k = _k_in ;
6262 this . damp = _d ; // Damping
6363 this . rest_posx = _x ; // Rest position X
6464 this . rest_posy = _y ; // Rest position Y
6565
6666 // Spring simulation variables
67- //float pos = 20.0; // Position
68- this . velx = 0.0 ; // X Velocity
69- this . vely = 0.0 ; // Y Velocity
70- this . accel = 0 ; // Acceleration
71- this . force = 0 ; // Force
67+ //float pos = 20.0; // Position
68+ this . velx = 0.0 ; // X Velocity
69+ this . vely = 0.0 ; // Y Velocity
70+ this . accel = 0 ; // Acceleration
71+ this . force = 0 ; // Force
7272
7373 this . friends = _others ;
7474 this . id = _id ;
7575
7676 this . update = function ( ) {
7777
78- if ( this . move ) {
79- this . rest_posy = mouseY ;
80- this . rest_posx = mouseX ;
81- }
78+ if ( this . move ) {
79+ this . rest_posy = mouseY ;
80+ this . rest_posx = mouseX ;
81+ }
8282
83- this . force = - this . k * ( this . y_pos - this . rest_posy ) ; // f=-ky
84- this . accel = this . force / this . mass ; // Set the acceleration, f=ma == a=f/m
85- this . vely = this . damp * ( this . vely + this . accel ) ; // Set the velocity
86- this . y_pos = this . y_pos + this . vely ; // Updated position
83+ this . force = - this . k * ( this . y_pos - this . rest_posy ) ; // f=-ky
84+ this . accel = this . force / this . mass ; // Set the acceleration, f=ma == a=f/m
85+ this . vely = this . damp * ( this . vely + this . accel ) ; // Set the velocity
86+ this . y_pos = this . y_pos + this . vely ; // Updated position
8787
8888
89- this . force = - this . k * ( this . x_pos - this . rest_posx ) ; // f=-ky
90- this . accel = this . force / this . mass ; // Set the acceleration, f=ma == a=f/m
91- this . velx = this . damp * ( this . velx + this . accel ) ; // Set the velocity
92- this . x_pos = this . x_pos + this . velx ; // Updated position
89+ this . force = - this . k * ( this . x_pos - this . rest_posx ) ; // f=-ky
90+ this . accel = this . force / this . mass ; // Set the acceleration, f=ma == a=f/m
91+ this . velx = this . damp * ( this . velx + this . accel ) ; // Set the velocity
92+ this . x_pos = this . x_pos + this . velx ; // Updated position
9393
9494
95- if ( ( this . overEvent ( ) || this . move ) && ! ( this . otherOver ( ) ) ) {
96- this . over = true ;
97- } else {
98- this . over = false ;
99- }
95+ if ( ( this . overEvent ( ) || this . move ) && ! ( this . otherOver ( ) ) ) {
96+ this . over = true ;
97+ } else {
98+ this . over = false ;
99+ }
100100 }
101101
102102 // Test to see if mouse is over this spring
103103 this . overEvent = function ( ) {
104- let disX = this . x_pos - mouseX ;
105- let disY = this . y_pos - mouseY ;
106- let dis = createVector ( disX , disY ) ;
107- if ( dis . mag ( ) < this . size / 2 ) {
108- return true ;
109- } else {
110- return false ;
111- }
104+ let disX = this . x_pos - mouseX ;
105+ let disY = this . y_pos - mouseY ;
106+ let dis = createVector ( disX , disY ) ;
107+ if ( dis . mag ( ) < this . size / 2 ) {
108+ return true ;
109+ } else {
110+ return false ;
111+ }
112112 }
113113
114114 // Make sure no other springs are active
115115 this . otherOver = function ( ) {
116- for ( let i = 0 ; i < num ; i ++ ) {
117- if ( i != this . id ) {
118- if ( this . friends [ i ] . over == true ) {
119- return true ;
120- }
121- }
122- }
123- return false ;
116+ for ( let i = 0 ; i < num ; i ++ ) {
117+ if ( i != this . id ) {
118+ if ( this . friends [ i ] . over == true ) {
119+ return true ;
120+ }
121+ }
122+ }
123+ return false ;
124124 }
125125
126126 this . display = function ( ) {
127- if ( this . over ) {
128- fill ( 153 ) ;
129- } else {
130- fill ( 255 ) ;
131- }
132- ellipse ( this . x_pos , this . y_pos , this . size , this . size ) ;
127+ if ( this . over ) {
128+ fill ( 153 ) ;
129+ } else {
130+ fill ( 255 ) ;
131+ }
132+ ellipse ( this . x_pos , this . y_pos , this . size , this . size ) ;
133133 }
134134
135135 this . pressed = function ( ) {
136- if ( this . over ) {
137- this . move = true ;
138- } else {
139- this . move = false ;
140- }
136+ if ( this . over ) {
137+ this . move = true ;
138+ } else {
139+ this . move = false ;
140+ }
141141 }
142142
143143 this . released = function ( ) {
144- this . move = false ;
145- this . rest_posx = this . y_pos ;
146- this . rest_posy = this . y_pos ;
144+ this . move = false ;
145+ this . rest_posx = this . y_pos ;
146+ this . rest_posy = this . y_pos ;
147147 }
148148} ;
0 commit comments