I am quite new in web dev. I want animate text on JavaScript, after a defined event. Found am example animating a line drawing, but the method does not work on arcs (how to animate drawing lines on canvas example: http://jsfiddle.net/m1erickson/7faRQ/. Scrolled through and found a way (http://jsfiddle.net/loktar/uhVj6/4/), but only to extent of dozen letters. After a number of lines animated the inaccuracy escalate, yet the animation shortens and I can't find a solution to control these factors. Lets say the letter 'P' would be:
var l = 10 //factor of scale
function line010(current) {
context.beginPath();
context.moveTo(x-5*l, y-3/2*l);
context.lineTo(x-5*l, y-3/2*l-4*l*current);
context.stroke();
curPerc++;
if (curPerc < endPerc) {
requestAnimationFrame(function () {
line010(curPerc / 100)
});
}
}
function line011(current) {
context.beginPath();
context.moveTo(x-5*l, y-11/2*l);
context.lineTo(x-5*l+3/2*l*current, y-11/2*l);
context.stroke();
curPerc++;
if (curPerc < endPerc) {
requestAnimationFrame(function () {
line011(curPerc / 100)
});
}
}
function arc012(current) {
context.beginPath();
context.arc(x-7/2*l, y-9/2*l, l, -1/2*Math.PI, Math.PI*current-1/2*Math.PI);
context.stroke();
curPerc++;
if (curPerc < endPerc) {
requestAnimationFrame(function () {
arc012(curPerc / 100)
});
}
}
function line013(current) {
context.beginPath();
context.moveTo(x-7/2*l, y-7/2*l);
context.lineTo(x-7/2*l-l*current, y-7/2*l);
context.stroke();
curPerc++;
if (curPerc < endPerc) {
requestAnimationFrame(function () {
line013(curPerc / 100)
});
}
}
Any error to point out or other more convenient method to create a set of uniform alphabets, and animate a text on function calling? Where I can insert text and it compile the function, eg.
function draw("insertText")
{
A();
B();
C();
-
-
-
!();
&();
-
-
-
}(1000);
onload.draw(Thanks for your help!);
Shows an animation on canvas drawing 'Thanks for your help!'
EDIT: the visual output is seen in the following pictures(single letter/four lines vs. dozen letters/fifty lines):