2012-09-07 3 views
4

텍스트를 시계 반대 방향으로 쓰려면 어떻게해야합니까?텍스트를 시계 반대 방향으로 쓰는 방법

function drawTextAlongArc(context, str, centerX, centerY, radius, angle){ 
    context.save(); 
    context.translate(centerX, centerY); 
    context.rotate(-1 * angle/2); 
    context.rotate(-1 * (angle/str.length)/2); 
    for (var n = 0; n < str.length; n++) { 
     context.rotate(angle/str.length); 
     context.save(); 
     context.translate(0, -1 * radius); 
     var char = str[n]; 
     context.fillText(char, 0, 0); 
     context.restore(); 
    } 
    context.restore(); 
} 

window.onload = function(){ 
    var canvas = document.getElementById("myCanvas"); 
    var context = canvas.getContext("2d"); 

    context.font = "30pt Calibri"; 
    context.textAlign = "center"; 
    context.fillStyle = "blue"; 
    context.strokeStyle = "blue"; 
    context.lineWidth = 4; 

    var centerX = canvas.width/2; 
    var centerY = canvas.height - 30; 
    var angle = Math.PI * 0.8; // radians 
    var radius = 150; 
    drawTextAlongArc(context, "Text along arc path", centerX, centerY, radius, angle); 

    // draw circle underneath text 
    context.arc(centerX, centerY, radius - 10, 0, 2 * Math.PI, false); 
    context.stroke(); 
}; 

나는 반 시계 방향이 enter image description here 당신이 요구하는지

답변

4

확실하지 같이 표시 텍스트를 원하지만 당신은 시계 반대 방향으로 거꾸로 텍스트를 작성하려는 경우, 당신은 좋겠

drawTextAlongArc(context, "Text along arc path", centerX, centerY, radius, -angle); 

마지막 인자 요로, 텍스트 거꾸로 생각 될 것입니다 -angle

변경이 줄을 변경 기대 하리라.

+0

예 텍스트가 뒤로 가야합니다. – Anish

관련 문제