{"id":1479,"date":"2010-09-16T22:21:00","date_gmt":"2010-09-17T04:21:00","guid":{"rendered":"http:\/\/www.evolutionarydesigns.net\/blog\/2010\/09\/16\/use-html5-canvas-elemnt-to-create-graphic-text\/"},"modified":"2010-09-17T23:11:54","modified_gmt":"2010-09-18T05:11:54","slug":"use-html5-canvas-elemnt-to-create-graphic-text","status":"publish","type":"post","link":"http:\/\/www.evolutionarydesigns.net\/blog\/2010\/09\/16\/use-html5-canvas-elemnt-to-create-graphic-text\/","title":{"rendered":"Use HTML5 Canvas Element to Create Graphic Text"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/www.evolutionarydesigns.net\/blog\/wp-content\/uploads\/2010\/09\/1284786155_firefox.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" style=\"display: inline; margin-left: 0px; margin-right: 0px; border: 0px;\" title=\"Firefox\" src=\"https:\/\/i0.wp.com\/www.evolutionarydesigns.net\/blog\/wp-content\/uploads\/2010\/09\/1284786155_firefox_thumb.png?resize=200%2C200\" border=\"0\" alt=\"Firefox\" width=\"200\" height=\"200\" align=\"left\" \/><\/a> In this installment of the HTML5 canvas element I want to show you another cool graphic that you can use on your site. This usage of the canvas tool is a little different. Instead of drawing a graphic with shapes, you can use the canvas element to draw text graphics.<\/p>\n<p>I came across this example a few weeks go and thought I would share it with you. If you know JavaScript, you can easily go into the code and modify it. If not you can go in and change the color theme, fonts and the size of the palette. But it\u2019s really easy to change the colors by changing the var textthem. The color is code using the hexadecimal numbers and then you can change the font by changing the variables on textfont to different. If you want to change the size of the canvas, you can do this by changing\u00a0 canvas size and the <code>var x = Math.random() * 650; and var y = Math.random() * 150; The x and y numbers (650 and 150)are the numbers you can change. The x will change the horizontal of an image and y will change the height of the image. <\/code><\/p>\n<p><strong><span style=\"color: #ff0000;\">NOTE:<\/span> As the writing of this article, there is not an option to download new web fonts. It safe to use fonts that comes by default on all computers.<\/strong><\/p>\n<p><a href=\"http:\/\/www.evolutionarydesigns.net\/demo\/cavastext.html\" target=\"_blank\">Click Here to View the Demo<\/a><\/p>\n<h3>Example Code<\/h3>\n<p>[js]<br \/>\n&lt;canvas id=&quot;textCanvas&quot; width=&quot;650&quot;  height=&quot;150&quot;&gt;&lt;\/canvas&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot;&gt;<br \/>\nvar  textcanvas, textgraphics;<br \/>\nfunction textdraw_init() {<br \/>\ntextcanvas =  document.getElementById(&#8216;textCanvas&#8217;);<br \/>\nif  (textcanvas.getContext){<br \/>\ntextgraphics =  textcanvas.getContext(&#8216;2d&#8217;);<br \/>\n}<br \/>\ntextdraw();<br \/>\n}<br \/>\nfunction textdraw()  {<br \/>\nvar texttheme = [&quot;#000000&quot;,&quot;#001AFF&quot;,&quot;#3B00FF&quot;,&quot;#F7F7F&quot;,&quot;#3F00FF&quot;];<br \/>\nvar  textfont = [&quot;Arial&quot;,&quot;Times New Roman&quot;,&quot;Comic Sans  MS&quot;,&quot;Papyrus&quot;,&quot;Baskerville&quot;];<br \/>\nvar x = Math.random() * 650;<br \/>\nvar y =  Math.random() * 150;<br \/>\nvar size = (Math.random() * 50) +  10;<br \/>\ntextgraphics.font = size+&quot;px &#8216;&quot;+textfont[ (Math.random() * 5 &gt;&gt;  0)]+&quot;&#8217;&quot;;<br \/>\nif (Math.random() &gt; .5) {<br \/>\ntextgraphics.fillStyle = texttheme[  (Math.random() * 5 &gt;&gt; 0)];<br \/>\ntextgraphics.fillText(&quot;Evolutionary  Designs&quot;, x, y);<br \/>\n} else {<br \/>\ntextgraphics.strokeStyle = texttheme[  (Math.random() * 5 &gt;&gt; 0)];<br \/>\ntextgraphics.strokeText(&quot;Evolutionary  Designs&quot;, x, y);<br \/>\n}<\/p>\n<p>t =  setTimeout(&#8216;textdraw()&#8217;,950);<br \/>\n}<br \/>\ntextdraw_init();<br \/>\n&lt;\/script&gt;<br \/>\n[\/js]<\/p>\n<h3>Demo Code<\/h3>\n<p>[html]<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;Canvas Text Demo and  Tutorial&lt;\/Title&gt;<br \/>\n&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html;  charset=utf-8&quot;&gt;&lt;style type=&quot;text\/css&quot;&gt;<br \/>\n&lt;!&#8211;<br \/>\nh1 {<br \/>\nfont-size:  36px;<br \/>\n}<br \/>\n&#8211;&gt;<br \/>\n&lt;\/style&gt;&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;h1  align=&quot;left&quot;&gt;Canvas Text Demo and Tutorial  &lt;\/h1&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;canvas id=&quot;textCanvas&quot; width=&quot;650&quot;  height=&quot;150&quot;&gt;&lt;\/canvas&gt;<\/p>\n<p>&lt;div align=&quot;left&quot;&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot;&gt;<br \/>\nvar  textcanvas, textgraphics;<br \/>\nfunction textdraw_init() {<br \/>\ntextcanvas =  document.getElementById(&#8216;textCanvas&#8217;);<br \/>\nif  (textcanvas.getContext){<br \/>\ntextgraphics =  textcanvas.getContext(&#8216;2d&#8217;);<br \/>\n}<br \/>\ntextdraw();<br \/>\n}<br \/>\nfunction textdraw()  {<br \/>\nvar texttheme = [&quot;#000000&quot;,&quot;#001AFF&quot;,&quot;#3B00FF&quot;,&quot;#F7F7F&quot;,&quot;#3F00FF&quot;];<br \/>\nvar  textfont = [&quot;Arial&quot;,&quot;Times New Roman&quot;,&quot;Comic Sans  MS&quot;,&quot;Papyrus&quot;,&quot;Baskerville&quot;];<br \/>\nvar x = Math.random() * 650;<br \/>\nvar y =  Math.random() * 150;<br \/>\nvar size = (Math.random() * 50) +  10;<br \/>\ntextgraphics.font = size+&quot;px &#8216;&quot;+textfont[ (Math.random() * 5 &gt;&gt;  0)]+&quot;&#8217;&quot;;<br \/>\nif (Math.random() &gt; .5) {<br \/>\ntextgraphics.fillStyle = texttheme[  (Math.random() * 5 &gt;&gt; 0)];<br \/>\ntextgraphics.fillText(&quot;Evolutionary  Designs&quot;, x, y);<br \/>\n} else {<br \/>\ntextgraphics.strokeStyle = texttheme[  (Math.random() * 5 &gt;&gt; 0)];<br \/>\ntextgraphics.strokeText(&quot;Evolutionary  Designs&quot;, x, y);<br \/>\n}<\/p>\n<p>t =  setTimeout(&#8216;textdraw()&#8217;,950);<br \/>\n}<br \/>\ntextdraw_init();<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>[\/html]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this installment of the HTML5 canvas element I want to show you another cool graphic that you can use on your site. This usage of the canvas tool is a little different. Instead of drawing a graphic with shapes, you can use the canvas element to draw text graphics. I came across this example [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[597,359,598,599,133],"class_list":["post-1479","post","type-post","status-publish","format-standard","hentry","category-web-design","tag-canvas-text-element","tag-html5","tag-html5-graphics","tag-html5-snippets","tag-javascript","entry","has-post-thumbnail"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pJPdG-nR","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/posts\/1479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/comments?post=1479"}],"version-history":[{"count":0,"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/posts\/1479\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/media?parent=1479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/categories?post=1479"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.evolutionarydesigns.net\/blog\/wp-json\/wp\/v2\/tags?post=1479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}