cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <canvas id="security" width="460" height="400"></canvas><br>



<img id="canvasImg" alt="Image here...">
            
          
!
            
              body { padding:20;background: #555; font-family: verdana;}
span { width:120px;display:inline-block;}
            
          
!
            
              var scale = 1.5;

var canvas = document.getElementById('security');
var ctx = canvas.getContext('2d');
var circleRads = Math.PI*2;
var wid = canvas.width * scale;
var hei = canvas.height * scale;

canvas.width = wid;
canvas.height = hei;


function drawIt() {
	var x = centreX * scale;
	var y = centreY * scale;
	var maxRadius = Math.sqrt( x * x + y * y );

	ctx.fillStyle = '#FFF';
	ctx.fillRect(0, 0, wid, hei);
	ctx.strokeStyle = '#000';
	ctx.lineWidth = 4 * scale;
	ctx.strokeRect(2, 2, wid-4, hei-4);

	function drawLines(v, r) {

		var angle = circleRads / v;

    r *= scale;
    
		if ( v ) {
			i = v;
			while( i-- ) {
				ctx.save();
				ctx.translate( x, y );
				ctx.rotate( i * angle );
				ctx.beginPath();
				ctx.moveTo(0,0);
				ctx.lineTo(0, r );
				ctx.stroke();
				ctx.restore();
			}
		}
	}

	function drawCircle( r ) {
    r *= scale;
		ctx.beginPath();
		ctx.fillStyle = "#fff";
		ctx.arc(x,y,r,0,circleRads, false);
		ctx.fill();
		ctx.stroke();
	}

	drawLines( outerSpokes, maxRadius );
	drawCircle( outerRadius );
	drawLines( innerSpokes, outerRadius );
  drawCircle( innerRadius );
}

var settings = {};
var t = 10;
function changer(v, min, max, value ) {
 
  var div = document.createElement("div");
  
  var label = document.createElement("span");
  label.innerHTML = v;
  
	var el = document.createElement("input");
  el.id = v;
  el.type = "range";
  el.min = min;
  el.max = max;
  el.value = value;
  
  var display = document.createElement("input");
  display.type = "text";
  display.value = value;
  display.tabIndex = t;
  t++;
  
  document.body.appendChild( div );
  div.appendChild( label );
  div.appendChild( el );
  div.appendChild( display );
  
  function set(e) {
    settings[ v ] = window[ v ] = display.value = el.value = e.srcElement.value;
		drawIt();
  }
  
	el.addEventListener("change", set);
  display.addEventListener("change", set);

	window[ v ] = settings[ v ] = el.value;
}

changer("outerSpokes", 1, 100, 30); // 30
changer("outerRadius", 1, 300, 150); // 110
changer("innerSpokes", 1, 100, 10); // 
changer("innerRadius", 1, 300, 135); // 86
changer("centreX", -50, wid + 100, 230 ); 
changer("centreY", -50, hei + 200, 480); // 450

var buttonExport = document.createElement("button");
buttonExport.addEventListener("click", function(e) {
  var output = "";
  for ( var p in settings ) output += p + ":" + settings[p] + " ";
  alert( output );
});
document.body.appendChild( buttonExport );
buttonExport.innerHTML = "export";


var buttonOutput = document.createElement("button");
buttonOutput.addEventListener("click", function(e) {
  var dataURL = canvas.toDataURL();
  document.getElementById('canvasImg').src = dataURL;
});
document.body.appendChild( buttonOutput );
buttonOutput.innerHTML = "output";

drawIt();

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console