model.context.setTransform(1,0,0,1,0,0);
var x = 100;
var y = 100;
var width = model.width;
var height = 100;
cX = x + width*0.5;
cY = y + height*0.5;
model.context.translate(x + .5*width, y + .5*height);
model.context.rotate(ang);
model.context.fillStyle = model.bgColor;
model.context.fillRect(-0.5*width, -0.5*height, width, height);
}
updateRectangle(model.angle);// display the rectangle/square
$( model.cnv ).mousedown(function(event){
// calculate click angle minus the last angle
var clickAngle = getAngle( cX + offX, cY + offY, event.clientX, event.clientY ) - model.angle;
$( model.cnv ).bind("mousemove", clickAngle, function(event){
// calculate move angle minus the angle onclick
model.angle = ( getAngle( cX + offX, cY + offY, event.clientX, event.clientY ) - clickAngle);
updateRectangle(model.angle);
});
});
So what i want is the following;
A image needs to be rotated by dragging like it does right now with the red square, now you can add a bgColor to the model but i can't seem to figure out how to replace te color with an image.
Could somebody help me with this?
11-09-2012, 03:51 PM
ReFreezed
Code:
model.img = img;
One problem is that 'img' is undefined here. Something like this will get the <img src="img.jpg"> element you have:
Code:
model.img = $(".picture img").get(0);
Then add this line in the updateRectangle() function to draw the image when dragging: