Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Draw Spiral On Canvas
  2.     function CanvasDrawSpiral(Canvas) {
  3.        
  4.         // Create ILDA
  5.         var TOTALFRAMES = 1;
  6.        
  7.         var file = new ILDA.File();
  8.         var s = new ILDA.Section();
  9.        
  10.         s.type = ILDA.SectionTypes.THREE_DIMENSIONAL;
  11.         s.name = 'Frame001'; //8 Characters or less. Fr0001
  12.         s.company = '';
  13.         s.index = 0; // Probably changed based on frame
  14.         // s.head = 1;
  15.         s.total = TOTALFRAMES; // 1 Frame=Still / Multiple Frames=Animation
  16.        
  17.         // alert("S: " + JSON.stringify(s,null,4));
  18.        
  19.  
  20.         file.sections.push(s);
  21.  
  22.        
  23.         // --------
  24.                
  25.         var c=document.getElementById(Canvas);
  26.         var ctx=c.getContext("2d");
  27.  
  28.         c.width = c.width; // Used to clear Canvas
  29.  
  30.         var centerX = c.width / 2;
  31.         var centerY = c.height / 2;
  32.         ctx.moveTo(centerX, centerY);
  33.    
  34.         var gap = 1.8; // increase this for spacing between spiral lines        
  35.         var STEPS_PER_ROTATION = 60; // increasing this makes the curve smoother
  36.        
  37.         var oldX="";
  38.         var oldY="";
  39.        
  40.         var increment = 2*Math.PI/STEPS_PER_ROTATION;      
  41.         var theta = increment;
  42.        
  43.         var newXScale;
  44.         var newYScale;
  45.        
  46.         var color=0;
  47.        
  48.         while( theta < 20*Math.PI) {
  49.            
  50.            var newX = centerX + theta * Math.cos(theta) * gap;
  51.            var newY = centerY + theta * Math.sin(theta) * gap;
  52.            ctx.lineTo(newX, newY);
  53.  
  54.            // alert("S: " + JSON.stringify(s,null,4));
  55.  
  56.            // alert("Old: " + oldX + "," + oldY);
  57.            // alert("New: " + newX + "," + newY);
  58.            
  59.            var newXScale = (c.width / 2) - newX / c.width * 32768;
  60.            var newYScale = (c.height / 2) - newY / c.height * -32768;
  61.  
  62.            if (oldX == "") { oldX = newXScale; }
  63.            if (oldY == "") { oldY = newYScale; }
  64.            
  65.            // Draw ILDA Line (0=Red / 16=Yellow) (256 color total) (0 to 255)
  66.            // drawLine(s, oldX, oldY, newX, newY, 16); // Color: 0 = Red, 16 = Yellow
  67.  
  68.             drawLine(s, oldX, oldY, newXScale, newYScale, color);
  69.            
  70.            
  71.            // s.points = mypoints;
  72.            
  73.            // alert("Old: " + oldX + "," + oldY);
  74.            // alert("New: " + newX + "," + newY);
  75.        
  76.            // alert("File: " + JSON.stringify(file,null,4));
  77.  
  78.  
  79.            oldX = newX;
  80.            oldY = newY;
  81.            
  82.            theta = theta + increment;
  83.            
  84.            if (color == "255") {
  85.                color = 1;
  86.            } else {
  87.                 color++;
  88.            }
  89.         }
  90.        
  91.         // Last Frame
  92.         s.points.push({
  93.             x: 0,
  94.             y: 0,
  95.             z: 0,
  96.             color: 0,
  97.             blanking: true,
  98.             last: true
  99.         });
  100.        
  101.         // Very End (to be sure) (need to add to conform to standard)
  102.        
  103.         endframe = {
  104.             type: 0,
  105.             name: "End000",
  106.             company: "",
  107.             index: 1,
  108.             points: [],
  109.             head: 0,
  110.             total: 1,
  111.             colors: []
  112.         };
  113.        
  114.         // file.push(endframe);
  115.        
  116.         // s.push(endframe);
  117.        
  118.        
  119.        
  120.         // Push Points to Array
  121.         // s.points = points;
  122.         // myJsonFile.sections.push(s);
  123.        
  124.         document.getElementById("fileContents3").innerHTML = JSON.stringify(file,null,4);
  125.         // alert("File: " + JSON.stringify(s,null,4));
  126.  
  127.  
  128.         // Draw on Canvas
  129.         ctx.strokeStyle = 'white';
  130.         ctx.stroke(); // draw the spiral
  131.        
  132.  
  133.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement