Skip to content

Commit 0728c87

Browse files
committed
adjusting drawing order
1 parent ba77e6f commit 0728c87

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

js/verlet-js/objects.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

2626
// generic verlet entities
2727

28+
VerletJS.prototype.point = function(pos) {
29+
var composite = new this.Composite();
30+
composite.particles.push(new Particle(pos));
31+
this.composites.push(composite);
32+
return composite;
33+
}
34+
2835
VerletJS.prototype.lineSegments = function(vertices, stiffness) {
2936
var i;
3037

js/verlet-js/verlet.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ VerletJS.prototype.Composite.prototype.pin = function(index, pos) {
103103
return pc;
104104
}
105105

106-
VerletJS.prototype.point = function(pos) {
107-
var composite = new this.Composite();
108-
composite.particles.push(new Particle(pos));
109-
this.composites.push(composite);
110-
return composite;
111-
}
112-
113106
VerletJS.prototype.frame = function(step) {
114107
var i, j, c;
115108

@@ -173,31 +166,26 @@ VerletJS.prototype.draw = function() {
173166

174167
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
175168

176-
// draw constraints
177169
for (c in this.composites) {
170+
// draw constraints
178171
if (this.composites[c].drawConstraints) {
179172
this.composites[c].drawConstraints(this.ctx, this.composites[c]);
180-
continue;
173+
} else {
174+
var constraints = this.composites[c].constraints;
175+
for (i in constraints)
176+
constraints[i].draw(this.ctx);
181177
}
182178

183-
var constraints = this.composites[c].constraints;
184-
for (i in constraints)
185-
constraints[i].draw(this.ctx);
186-
}
187-
188-
// draw particles
189-
for (c in this.composites) {
179+
// draw particles
190180
if (this.composites[c].drawParticles) {
191181
this.composites[c].drawParticles(this.ctx, this.composites[c]);
192-
continue;
182+
} else {
183+
var particles = this.composites[c].particles;
184+
for (i in particles)
185+
particles[i].draw(this.ctx);
193186
}
194-
195-
var particles = this.composites[c].particles;
196-
for (i in particles)
197-
particles[i].draw(this.ctx);
198187
}
199-
200-
188+
201189
// highlight nearest / dragged entity
202190
var nearest = this.draggedEntity || this.nearestEntity();
203191
if (nearest) {

0 commit comments

Comments
 (0)