From 287518c6cfaae20afbbff05b0502e9c612bf0e8f Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 18 Sep 2013 11:27:47 +0200 Subject: [PATCH] Removed unused draw logic --- js/draw_logic.js | 277 ----------------------------------------------- 1 file changed, 277 deletions(-) delete mode 100644 js/draw_logic.js diff --git a/js/draw_logic.js b/js/draw_logic.js deleted file mode 100644 index ebabbe0..0000000 --- a/js/draw_logic.js +++ /dev/null @@ -1,277 +0,0 @@ -var oopsTimer; -var dragging; -var path; -var svg; -var preview; -var previewCtx; - -var svgPathRegExp = /[LM]\d* \d*/ig; -var svgPathParamsRegExp = /([LM])(\d*) (\d*)/; - -var svgTopLeftCoords = []; -function initDrawing() { - - path = document.getElementById('path'); - svg = document.getElementById('svg'); - - svgTopLeftCoords[0] = $("#drawAreaContainer").css("left").match(/[0-9]/g).join(""); - svgTopLeftCoords[1] = $("#drawAreaContainer").css("top").match(/[0-9]/g).join(""); - - svg.addEventListener('mousedown',onMouseDown,false); - svg.addEventListener('mousemove',onMouseMove,false); - svg.addEventListener('mouseup',onMouseUp,false); - svg.addEventListener('touchstart',onTouchDown,false); - svg.addEventListener('touchmove',onTouchMove,false); - btnNew.addEventListener('mousedown',clear,false); - btnNew.addEventListener('touchstart',clear,false); - btnOops.addEventListener('touchstart',startOops,false); - btnOops.addEventListener('touchend',stopOops,false); - btnOops.addEventListener('mousedown',startOops,false); - btnOops.addEventListener('mouseup',stopOops,false); - btnPrint.addEventListener('mousedown',print,false); - btnPrint.addEventListener('touchstart',print,false); - btnSave.addEventListener('mousedown',print,false); - btnSave.addEventListener('touchstart',print,false); - - document.body.addEventListener('touchmove',prevent,false); - - preview = document.getElementById('preview'); - previewCtx = preview.getContext('2d'); - redrawPreview(); -}; - -function prevent(e) { - e.preventDefault(); -} - -function clear() { - path.attributes.d.nodeValue = "M0 0"; - redrawPreview(); -} - -function startOops() { - oopsTimer = setInterval("oops()",1000/30); -} - -function stopOops() { - clearInterval(oopsTimer); -} - -function oops() { - str = path.attributes.d.nodeValue; - n = str.lastIndexOf(" L"); - if(n != -1) { - path.attributes.d.nodeValue = str.substr(0,n); - redrawPreview(); - //requestAnimationFrame(updatePreview); - } -} - -function moveTo(x,y) { - if (path.attributes.d.nodeValue=="M0 0") { - path.attributes.d.nodeValue = "M" + x + " " + y; - } else { - path.attributes.d.nodeValue += " M" + x + " " + y; - } - updatePreview(x,y,true) - //redrawPreview(); -} - -function lineTo(x,y) { - path.attributes.d.nodeValue += " L" + x + " " + y; - //updatePreview(); - //requestAnimationFrame(updatePreview); - updatePreview(x,y,false); -} - -function onTouchDown(e) { - var x = e.touches[0].pageX - svgTopLeftCoords[0]; - var y = e.touches[0].pageY - svgTopLeftCoords[1]; - moveTo(x,y); -} - -function onTouchMove(e) { - e.preventDefault(); - var x = e.touches[0].pageX - svgTopLeftCoords[0]; - var y = e.touches[0].pageY - svgTopLeftCoords[1]; - lineTo(x,y); -} - -function onMouseDown(e) { - dragging = true; - moveTo(e.offsetX,e.offsetY); -} - -function onMouseMove(e) { - if (!dragging) return; - lineTo(e.offsetX,e.offsetY); -} - -function onMouseUp(e) { - dragging = false; -} - -function print(e) { - - output = path.attributes.d.nodeValue; - console.log(output); - - output = output.split("M").join("\n"); - output = output.split(" L").join("_"); - output = output.split(" ").join(","); - output = output.split("_").join(" "); - - output = "\nBEGIN\n" + output + "\n\nEND\n"; - - console.log("output :" + output ); - - $.post("/doodle3d.of", { data:output }, function(data) { - btnPrint.disabled = false; - }); -} - -var numLayers = 100; //50 -var globalScale = 0.20; // global scale of preview -var globalAlpha = 0.20; // global alpha of preview -var scaleY = 0.4; // additional vertical scale per path for 3d effect -var strokeWidth = 2; //4; -var rStep = Math.PI/40; //Math.PI/40; // -var yStep = 3; //6; -var svgWidth = 650; //parseInt($(svg).css("width")); -var svgHeight = 450; //parseInt($(svg).css("height")); -var layerCX = svgWidth/2*globalScale; -var layerCY = svgHeight/2*globalScale; -var layerOffsetY= 360; -var prevX = 0; -var prevY = 0; -var highlight = true; //highlight bottom, middle and top layers - -function redrawPreview() { - var svgData = path.attributes.d.nodeValue; - var linesRaw = svgData.match(svgPathRegExp); - console.log("svgData: " + svgData); - console.log("linesRaw: " + linesRaw); - console.log(""); -// console.log(""); - var lines = new Array(); - for(var i=0;i