Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance in Particle.prototype.draw() #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions jquery.particleground.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
var paused = false;

options = extend({}, window[pluginName].defaults, options);
var proximityS2 = options.proximity * options.proximity;

/**
* Init
Expand Down Expand Up @@ -243,10 +244,10 @@
// Pythagorus theorum to get distance between two points
var a = this.position.x - p2.position.x
var b = this.position.y - p2.position.y
var dist = Math.sqrt((a * a) + (b * b)).toFixed(2);
var distS2 = (a * a) + (b * b);

// If the two particles are in proximity, join them
if (dist < options.proximity) {
if (distS2 < proximityS2) {
ctx.moveTo(this.position.x + this.parallaxOffsetX, this.position.y + this.parallaxOffsetY);
if (options.curvedLines) {
ctx.quadraticCurveTo(Math.max(p2.position.x, p2.position.x), Math.min(p2.position.y, p2.position.y), p2.position.x + p2.parallaxOffsetX, p2.position.y + p2.parallaxOffsetY);
Expand Down
4 changes: 2 additions & 2 deletions jquery.particleground.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.