A Pen by Dave DeHaan

Thumbnail
This awesome code was written by davedehaan, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright davedehaan ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Dave DeHaan</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <center>
  <canvas id="canvas" height="400" width="400"></canvas> 
</center>
<img src="https://lamplighter.io/signup/images/lamplighter_icon@2x.png" id="LL" />
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/davedehaan/a-pen-by-dave-dehaan-tbzvr */
body {
  margin: 0px;
  background: #333;
}
#LL {
  display: none;
}
#canvas {
}

/*Downloaded from https://www.codeseek.co/davedehaan/a-pen-by-dave-dehaan-tbzvr */
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');

var circleRadius = 0;
var grow = 1;
var LL = document.getElementById('LL');

var pad = '#000000';
var fillColor = '#FFFF00';
var bgColor = '#FFF';

setInterval(function() {
  canvas.width = canvas.width;
  context.fillStyle = bgColor;
  context.fillRect(0, 0, canvas.width/2, canvas.height/2);
  context.fillRect(canvas.width/2, canvas.height/2, canvas.width/2, canvas.height/2);
  context.fillRect(0, canvas.height/2, canvas.width/2, canvas.height/2);
  context.fillRect(canvas.width/2, 0, canvas.width/2, canvas.height/2);
  circleRadius = grow ? circleRadius + 1 : circleRadius - 1;
  if (circleRadius >= canvas.width * 2/3) 
    grow = 0;
  if (circleRadius <= 0) {
    grow = 1;
    fillColor = Math.floor(Math.random()*16777215).toString(16);
    fillColor = pad.substring(0, pad.length - fillColor.length) + fillColor;
    bgColor = Math.floor(Math.random()*16777215).toString(16);
    bgColor = pad.substring(0, pad.length - bgColor.length) + bgColor;

  }
  context.globalCompositeOperation = 'xor';
  context.beginPath();
  context.fillStyle = fillColor;
  context.arc(canvas.width/2, canvas.height/2, circleRadius, 0, Math.PI * 2);
  context.fill();
  
}, 1000/60);

Comments