<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>https://web.dev/</id>
  <title>James Williams on web.dev</title>
  <updated>2026-04-15T23:21:06Z</updated>
  <author>
    <name>James Williams</name>
  </author>
  <link href="https://web.dev/authors/jameswilliams/feed.xml" rel="self"/>
  <link href="https://web.dev/"/>
  <icon>https://web-dev.imgix.net/image/T4FyVKpzu4WKF1kBNvXepbi08t52/XAcwYmIIXpwKmGY5oUsy.png?auto=format</icon>
  <logo>https://web.dev/images/shared/rss-banner.png</logo>
  <subtitle>Independent Developer</subtitle>
  
  
  <entry>
    <title>Introduction to Raphaël.js</title>
    <link href="https://web.dev/raphael/"/>
    <updated>2011-09-08T00:00:00Z</updated>
    <id>https://web.dev/raphael/</id>
    <content type="html" mode="escaped">&lt;h2 id=&quot;introduction&quot;&gt;Introduction &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#introduction&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;SVG, short for Scalable Vector Graphics, is a XML-based language for
describing objects and scenes. SVG elements can fire events and can be
scripted with JavaScript. SVG comes with several built-in primitive types such
as circles and rectangles as well as being able to display text. While SVG as
a technology is not new, HTML5 now enables SVG objects
to be embedded in a page directly without the use of a &lt;code&gt;&amp;lt;object&amp;gt;&lt;/code&gt;
or &lt;code&gt;&amp;lt;embed&amp;gt; &lt;/code&gt;tag bringing it in line with what is currently
available with the canvas. &lt;a href=&quot;http://raphaeljs.com/&quot; rel=&quot;noopener&quot;&gt;Raphaël.js&lt;/a&gt;
is a JavaScript library that allows you to create SVG scenes programmatically.
It uses a unified API to create SVG scenes where it is supported or
VML(Vector Modeling Language) where it is now, namely Internet Explorer
versions before IE9.&lt;/p&gt;
&lt;h2 id=&quot;drawing-your-first-scene&quot;&gt;Drawing Your First Scene &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#drawing-your-first-scene&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Let&#39;s begin by drawing a simple scene with Raphaël. We begin drawing the
scene by instantiating a Raphaël object. In this case,
I used the constructor that inserts it into a given HTML element with a given
width and height but you could also have Raphaël append the object to the DOM
(Document Object Model). Next, I created a rectangle by supplying the desired
x and y positions with the width and height. Next, I created a circle by
giving the desired coordinates and radius. Finally, I used the attribute function
(attr) to assign colors to the objects.&lt;/p&gt;
&lt;p&gt;Each SVG object can have attributes
assigned to it for things like the color, rotation, stroke color and size,
etc. You can find a detailed list of assignable attributes &lt;a href=&quot;http://raphaeljs.com/reference.html#attr&quot; rel=&quot;noopener&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; paper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Raphael&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;sample-1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;75&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rect &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; circle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;circle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;110&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;circle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;blue&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h2 id=&quot;drawing-advanced-shapes-with-paths&quot;&gt;Drawing Advanced Shapes with Paths &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#drawing-advanced-shapes-with-paths&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A path is a series of instructions used by the renderer to create objects.
Drawing with a path is like drawing with a pen on a giant piece of graph paper.
You can instruct the pen to be lifted from the paper and move to a different
position(move to), to draw a line(line to), or to draw a curve(arc to). Paths
enable SVG to create objects with the same level of detail regardless of the
scale. When you issue an instruction to say, draw a curve, SVG takes into
account the original and final desired size of the curve (after scaling), it
mathematically computes the intermediary points to render a smooth curve.&lt;/p&gt;
&lt;p&gt;The code and figure below show a rectangle and closed curved drawn with paths.
The letter M followed by coordinates moves the pen to that position, L followed
by coordinate pair draws a line from that the current position to that position.
s draws a smooth Bezier curve with a given control point and endpoint with
relative coordinates. Z closes a path. Generally, using an uppercase letter issues the command
with absolute coordinates, lowercase uses relative coordinates. M/m and Z/z,
respectively, issue the same command for uppercase or lowercase.
You can view a list of all the path instructions &lt;a href=&quot;http://www.w3.org/TR/SVG/paths.html&quot; rel=&quot;noopener&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; paper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Raphael&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;sample-2&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rectPath &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;M10,10L10,90L90,90L90,10Z&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; curvePath &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;M110,10s55,25 40,80Z&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;rectPath&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;curvePath&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;blue&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h2 id=&quot;drawing-text&quot;&gt;Drawing Text &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#drawing-text&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Having illustrations without the ability to draw text would be really boring,
luckily, Raphaël provides two methods to draw text. The first method, text,
takes a x and y coordinates along with the string to draw. The text method
doesn&#39;t give you much control over the font or other effects. It draws in the
default font with the default size.&lt;/p&gt;
&lt;p&gt;The second method, print, draws the text as a collection of paths. As a result,
we are able to modify individual letters. In the example below, we colored the
numeral 5 with an orange fill, colored &amp;quot;ROCKS&amp;quot; with a bluish fill and made the
stroke thicker to simulate bold text. We did this using a custom font with a
font size of 40pts.&lt;/p&gt;
&lt;div&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; paper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Raphael&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;sample-4&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; t &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;HTML5ROCKS&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; letters &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;HTML5ROCKS&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; paper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getFont&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Vegur&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;letters&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;orange&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; letters&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br /&gt;letters&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#3D5C9D&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string-property property&quot;&gt;&quot;stroke-width&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;2&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#3D5C9D&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;The Vegur font isn&#39;t in Raphaël, nor is any font for that matter. And besides,
most fonts use TrueType(TTF) or OpenType(OTF) format. To get from those formats
into something that is usable by Raphaël, we need to convert them using a tool
called &lt;a href=&quot;https://github.com/sorccu/cufon/wiki/about&quot; rel=&quot;noopener&quot;&gt;Cufon&lt;/a&gt;. Cufon allows you export the different font styles
of a given font (regular, bold, italic, bold italic, etc) for use with Raphaël.
It is outside the scope of this tutorial to cover Cufon in detail. Check
the aforemention link for more details. A great source of unemcumbered fonts for
your applications is the &lt;a href=&quot;http://www.google.com/webfonts&quot; rel=&quot;noopener&quot;&gt;Google Font Directory&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;events&quot;&gt;Events &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#events&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;SVG elements can directly subscribe to all the traditional mouse-based events:
&lt;strong&gt;click, dblclick, mousedown, mousemove, mouseout, mouseover, mouseup, and hover&lt;/strong&gt;.
Raphaël provides the ability to add your own methods to either the canvas or
individual elements, so in theory there is nothing preventing you from adding
gestures for mobile browsers.&lt;/p&gt;
&lt;p&gt;The snippet below binds a function to rotate a given letter in &amp;quot;ROCKS&amp;quot; 45
degrees when it is clicked.&lt;/p&gt;
&lt;div&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; letters&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br /&gt;letters&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token literal-property property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#3D5C9D&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string-property property&quot;&gt;&quot;stroke-width&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;2&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#3D5C9D&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;letters&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;evt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;h2 id=&quot;svg-vs-canvas&quot;&gt;SVG vs Canvas &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#svg-vs-canvas&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Given that they are both methods to draw objects on the screen, it&#39;s often
not immediately clear why you should use one over the other. The two mediums
have vastly different approaches. Canvas is an immediate mode API is much like
drawing with crayons. You can clear or destroy part
of the drawing but you can&#39;t by default revert or alter a previous stroke. Canvas
is also a raster bitmap so it is is very much subject to pixelation when images
are scaled. SVG on the other hand, as previously mentioned can serve multiple
resolutions with the same level of detail and can be scripted.&lt;/p&gt;
&lt;p&gt;Whether to use SVG or Canvas for game programming is fairly simple. Besides
the normal constraints of whether you plan to deploy to desktop or mobile, it
really comes down to sprite count. SVG lends itself to what I&#39;d call low-fidelty
games. I describe those as games that have limited concurrent movement of objects
and sprite removal and creation. Many board games like Chess, Checkers, or Battleship, as
well as card games like BlackJack, Poker, and Hearts fall into this category.
Another unifying thread is that in many of these games, a player will need
to move an arbitrary object and SVG&#39;s scriptability makes object picking
easy.&lt;/p&gt;
&lt;h2 id=&quot;authoring-tools-for-svg&quot;&gt;Authoring Tools for SVG &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#authoring-tools-for-svg&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Using SVG doesn&#39;t mean at all that you have to create paths by hand. There
are several tools, both open source and commercial, that allow you to export to
SVG. The two tools I have used extensively and highly recommend are
&lt;a href=&quot;http://inkscape.org/&quot; rel=&quot;noopener&quot;&gt;Inkscape&lt;/a&gt; and &lt;a href=&quot;http://code.google.com/p/svg-edit&quot; rel=&quot;noopener&quot;&gt;svg-edit&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;svg-edit&quot;&gt;svg-edit &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#svg-edit&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;svg-edit is a browser-based SVG editor written in JavaScript.
It provides a limited user interface reminiscent of GIMP or MS Paint. Unless the
level of detail was relatively low, I&#39;ve mostly used svg-edit to tweak SVG
drawings rather than create them. svg-edit allows you to create objects graphically
or with SVG code.&lt;/p&gt;
&lt;h3 id=&quot;inkscape&quot;&gt;Inkscape &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#inkscape&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Inkscape is a cross-platform full-fledged vector graphics editor similar to CorelDraw,
Adobe Illustrator, and Xara. Inkscape benefits from a vibrant plugin community and a
mature codebase. The predecessor to Inkscape, from which Inkscape forked, was
developed in 1999. Inkscape is my go-to application for vector-based and bitmap
assets.&lt;/p&gt;
&lt;h2 id=&quot;a-minor-aside&quot;&gt;A Minor Aside &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#a-minor-aside&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;SVG is not supported on Windows in Internet Explorer versions before IE9.
IE uses a vector graphics format called VML, Vector Markup Language, which
provides much of the same functionality as SVG. Raphaël
can create scenes that use SVG or VML where it is supported. Using Raphaël
is an easy way to provide cross-platform support.&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/raphael/#references&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Rapahël.js: &lt;a href=&quot;http://raphaeljs.com/&quot; rel=&quot;noopener&quot;&gt;http://raphaeljs.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Raphaël Documentation: &lt;a href=&quot;http://raphaeljs.com/reference.html&quot; rel=&quot;noopener&quot;&gt;http://raphaeljs.com/reference.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
    <author>
      <name>James Williams</name>
    </author>
  </entry>
</feed>
