forked from zero-to-mastery/ZtM-Job-Board
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// ---------------------------------------- | ||
// Particle | ||
// ---------------------------------------- | ||
|
||
function Particle(x, y, radius) { | ||
this.init(x, y, radius); | ||
} | ||
|
||
Particle.prototype = { | ||
|
||
init: function(x, y, radius) { | ||
|
||
this.alive = true; | ||
|
||
this.radius = radius || 10; | ||
this.wander = 0.15; | ||
this.theta = random(TWO_PI); | ||
this.drag = 0.92; | ||
this.color = '#EEEEEE'; | ||
|
||
this.x = x || 0.0; | ||
this.y = y || 0.0; | ||
|
||
this.vx = 0.0; | ||
this.vy = 0.0; | ||
|
||
}, | ||
|
||
move: function() { | ||
|
||
this.x += this.vx; | ||
this.y += this.vy; | ||
|
||
this.vx *= this.drag; | ||
this.vy *= this.drag; | ||
|
||
this.theta += random(-0.5, 0.5) * this.wander; | ||
this.vx += sin(this.theta) * 0.1; | ||
this.vy += cos(this.theta) * 0.1; | ||
|
||
this.radius *= 0.96; | ||
this.alive = this.radius > 0.5; | ||
|
||
}, | ||
|
||
draw: function(ctx) { | ||
|
||
ctx.beginPath(); | ||
ctx.arc(this.x, this.y, this.radius, 0, TWO_PI); | ||
ctx.fillStyle = this.color; | ||
ctx.fill(); | ||
|
||
} | ||
|
||
}; | ||
|
||
// ---------------------------------------- | ||
// Example | ||
// ---------------------------------------- | ||
|
||
var MAX_PARTICLES = 300; | ||
var COLOURS = [ | ||
'#E3F2FD', '#BBDEFB', '#90CAF9', '#64B5F6', '#42A5F5', '#2196F3', '#1E88E5', '#1976D2', '#1565C0', '#0D47A1', // Blue 50->900 | ||
'#FFF8E1', '#FFECB3', '#FFE082', '#FFD54F', '#FFCA28', '#FFC107', '#FFB300', '#FFA000', '#FF8F00', '#FF6F00' // Amber 50->900 | ||
]; | ||
|
||
var particles = []; | ||
var pool = []; | ||
|
||
if ((typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1)) { | ||
|
||
console.info("Sketch particles: detected mobile device"); | ||
|
||
var liveBg = Sketch.create({ | ||
fullscreen: true, | ||
autostart: true, | ||
autoclear: true, | ||
autopause: false, | ||
container: document.getElementById('sketch-particles'), | ||
interval: 1, | ||
globals: true, | ||
retina: 'auto', | ||
type: Sketch.CANVAS | ||
}); | ||
|
||
} | ||
else { | ||
|
||
console.info("Sketch particles: detected device other than mobile"); | ||
|
||
var liveBg = Sketch.create({ | ||
fullscreen: true, | ||
autostart: true, | ||
autoclear: true, | ||
autopause: false, | ||
container: document.getElementById('sketch-particles'), | ||
interval: 1, | ||
globals: true, | ||
retina: 'auto', | ||
type: Sketch.CANVAS, | ||
eventTarget: document.getElementById('sketch-particles') | ||
}); | ||
|
||
} | ||
|
||
liveBg.spawn = function(x, y) { | ||
|
||
var particle, theta, force; | ||
|
||
if (particles.length >= MAX_PARTICLES) { | ||
pool.push( particles.shift() ); | ||
} | ||
|
||
particle = pool.length ? pool.pop() : new Particle(); | ||
particle.init(x, y, random(5, 40)); | ||
|
||
particle.wander = random(0.5, 2.0); | ||
particle.color = random(COLOURS); | ||
particle.drag = random(0.9, 0.99); | ||
|
||
theta = random(TWO_PI); | ||
force = random(2, 8); | ||
|
||
particle.vx = sin(theta) * force; | ||
particle.vy = cos(theta) * force; | ||
|
||
particles.push(particle); | ||
|
||
}; | ||
|
||
liveBg.update = function() { | ||
|
||
var i, particle; | ||
|
||
for (i = particles.length - 1; i >= 0; i--) { | ||
|
||
particle = particles[i]; | ||
|
||
if (particle.alive) { | ||
particle.move(); | ||
} | ||
else { | ||
pool.push(particles.splice( i, 1 )[0]); | ||
} | ||
|
||
} | ||
|
||
}; | ||
|
||
liveBg.draw = function() { | ||
|
||
liveBg.globalCompositeOperation = 'source-over'; // best options: 'lighter' or 'source-over' | ||
|
||
for (var i = particles.length - 1; i >= 0; i--) { | ||
particles[i].draw(liveBg); | ||
} | ||
|
||
}; | ||
|
||
liveBg.mousemove = function() { | ||
|
||
var particle, theta, force, touch, max, i, j, n; | ||
|
||
for (i = 0, n = liveBg.touches.length; i < n; i++) { | ||
|
||
touch = liveBg.touches[i], max = random(1, 4); | ||
|
||
for (j = 0; j < max; j++) { | ||
liveBg.spawn(touch.x, touch.y); | ||
} | ||
|
||
} | ||
|
||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters