var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var canvasOffset = $("#canvas").offset();
var offsetX = canvasOffset.left;
var offsetY = canvasOffset.top;
// animation variables
var currentX = 10;
var currentY = 10;
var frameCount = 60;
var timer;
var points;
var currentFrame;
var img=document.getElementById("image1");
var angleDegrees = 0;
function animate() {
var point = points[currentFrame++];
draw(point.x, point.y, point.angle);
// refire the timer until out-of-points
if (currentFrame < points.length) {
timer = setTimeout(animate, 1000 / 60);
}
}
function linePoints(x1, y1, x2, y2, frames) {
var dx = x2 - x1;
var dy = y2 - y1;
var aEnd = Math.PI * 2;
var length = Math.sqrt(dx * dx + dy * dy);
var incrementX = dx / frames;
var incrementY = dy / frames;
var incrementA = aEnd / frames;
var a = new Array();
a.push({
x: x1,
y: y1
});
for (var frame = 0; frame < frames - 1; frame++) {
a.push({
x: x1 + (incrementX * frame),
y: y1 + (incrementY * frame),
angle: incrementA * frame
});
}
a.push({
x: x2,
y: y2,
angle: aEnd
});
return (a);
}
function draw(x, y, angle) {
clearCanvas(ctx, canvas);
ctx.save(); // Save coordinte system
ctx.translate(x, y); // Translate moves the center of the canvas to x, y
ctx.rotate(angle); // Rotate rotaes around the center of the canvas
ctx.drawImage(img, -(img.width/2),...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.