function drawCircle(x0,y0,r,res) { if (res==undefined) res = 50; //circle resolution beginShape(); var step = Math.PI * 2.0 / res; for (var a=0; a= 1.0 ? 1 : 0; zoomValue = Math.min(zxMax, zyMax); if (dir == 1 && zoomValue < 1.0) zoomValue = 1; console.log("orgZV, zxMax, zyMax, finZV: " + oldZV + ", " + zxMax + ", " + zyMax + ", " + zoomValue); translatePoints(_points, delta.x, delta.y); //move points towards center as far as necessary to avoid clipping translatePoints(_points,-bounds.x,-bounds.y); translatePoints(_points,-bounds.width/2,-bounds.height/2); scalePoints(_points,zoomValue,zoomValue); translatePoints(_points,bounds.width/2,bounds.height/2); translatePoints(_points,bounds.x,bounds.y); updateView(); } function rotateShape(radians) { var bounds = getBounds(_points); var cx = bounds.x + bounds.width/2; var cy = bounds.y + bounds.height/2; rotatePoints(_points, radians, cx, cy); updateView(); } function updateView() { setSketchModified(true); redrawDoodle(); adjustPreviewTransformation(); renderToImageDataPreview(); if (debugMode) { var bounds = getBounds(_points); drawCircleTemp(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, 5, 'red'); } } //returns (dx,dy) updated such that it moving bounds by that amount still fits inside canvas //if dx,dy == 0,0, it is assumed that bounds do not fit to begin with, so a delta is returned to minimize clipping on all sides (for zooming) function clipDeltaToCanvas(dx, dy, bounds) { dx = Math.max(dx, -bounds.x); dx = Math.min(dx, canvasWidth - (bounds.x + bounds.width)); dy = Math.max(dy, -bounds.y); dy = Math.min(dy, canvasHeight - (bounds.y + bounds.height)); return { x: dx, y: dy }; } //*draws* a circle (i.e. it is not added as points to shape) function drawCircleTemp(x, y, r, color) { ctx.beginPath(); ctx.lineWidth = 1; ctx.fillStyle = color; ctx.arc(x, y, r, 0, 2 * Math.PI, false); ctx.fill(); ctx.stroke(); ctx.fillStyle = 'black'; }