// create a short variable name to represent the mouse position var mouse = smartShape.currentMousePos; /** * SetBezierNodePosition sets the position of the passed node to the * position of the point pt parameter. All node control points are * set to this point as well * Requires: SetBezierNodePosition */ SetNodePosition = function(node, pt){ SetBezierNodePosition(node, pt,pt,pt); // set point position for all nodes to pt } /** * SetBezierNodePosition sets the position of the passed node to the * position of the points ptp (node predecessor), pt (main point), and * pts (node successor) */ SetBezierNodePosition = function(node, ptp, pt, pts){ node.predX = ptp.x; node.predY = ptp.y; // Predecessor point node.x = pt.x; node.y = pt.y; // Main points node.succX = pts.x; node.succY = pts.y; // Successor points } /** * AddPoints adds two points pt1 and pt2 and returns the resulting point */ AddPoints = function(pt1, pt2){ return {x:pt1.x + pt2.x, y:pt1.y + pt2.y}; // add x and y properties in returned object } // create new path as first element in elements array smartShape.elem.elements[0] = new Path(); // create new contour as first contour in contours array smartShape.elem.elements[0].contours[0] = new Contour(); // set the contour to be a closed contour smartShape.elem.elements[0].contours[0].isClosed = true; // assign a short variable to represent the nodes array var nods = smartShape.elem.elements[0].contours[0].nodes; // create 4 nodes in the contour by altering the nodes array (nods) length nods.length = 4; // set the position of the 4 nodes in the first contour in a box shape // each point is based around a zero location and then has added to it // the position of the mouse using AddPoints. This makes the position of // the points around the position of the mouse. SetNodePosition(nods[0], AddPoints(mouse, {x:-25, y:-25})); SetNodePosition(nods[1], AddPoints(mouse, {x:25, y:-25})); SetNodePosition(nods[2], AddPoints(mouse, {x:25, y:25})); SetNodePosition(nods[3], AddPoints(mouse, {x:-25, y:25})); // create new contour as second contour in contours array smartShape.elem.elements[0].contours[1] = new Contour(); // set the contour to be a closed contour smartShape.elem.elements[0].contours[1].isClosed = true; // assign a short variable to represent the nodes array nods = smartShape.elem.elements[0].contours[0].nodes; // create 4 nodes in the contour by altering the nodes array (nods) length nods.length = 4; // set the position of the 4 nodes in the second contour in a box shape // that lies within the box shape of the first contour also positioned // around the location of the mouse SetNodePosition(nods[0], AddPoints(mouse, {x:-15, y:-15})); SetNodePosition(nods[1], AddPoints(mouse, {x:15, y:-15})); SetNodePosition(nods[2], AddPoints(mouse, {x:15, y:15})); SetNodePosition(nods[3], AddPoints(mouse, {x:-15, y:15}));