Skip to content

Instantly share code, notes, and snippets.

@laithnurie
Created June 15, 2013 20:23
Show Gist options
  • Save laithnurie/5789485 to your computer and use it in GitHub Desktop.
Save laithnurie/5789485 to your computer and use it in GitHub Desktop.
A CodePen by laithnurie. Try to Focus - Can easily cause headaches
<div class="container">
<canvas></canvas>
<p class="text">Try to F<span>o</span>cus</p>
</div>
var canvas = document.querySelector('canvas'),
ctx = canvas.getContext('2d'),
w = window.innerWidth,
h = window.innerHeight,
points = 1000,
colors = ['#024a59','#04a65b','#04bf56','#f2cc5d','#f3574a'],
canvasPoints = [];
canvas.width = w;
canvas.height = h;
function Point(){
this.x = Math.round(Math.random()*w);
this.y = 100;
this.r = Math.round(Math.random()*20)+5;
this.opacity = Math.random();
this.velocity = this.opacity*10;
this.c = colors[Math.floor(Math.random()*5)];
}
(function init(){
for(var i = 0; i<points;i++){
canvasPoints.push(new Point());
}
})();
function draw(){
ctx.clearRect(0,0,w,h);
for(var i = 0; i<points;i++){
ctx.globalCompositeOperation = 'lighter';
var temp = canvasPoints[i];
ctx.fillStyle = temp.c;
ctx.globalAlpha = temp.opacity;
ctx.beginPath();
ctx.arc(temp.x,temp.y,temp.r,0,Math.PI*2,true);
temp.y -= temp.velocity;
ctx.fill();
if(temp.y<0)temp.y = h;
}
requestAnimFrame(draw);
}
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
draw();
@import url(http://fonts.googleapis.com/css?family=Raleway:300);
*{margin:0}
.container{
height:100%;
width:100%;
position: relative;
}
canvas{
background:#222;
}
.text{
color:#0072c5;
font:70px 'Raleway',Arial;
letter-spacing:20px;
position: absolute;
padding:20px 0;
text-align:center;
top:40%;
transition:all 1s;
width:100%;
}
span{
color:transparent;
text-shadow:0 0 10px #222,0 0 20px #0072c5;
}
.text:hover{
letter-spacing:0px;
background:#222;
}
.text:hover span{
color:#0072c5;
text-shadow:none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment