UniquePineapple UniquePineapple - 9 months ago 36
Javascript Question

Draw upper half of a string in Javascript

If I have a string, such as

"Hello World!"
How would I draw only the upper half of said string to a javascript canvas?

I would want it to appear like


using the .clip() method, you can specify a section of the canvas in which to draw with anything outside the clipping region being omitted; a la:

<body style="background:black;">
<canvas id="myCanvas" width="300" height="200"></canvas>

    var c=document.getElementById("myCanvas");
    var ctx=c.getContext("2d");
    // Clip a rectangular area
    // Draw text into clip()
    ctx.font = "30px Arial";
    ctx.fillText("Hello World",60,110);


see this entry for details

good luck!