html5 - filltext without coordinates -
so have made circle in canvas, , i'm trying have line of text in it. problem is, filltext code line generates text @ particular given coordinate, dont want that.
is there way have line of text stay inside circle?
var programfill = function ( context ) { context.beginpath(); context.arc( 0, 0, 1, 0, pi2, true ); context.font="20px georgia"; context.filltext("hello world!",10,50); context.closepath(); context.fill(); }
draw filled text inside circle
here's example of how put text inside circle: http://jsfiddle.net/m1erickson/bukkt/
notice context.beginpath() called twice because doing 2 fills. first draw filled circle , second change fill color , draw filled text.
and here code:
<!doctype html> <html> <head> <link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css --> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <style> body{ background-color: ivory; padding:10px; } canvas{border:1px solid red;} </style> <script> $(function(){ var canvas1=document.getelementbyid("canvas"); var context=canvas1.getcontext("2d"); context.beginpath(); context.fillstyle="yellow"; context.strokestyle="black"; context.font="20px georgia"; context.linewidth=10; context.arc(100,100, 75, 0 , 2 * math.pi, false); context.fill(); context.beginpath(); context.fillstyle="red"; context.filltext("hello world!",40,100); context.fill(); }); // end $(function(){}); </script> </head> <body> <canvas id="canvas" width=300 height=300></canvas><br/> </body> </html>
Comments
Post a Comment