puzzle 3.0

bezier curves to make the shapes, rotation works, dragging and dropping works, theres no snapping or locking yet

by Darby Rathbone

HTML

<script src="http://www.prlog.org/11949574-hot-girl.jpg"></script>
<img hidden=true id="image" style="position:absolute;visibility:hidden;" src="http://www.gstatic.com/tv/thumb/movieposters/170620/p170620_p_v8_al.jpg"></img>

JavaScript

function clone(obj) {
    if (null === obj || "object" != typeof obj) return obj;
    var copy = obj.constructor();
    for (var attr in obj) {
        if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
    }
    return copy;
}

function Point(x, y) {
    this.x = x;
    this.y = y;
    this.d = Math.sqrt(x * x + y * y);
    return this;
}
Point.prototype = {
    slopeTo: function (p) {
        return (this.y - p.y) / (this.x - p.x);
    },
    distanceTo: function (p) {
        return (Math.sqrt(((this.y - p.y) * (this.y - p.y)) + ((this.x - p.x) * (this.x - p.x))));
    },
    distanceByAxis: function (p) {
        return (new Point(this.x - p.x, this.y - p.y));
    },
    normalize: function () {
        return new Point(this.x / this.d, this.y / this.d);
    }
};
var puzzlePiece = (function () {
    function puzzlePiece(obj) {

        this.imgtop = clone(obj.top);

        this.imgright = clone(obj.right);
        this.imgbottom = clone(obj.bottom);
        this.imgleft = clone(obj.left);
        this.rotation = obj.rotation;
        this.image = obj.image;
        this.width = obj.width + 0;
        this.height = obj.height + 0;
        this.canvas = document.createElement("canvas");

        this.canvas.rotation = 0;
        this.connected = [];
        this.canvas.setAttribute("style", "position:absolute;");
        this.canvas.setAttribute("width", obj.width * 3);
        this.canvas.setAttribute("height", obj.height * 3);
        this.canvas.style.setProperty("top", this.imgtop.first.y + 1 + "px");
        this.canvas.style.setProperty("left", this.imgtop.first.x + 1 + "px");
        //this.canvas.ondblclick = dblclick;

        this.context = this.canvas.getContext('2d');


        document.body.appendChild(this.canvas);
        this.top = {
            "first": new Point((this.canvas.height / 2) - (obj.width / 2.0), (this.canvas.height / 2) - (obj.height / 2.0)),
                "last": new Point((this.canvas.height / 2) + (obj.width / 2.0),...