Wagn0re

Prime spiral

Dec 27th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <body>
  4.  
  5.   <canvas id="myCanvas" width="4000" height="4000" style="border:1px solid #d3d3d3; background-color: #424242;">
  6.   Your browser does not support the HTML5 canvas tag.</canvas>
  7.  
  8.           <script>
  9.                   var c = document.getElementById("myCanvas");
  10.                   var ctx = c.getContext("2d");
  11.                   var startx = 2000;
  12.                   var starty = 2000;
  13.                   var paddings = 30;
  14.                   var start_ang = 6.25;
  15.                   var end_ang = 6.28;
  16.  
  17.                   function isPrime(num) {
  18.                     var sqrtnum=Math.floor(Math.sqrt(num));
  19.                       var prime = num != 1;
  20.                       for(var i=2; i<sqrtnum+1; i++) {
  21.                           if(num % i == 0) {
  22.                               prime = false;
  23.                               break;
  24.                           }
  25.                       }
  26.                       return prime;
  27.                   }
  28.  
  29.                   function circleDots(iterations, step, step_inc){
  30.                     var count = 0;
  31.                     for(var i = 0; i < iterations; i++){
  32.                       for(var j = 628; j > 0; j--){
  33.                         dotPlot(count, step);
  34.                         count++;
  35.                       }
  36.                       step = step + step_inc;
  37.                     }
  38.  
  39.                   }
  40.  
  41.                   function darkener(spans, pads, incrementz, iterations){
  42.                     for(var i = 0; i < iterations; i++){
  43.                       circleDots(spans, pads, incrementz);
  44.                     }
  45.                   }
  46.  
  47.                   darkener(1500, 0, 2, 5);
  48.  
  49.  
  50.                   function decimaler(num){
  51.                     var decified = num / 100;
  52.                     return decified;
  53.                   }
  54.  
  55.                   function dotPlot(position, step){
  56.                     var increment = .3;
  57.                     var stringed_pos = position.toString();
  58.                     if(isPrime(position) === true){
  59.                       if(stringed_pos.charAt(stringed_pos.length - 1) == 1){//testing some conditionals
  60.                         position = position + 5;
  61.                         DrawArc(startx, starty, paddings + step, decimaler(position - increment), decimaler(position));
  62.                       }
  63.                       if(stringed_pos.charAt(stringed_pos.length - 1) == 3){//testing some conditionals
  64.                         position = position + 3;
  65.                         DrawArc(startx, starty, paddings + step, decimaler(position - increment), decimaler(position));
  66.                       }
  67.                       if(stringed_pos.charAt(stringed_pos.length - 1) == 7){//testing some conditionals
  68.                         position = position - 1;
  69.                         DrawArc(startx, starty, paddings + step, decimaler(position - increment), decimaler(position));
  70.                       }
  71.                       if(stringed_pos.charAt(stringed_pos.length - 1) == 9){//testing some conditionals
  72.                         position = position - 3;
  73.                         DrawArc(startx, starty, paddings + step, decimaler(position - increment), decimaler(position));
  74.                       }/*
  75.                       DrawArc(startx, starty, paddings + step, decimaler(position - increment), decimaler(position));
  76.                       */
  77.                     } /*
  78.                     else{
  79.                       DrawArcRed(startx, starty, paddings + step, decimaler(position - increment), decimaler(position));
  80.                     } */
  81.                   }
  82.  
  83.                   function DrawArc(start_x, start_y, padding, start_a, end_a){
  84.                     ctx.strokeStyle = "black";
  85.                     ctx.beginPath();
  86.                     ctx.arc(start_x, start_y, padding, start_a, end_a);
  87.                     ctx.stroke();
  88.                   }
  89.                   function DrawArcRed(start_x, start_y, padding, start_a, end_a){
  90.                     ctx.strokeStyle = '#595959';
  91.                     ctx.beginPath();
  92.                     ctx.arc(start_x, start_y, padding, start_a, end_a);
  93.                     ctx.stroke();
  94.                   }
  95.  
  96.                   </script>
  97.  
  98.   </body>
  99. </html>
Advertisement
Add Comment
Please, Sign In to add comment