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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

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

  <canvas id="myCanvas" height="600" width="1600">Canvas is not supported</canvas>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                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;
  }
  ctx.beginPath();  
  ctx.moveTo(x1,y1);
  ctx.lineTo(x2,y2);
  ctx.stroke();
}

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";
  ctx.fillText(""+d+"°",x,base_y+23);
}

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;
console.log(mpp);
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";
  ctx.fillText(""+h,mid-12,base_y-yh+5);
}



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) {

SunLine(-27);
SunLine(-28);
SunLine(13);
SunLine(30);
SunLine(33);
SunLine(66);


for (var d =38;d<=55;d+=2) {
  SunLine(d);
}
}
else{
  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]);

    console.log(intersect)


    ctx.strokeStyle="#c0c040"
    ctx.beginPath();  
    ctx.moveTo(x1,y1);
//    ctx.quadraticCurveTo(x2,y2,x3,y3)
    ctx.quadraticCurveTo(intersect[0],intersect[1],x3,y3)
    ctx.stroke();

  }  
}


  //SunLine(47.6);


  
              
            
!
999px

Console