0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-16 15:47:55 +01:00
doodle3d-client/js_src/Shape.js
2013-12-20 16:31:41 +01:00

43 lines
978 B
JavaScript

/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
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<=Math.PI*2; a+=step) {
var x = Math.sin(a) * r + x0;
var y = Math.cos(a) * r + y0;
if (a==0) shapeMoveTo(x,y);
else shapeLineTo(x,y);
}
endShape();
}
function beginShape(x,y) {
setSketchModified(true);
}
function shapeMoveTo(x,y) {
_points.push([x, y, true]);
adjustBounds(x, y)
adjustPreviewTransformation();
draw(x, y, .5);
}
function shapeLineTo(x,y) {
_points.push([x, y, false]);
adjustBounds(x, y)
adjustPreviewTransformation();
draw(x, y);
}
function endShape() {
renderToImageDataPreview();
}