+\r
+ const REST_DIST_X = width / (numPointsWidth-1);\r
+ const REST_DIST_Y = height / (numPointsHeight-1);\r
+\r
+ /**\r
+ * generate constraints (springs)\r
+ */\r
+ this.constraints = [];\r
+ for (let y = 0; y < numPointsHeight; y++) {\r
+ for (let x = 0; x < numPointsWidth; x++) {\r
+ if (x < numPointsWidth-1) {\r
+ this.constraints.push(new Constraint(\r
+ this.particles[this.getVertexIndex(x, y)],\r
+ this.particles[this.getVertexIndex(x+1, y)],\r
+ REST_DIST_X\r
+ ));\r
+ }\r
+ if (x < numPointsWidth-1) {\r
+ this.constraints.push(new Constraint(\r
+ this.particles[this.getVertexIndex(x, y)],\r
+ this.particles[this.getVertexIndex(x, y+1)],\r
+ REST_DIST_Y\r
+ ));\r
+ }\r
+ }\r
+ }\r