Skip to content

Commit

Permalink
Make background... ALIVE!
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekidoxx committed May 22, 2018
1 parent 38fca63 commit 2218b65
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 4 deletions.
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
To begin the development, run "npm run start" or "yarn start".
To create a production bundle, use "npm run build" or "yarn build".
-->
<script src="%PUBLIC_URL%/sketch.min.js"></script>
<script defer src="%PUBLIC_URL%/sketch-particles.js"></script>
</body>
</html>
174 changes: 174 additions & 0 deletions public/sketch-particles.js
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);
}

}

};
2 changes: 2 additions & 0 deletions public/sketch.min.js

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

4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class App extends Component {
});
return (
<div className="flex flex-column min-vh-100 tc">
<header className="custom--unselectable fixed top-0 w-100 h3 white custom--bg-additional3 custom--shadow-4 z-2">
<header className="custom--unselectable fixed top-0 w-100 h3 white custom--bg-additional3 custom--shadow-4 z-3">
<h1 id="title" className="relative ma0 pa0 fl-l">
<svg className="w2 h2 mr2 v-top" viewBox="0 0 24 24">
<path d="M12,6A3,3 0 0,0 9,9A3,3 0 0,0 12,12A3,3 0 0,0 15,9A3,3 0 0,0 12,6M6,8.17A2.5,2.5 0 0,0 3.5,10.67A2.5,2.5 0 0,0 6,13.17C6.88,13.17 7.65,12.71 8.09,12.03C7.42,11.18 7,10.15 7,9C7,8.8 7,8.6 7.04,8.4C6.72,8.25 6.37,8.17 6,8.17M18,8.17C17.63,8.17 17.28,8.25 16.96,8.4C17,8.6 17,8.8 17,9C17,10.15 16.58,11.18 15.91,12.03C16.35,12.71 17.12,13.17 18,13.17A2.5,2.5 0 0,0 20.5,10.67A2.5,2.5 0 0,0 18,8.17M12,14C10,14 6,15 6,17V19H18V17C18,15 14,14 12,14M4.67,14.97C3,15.26 1,16.04 1,17.33V19H4V17C4,16.22 4.29,15.53 4.67,14.97M19.33,14.97C19.71,15.53 20,16.22 20,17V19H23V17.33C23,16.04 21,15.26 19.33,14.97Z" />
Expand All @@ -64,7 +64,7 @@ class App extends Component {
<main className="flex-auto">
<CardList persons={filteredPersons} />
</main>
<footer className="w-100 h3 custom--bg-additional3 flex items-center justify-center justify-end-l">
<footer className="w-100 h3 custom--bg-additional3 flex items-center justify-center justify-end-l z-2">
<a href="https://github.com/zero-to-mastery/ZtM-Job-Board" title="Repository">
<svg className="repo w2 h2" viewBox="0 0 12 16" version="1.1" aria-hidden="true">
<path fillRule="evenodd" d="M4 9H3V8h1v1zm0-3H3v1h1V6zm0-2H3v1h1V4zm0-2H3v1h1V2zm8-1v12c0 .55-.45 1-1 1H6v2l-1.5-1.5L3 16v-2H1c-.55 0-1-.45-1-1V1c0-.55.45-1 1-1h10c.55 0 1 .45 1 1zm-1 10H1v2h2v-1h3v1h5v-2zm0-10H2v9h9V1z"></path>
Expand Down
2 changes: 1 addition & 1 deletion src/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Card = ({user}) => {
// Using the new id var to filter the new developer submissions
if (id !== undefined) {
return (
<div id={`person-${id}`} className="card ma4 w5 tc bg-white br2 custom--shadow-2 custom--shadow-hover-8">
<div id={`person-${id}`} className="card ma4 w5 tc bg-white br2 custom--shadow-2 custom--shadow-hover-8 custom--o-95 z-1">
<div className="header pt3 br2 br--top">
<div className="photo br-100 h4 w4 bw2 b--solid custom--b--primary bg-center cover" title={name} style={img !== '' ? {backgroundImage: 'url("' + img + '")'} : {}}></div>
<h2 className="name mt3 mb1 ph3 w-100 flex items-center justify-center">{name}</h2>
Expand Down
2 changes: 1 addition & 1 deletion src/CardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CardList = ({persons}) => {
});

return (
<div className="flex flex-wrap justify-center">
<div id="sketch-particles" className="flex flex-wrap justify-center">
{cardCom}
</div>
);
Expand Down
15 changes: 15 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ svg {
transition: fill 280ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
}



body {
min-width: 22.25rem;
font-family: "Roboto Condensed", sans-serif;
Expand Down Expand Up @@ -247,8 +249,18 @@ main {

}

canvas.sketch {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
}

}



footer {

padding: 0 5%;
Expand Down Expand Up @@ -284,6 +296,9 @@ footer {
}


.custom--o-95 {
opacity: 0.95;
}

.custom--shadow-0,
.custom--shadow-hover-0:hover {
Expand Down

0 comments on commit 2218b65

Please sign in to comment.