Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Draw Spiral On Canvas
- function CanvasDrawSpiral(Canvas) {
- // Create ILDA
- var TOTALFRAMES = 1;
- var file = new ILDA.File();
- var s = new ILDA.Section();
- s.type = ILDA.SectionTypes.THREE_DIMENSIONAL;
- s.name = 'Frame001'; //8 Characters or less. Fr0001
- s.company = '';
- s.index = 0; // Probably changed based on frame
- // s.head = 1;
- s.total = TOTALFRAMES; // 1 Frame=Still / Multiple Frames=Animation
- // alert("S: " + JSON.stringify(s,null,4));
- file.sections.push(s);
- // --------
- var c=document.getElementById(Canvas);
- var ctx=c.getContext("2d");
- c.width = c.width; // Used to clear Canvas
- var centerX = c.width / 2;
- var centerY = c.height / 2;
- ctx.moveTo(centerX, centerY);
- var gap = 1.8; // increase this for spacing between spiral lines
- var STEPS_PER_ROTATION = 60; // increasing this makes the curve smoother
- var oldX="";
- var oldY="";
- var increment = 2*Math.PI/STEPS_PER_ROTATION;
- var theta = increment;
- var newXScale;
- var newYScale;
- var color=0;
- while( theta < 20*Math.PI) {
- var newX = centerX + theta * Math.cos(theta) * gap;
- var newY = centerY + theta * Math.sin(theta) * gap;
- ctx.lineTo(newX, newY);
- // alert("S: " + JSON.stringify(s,null,4));
- // alert("Old: " + oldX + "," + oldY);
- // alert("New: " + newX + "," + newY);
- var newXScale = (c.width / 2) - newX / c.width * 32768;
- var newYScale = (c.height / 2) - newY / c.height * -32768;
- if (oldX == "") { oldX = newXScale; }
- if (oldY == "") { oldY = newYScale; }
- // Draw ILDA Line (0=Red / 16=Yellow) (256 color total) (0 to 255)
- // drawLine(s, oldX, oldY, newX, newY, 16); // Color: 0 = Red, 16 = Yellow
- drawLine(s, oldX, oldY, newXScale, newYScale, color);
- // s.points = mypoints;
- // alert("Old: " + oldX + "," + oldY);
- // alert("New: " + newX + "," + newY);
- // alert("File: " + JSON.stringify(file,null,4));
- oldX = newX;
- oldY = newY;
- theta = theta + increment;
- if (color == "255") {
- color = 1;
- } else {
- color++;
- }
- }
- // Last Frame
- s.points.push({
- x: 0,
- y: 0,
- z: 0,
- color: 0,
- blanking: true,
- last: true
- });
- // Very End (to be sure) (need to add to conform to standard)
- endframe = {
- type: 0,
- name: "End000",
- company: "",
- index: 1,
- points: [],
- head: 0,
- total: 1,
- colors: []
- };
- // file.push(endframe);
- // s.push(endframe);
- // Push Points to Array
- // s.points = points;
- // myJsonFile.sections.push(s);
- document.getElementById("fileContents3").innerHTML = JSON.stringify(file,null,4);
- // alert("File: " + JSON.stringify(s,null,4));
- // Draw on Canvas
- ctx.strokeStyle = 'white';
- ctx.stroke(); // draw the spiral
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement