cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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.

            
              svg#canvas(width=800, height=800)
#menu
  label.verticies Verticies
    input#verticies(type="range", min=3, max=128, step=1, value=24)
    .val
  label.radius Radius
    input#radius(type="range", min=1, max=100, step=1, value=100)
    .val
            
          
!
            
              #menu
  label
    display: block
  position: absolute
  right: 0
  top: 0
  
#canvas
  width: 100%
  height: 100%
            
          
!
            
              var TAU = Math.PI * 2;
var paper = Snap("#canvas");

var radius = 400;
var numVerticies = 24;

function setup(){
  $("#verticies").on("input", onChangeVerticies);
  $("#radius").on("input", onChangeRadius);
	render();
}

setup();

function render(){
  paper.clear();
  var verticies = getVerticies(radius, numVerticies);
  drawLines(verticies);
}
function getVerticies(radius, numVerticies){
  var verticies = [];
  var center = {
    x: radius,
    y: radius
  }
  var displacementAngle = TAU / numVerticies;
  var v;
  for (var i=0; i<numVerticies; i++){
    v = {
      x: center.x + Math.cos(displacementAngle * i) * radius,
      y: center.y + Math.sin(displacementAngle * i) * radius,
    }
    verticies.push(v);
  }
  return verticies;
}

function drawLines(verticies){
  var numVerticies = verticies.length
  var pathStrings = [];
  var path, baseString, vi, vj;
  for (var i=0; i<numVerticies; i++){
    path = [];
    vi = verticies[i];
  	baseString = ["M " + vi.x +" "+ vi.y];
    for (var j=i+1; j < numVerticies; j++){
      vj = verticies[j];
      path.push([baseString, "L",vj.x,vj.y].join(" "))
    }
    paper.path(path.join(" ")).attr({
        fill: "none",
        stroke: "#000",
        strokeWidth: 1
    });
  }
}

// Menu
function onChangeVerticies(e){
  numVerticies = parseInt(e.target.value, 10);
  $("label.verticies .val").text(numVerticies);
  render();
}

function onChangeRadius(e){
  radius = $("#canvas").width() * 0.5 * (parseInt(e.target.value, 10) / 100);
  $("label.radius .val").text(radius >> 0);
  render();
}
            
          
!
999px
Loading ..................

Console