SHARE
TWEET

Untitled

a guest Jan 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.onload = function(){
  2.  
  3.     var canvas = document.getElementById("canvas");
  4.     var c = canvas.getContext("2d");
  5.  
  6.  
  7.  
  8.  
  9.  
  10.     var sphere = {
  11.  
  12.         diameter : 300,
  13.     }
  14.     function drawSphere(resolution){
  15.  
  16.          var size = resolution;
  17.          var diameter = sphere.diameter;
  18.          var j = 0;
  19.  
  20.  
  21.  
  22.         var langd = diameter/2;
  23.         var bredd = 0;
  24.         var radie = diameter/2;
  25.  
  26.         c.fillStyle = "gray";
  27.  
  28.         var y;
  29.             for(y = 0; 0 < diameter; y += size){
  30.  
  31.  
  32.  
  33.  
  34.             var startX = radie - bredd/2;
  35.             var slutX = radie + bredd/2;
  36.  
  37.             var x;
  38.                 for(x = startX; x < slutX; x += size){
  39.  
  40.                 c.beginPath();
  41.                 c.fillRect(x, y, x + size,y + size);
  42.                 c.closePath();
  43.  
  44.             }
  45.  
  46.         j = j + 1;
  47.         langd = langd - size*j;
  48.         bredd = Math.sqrt(radie*radie - langd*langd);
  49.         }
  50.  
  51.     }
  52.  
  53.     function init(){
  54.         drawSphere(2);
  55.     }
  56.  
  57.     init();
  58. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top