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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <html lang="en">
  <meta charset="utf-8" >
  <title>Test HTML5 Canvas API</title>
    #myCanvas {
    //  border: 1px solid black;

  <canvas id="myCanvas" height="600" width="1600">Canvas is not supported</canvas>
              var canvas=document.getElementById("myCanvas");
var ctx=canvas.getContext("2d");

var width = canvas.width;
var height = canvas.height;

function line (x1,y1,x2,y2,col) {
  if (col != undefined) {
    ctx.strokeStyle = col;

var axisW = width * 0.95;

function d2x(d) {
  return (d+90)/180 * axisW - axisW/2 + width/2;

function radians(d) {
  return Math.PI * d / 180.0;

var base_y = 0.9 * height;

// X Axis
line (d2x(-90),base_y,d2x(90),base_y)

for (var d =-90;d<=90;d+=10) {
  var x = d2x(d);
  line ( x,base_y,x,base_y+10,"#4040FF" );
  ctx.font = "15px Arial";
  ctx.textAlign = "center";

for (var d =-90;d<=90;d+=1) {
  var x = d2x(d);
  line ( x,base_y,x,base_y+4,"#4040FF" );
// Y- axis

var mid = d2x(0);

// Y axis
line (mid,base_y,mid,-height,"#C0C0C0")

// calculate miles per pixel
var mpp = 24901.0/2/axisW;
for (var h=200;h<=4000;h+=200) {
  var yh = h/mpp;
  line (d2x(-90),base_y-yh,d2x(90),base_y-yh,"#E8E8E8")
  line (mid,base_y-yh,mid-10,base_y-yh,"#000000");
  ctx.textAlign = "right";

function SunLine(d) {
  var l = 1500;
  var dx = l * Math.sin(radians(d));
  var dy = l * Math.cos(radians(d));
  var x = d2x(d);
  var y = base_y
  line ( x, y, x-dx, y-dy, "#000000"); 

if (false) {


for (var d =38;d<=55;d+=2) {
  for (var d =-90;d<=90;d+=5) {
//  SunLine(d);

// K is the constant for the spread of the sun's rays
// bascially divides the 
var K = 2.2;
var sunH = 4000/mpp;

for (var d =-90;d<=90;d+=5) {
  if (d!=0) {
    var x1 = d2x(d);
    var y1 = base_y

    var a = radians(90-Math.abs(d));
    var b = (Math.PI/2-a)/K;
    var ta = Math.tan(a);
    var tb = Math.tan(b)

    // middle control point is where the line would
    // intersect the y axis
    var x2 = mid;
    var y2 = base_y-Math.abs(d)/90*axisW/2*ta

    // end control point is where the sun is.
    var x3 = mid
    var y3 = base_y-sunH;


    var x4 = mid + sunH*tb * math.sign(d)
    var y4 = base_y;

//    line(x1,y1,x2,y2,"#0xFF0000")
//    line(x3,y3,x4,y4,"#0x00FF00")

    var intersect = math.intersect([x1,y1],[x2,y2],[x3,y3],[x4,y4]);


//    ctx.quadraticCurveTo(x2,y2,x3,y3)



🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.