Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<canvas id="canvas" width="1000" height="1000">
 </canvas>
        
              
            
!

CSS

              
                canvas {
    border: 1px dotted black;
}
              
            
!

JS

              
                // Set up!
var a_canvas = document.getElementById("canvas");
var context = a_canvas.getContext("2d");

var xCenter = 500;
var yCenter = 300;
var magnifier = 75;
var smallRadius = 2 * magnifier;
var bigRadius = 3 * magnifier;
var realimgWidth = 1;
var imgWidth = magnifier;
var numIMGs = 3;
var changeAngle;

//Sidebar
context.font = "20px Garamond";
context.fillText("radius =" + smallRadius/magnifier, 0, 30);
context.font = "20px Garamond";
context.fillText("Image Width =" + realimgWidth, 0, 60);
context.font = "20px Garamond";
context.fillText("Number of Images =" + numIMGs, 0, 90);
context.font = "20px Garamond";
context.fillText("Angle between IMG centerpoints =" + 360/numIMGs, 0, 120);


//Diagram
var drawCircle = function( xPos, yPos, radius, colour){
  context.fillStyle = colour;
  context.beginPath();
  context.arc(xPos, yPos, radius, 0, 2*Math.PI);
  context.closePath();
  context.fill();
  context.lineWidth = 1;
  context.stroke();
  context.fillStyle = "black";
  console.log("circle drawn at: " + xPos + ", " + yPos);
}

var drawLine = function(xStart, yStart, xFin, yFin){
  context.beginPath();
  context.moveTo(xStart, yStart);
  context.lineTo(xFin, yFin);
  context.stroke();
}

drawCircle(xCenter, yCenter, bigRadius, "red");
drawCircle(xCenter, yCenter, smallRadius, "yellow");
drawLine(xCenter,yCenter, xCenter, yCenter -smallRadius);
drawLine(xCenter - imgWidth/2, yCenter - smallRadius, xCenter + imgWidth/2, yCenter - smallRadius);
 //white line
    context.strokeStyle = "#FFFFFF";
    context.beginPath();
    context.moveTo(xCenter, yCenter);
    context.lineTo(xCenter + imgWidth/2, yCenter - smallRadius);
    context.stroke();

    context.beginPath();
    context.moveTo(xCenter, yCenter);
    context.lineTo(xCenter - imgWidth/2, yCenter - smallRadius);
    context.stroke();
//context.font = "15px Garamond";
//context.fillText("imgWidth", xCenter - 30, yCenter - smallRadius - 5);

// Word Diagram
context.font = "30px Garamond";
context.fillText("Diagram", xCenter,yCenter + bigRadius + 50);
context.font = "10px Garamond";
context.fillText("0, 0", xCenter,yCenter);
//function takes degrees and outputs radians
var toRadians = function(angle) {
  return angle * (Math.PI/180);
}


var angleCounter = 150;

for (i = 0; i < numIMGs; i++) { 
    var xDelta = smallRadius * Math.cos(toRadians(i *(360/numIMGs)  -90));
    var yDelta = smallRadius * Math.sin(toRadians(i*(360/numIMGs) - 90));
    var newX = xCenter + xDelta;
    var newY = yCenter + yDelta;
    console.log("newX: " + newX + ", newY: " +newY);
    console.log("angle " + (i + 1) + " " + xCenter + ", " + xDelta + ", " + yCenter + ", " + yDelta);
    drawCircle(newX, newY, 2, "black");
  var anglePlusOne = i +1;
  var realX = (newX - xCenter)/magnifier;
  var realY = (newY - yCenter)/magnifier;
  context.font = "10px Garamond";
  context.fillText("angle " + anglePlusOne, newX, newY);
  context.fillText("angle " + anglePlusOne + ": " + realX + ", " + realY, 10, angleCounter);
  angleCounter +=10;
}
              
            
!
999px

Console