Altered circle

by blackpolygon

HTML

<html>

  <head>
    <title>Altered circles</title>
  </head>

  <body>
    <canvas id="canvas"></canvas>
  </body>

</html>

CSS

html {
  width: 100%;
  height: 100%;
}

body {
  margin: 0 auto;
  overflow: hidden;
  height: 100%;
  background: #121222;
}

JavaScript

var canvas, ctx

function init() {
  canvas = document.getElementById('canvas');
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;

  ctx = canvas.getContext('2d');
  ctx.lineWidth = 1;

}

function draw(radius, amplitude, period, color) {
  console.log(radius, amplitude, period, color);

  ctx.strokeStyle = color;

  var sides = 2000;
  ctx.beginPath();
  for (var i = 0; i < sides; i++) {
    var angle = i * ((Math.PI * 2) / sides);

    var newRadius = radius + Math.cos(i / period) * amplitude;
    var x = (canvas.width / 2) + Math.cos(angle) * newRadius;
    var y = (canvas.height / 2) + Math.sin(angle) * newRadius;
    ctx.lineTo(x, y);
  }

  ctx.stroke();
  ctx.closePath();
}

init();

var hue = 24;
var sat = 100;

var layers = 100;
var colorRange = layers/100;

for (var i = 1; i < layers; i++) {
  var radius = 30 + i * 10;
  var amplitude = 5 + i * Math.sin(i / 14)*Math.cos(i/2);
  var period = 10; // + Math.sin(i/10);

  hue += colorRange*i;
  // sat -= 0.01;
  var color = 'hsl(' + hue + ', ' + sat + '%, 50%)';

  draw(radius, amplitude, period, color);
}