Skip to content

Commit 4ca0bb1

Browse files
committed
adding highlightColor
1 parent 6468ab3 commit 4ca0bb1

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

experiments/03-cloth.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
// simulation
3131
var sim = new VerletSimulation(width, height, canvas);
32+
sim.highlightColor = "#fff";
3233

3334
// entities
3435
var min = Math.min(width,height)*0.5;
@@ -65,20 +66,9 @@
6566

6667
ctx.fillStyle = "rgba(" + coef + ",0," + (255-coef)+ ",1)";
6768

68-
69-
7069
ctx.fill();
7170
}
7271
}
73-
74-
/*var i;
75-
for (i in composite.particles) {
76-
var point = composite.particles[i];
77-
ctx.beginPath();
78-
ctx.arc(point.pos.x, point.pos.y, 1.2, 0, 2*Math.PI);
79-
ctx.fillStyle = "#ff6000";
80-
ctx.fill();
81-
}*/
8272
}
8373

8474
// animation loop

js/common/simulation.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var VerletSimulation = function(width, height, canvas) {
3030
this.mouseDown = false;
3131
this.draggedEntity = null;
3232
this.selectionRadius = 20;
33+
this.highlightColor = "#4f545c";
3334
var _this = this;
3435

3536
// prevent context menu
@@ -223,15 +224,6 @@ VerletSimulation.prototype.draw = function() {
223224

224225
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
225226

226-
// highlight nearest / dragged entity
227-
var nearest = this.draggedEntity || this.nearestEntity();
228-
if (nearest) {
229-
this.ctx.beginPath();
230-
this.ctx.arc(nearest.pos.x, nearest.pos.y, 8, 0, 2*Math.PI);
231-
this.ctx.strokeStyle = "#4f545c";
232-
this.ctx.stroke();
233-
}
234-
235227
// draw constraints
236228
for (c in this.composites) {
237229
if (this.composites[c].drawConstraints) {
@@ -255,6 +247,16 @@ VerletSimulation.prototype.draw = function() {
255247
for (i in particles)
256248
particles[i].draw(this.ctx);
257249
}
250+
251+
252+
// highlight nearest / dragged entity
253+
var nearest = this.draggedEntity || this.nearestEntity();
254+
if (nearest) {
255+
this.ctx.beginPath();
256+
this.ctx.arc(nearest.pos.x, nearest.pos.y, 8, 0, 2*Math.PI);
257+
this.ctx.strokeStyle = this.highlightColor;
258+
this.ctx.stroke();
259+
}
258260
}
259261

260262
VerletSimulation.prototype.nearestEntity = function() {

0 commit comments

Comments
 (0)