<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>eleqtriq</title> <atom:link href="http://www.eleqtriq.com/feed/" rel="self" type="application/rss+xml" /><link>http://www.eleqtriq.com</link> <description>Tweaking bytes at 72 dots per inch</description> <lastBuildDate>Wed, 27 Mar 2013 08:02:05 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Finally! csswarp.js for dynamic Text warping</title><link>http://www.eleqtriq.com/2012/02/geschafft-csswarp-js-fur-dynamisches-text-warping/</link> <comments>http://www.eleqtriq.com/2012/02/geschafft-csswarp-js-fur-dynamisches-text-warping/#comments</comments> <pubDate>Fri, 10 Feb 2012 10:53:03 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Typography]]></category> <category><![CDATA[CSS3 transforms]]></category> <category><![CDATA[HTML-formatting]]></category> <category><![CDATA[Illustrator]]></category> <category><![CDATA[text on a path]]></category> <category><![CDATA[text warping]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=1002</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/uploads/2012/02/csswarpjs_feature.png" width="218"height="80" alt="HTML text warping"/>Finally the first incarnation of csswarp.js is ready. Now it's possible to have warped text that follows a path even when content is served dynamically. An extensive set of configuration options gives you the ability to control every aspect of your warp.]]></description> <content:encoded><![CDATA[<p>I proudly present the first version of <a href="https://github.com/dirkweber/csswarp.js" title="download.csswarp.js from github">csswarp.js</a>. This small (<8kb, minified, unzipped) library does the same thing  as <a href="http://csswarp.eleqtriq.com" title="Go to csswarp.com">csswarp.com</a>, but dynamically at runtime, making it possible to warp text that is not know in advance, i. e. when served from a cms. I added a ton of features, so you can adjust csswarp.js to your needs in every possible way. I plan to publish a documentation on csswarp.com, in the meantime use the docs on <a href="https://github.com/dirkweber/csswarp.js" title="download.csswarp.js from github">github</a>.</p><p class="aligncenter" ><a href="/wp-content/static/demos/2012/csswarpjs?iframe=true&amp;width=600&amp;height=600" rel="prettyPhoto[iframe]" id="csswarp" title="csswarp.js"><img class="aligncenter" src="http://www.eleqtriq.com/wp-content/uploads/2012/02/csswarpjs.png" width="450" height="448" title="csswarp"/></a></p> <a class="downloadexample" href="https://github.com/dirkweber/csswarp.js" title="Download csswarp.js">Download csswarp.js</a>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2012/02/geschafft-csswarp-js-fur-dynamisches-text-warping/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Better CSS Sprites with SVG</title><link>http://www.eleqtriq.com/2012/01/enhancing-css-sprites-and-background-image-with-svg/</link> <comments>http://www.eleqtriq.com/2012/01/enhancing-css-sprites-and-background-image-with-svg/#comments</comments> <pubDate>Mon, 02 Jan 2012 12:00:47 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[HTML]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Coding SVG]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[Frontend-development]]></category> <category><![CDATA[hack]]></category> <category><![CDATA[Optimization]]></category> <category><![CDATA[Speed]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=933</guid> <description><![CDATA[<img class="floatleft"  src="/wp-content/uploads/2012/01/gene.png" width="214" height="176" alt="gene" /> SVG CSS sprites offer some possibilities for webdevelopers that are superior to the "classical" CSS sprites. With SVG it is possible to get access to much needed properties like "background-rotation" or "background-opacity" that currently are missing from the CSS spec. This article shows how SVG can give us additional useful CSS tools for our frontend coding tasks.]]></description> <content:encoded><![CDATA[<p>For webdesigners it's still frustrating to deal with the limitations of the CSS "background-image" property. Sure, things have improved ten times with CSS3. We now are able to add multiple backgrounds, have a decent control of sizing and some clipping features. But where is "background-rotation"? Why isn't there a "background-opacity" or a "background-padding" attribute?</p><p> So in the end we often find ourselves creating another version of a bitmap if we want to rotate it or need some more padding, feeling guilty because we know that this will cause more traffic and additional http-requests.</p><p> I have good news for you: there actually exists a ridiculously easy method to have all this additional attributes and it is supported in every modern browser. Funny enough I did not notice it out in the wild many times. The trick is: create an SVG and use it as wrapper for your bitmap. All the transformations we need can be applied to the image within the SVG. And if it's supported by the browser we can even use these sexy SVG filters. As SVGs are styled with CSS, we can link to the very same stylesheets we use to style our HTML - a convenient way to change attributes consistently across the document.</p><p> Using SVG sprites offers a lot of benefits over <a href="http://www.alistapart.com/articles/sprites" title="A List Apart article on CSS Sprites from 2004">conventional sprites</a>. Size is not a problem, as a larger SVG doesn't mean bigger file size. Plenty of room to place elements wherever you want them, no need to break your head about the most efficient way to position your tiles. And it is possible to use .jpeg, .png, .webm or .gif together in one sprite. It's even possible to create alpha channels for JPEGs by putting them into a clipping path.</p><h3>Some Demos</h3><p> Demos open in new window. Did I mention that KISS is the greatest Rockband EVA?</p><ul class="svgdemos"><li> <a href="/wp-content/static/demos/2012/svgbg/bottomrightposition.html" title="Open demo in new window" class="newWin"><img src="/wp-content/uploads/2012/01/gene.png" width="214" height="176" alt="gene" /></a></li><li> <a href="/wp-content/static/demos/2012/svgbg/rotated.html" title="Open demo in new window" class="newWin"><img src="/wp-content/uploads/2012/01/ace.png" width="222" height="176" alt="ace"/></a></li><li> <a href="/wp-content/static/demos/2012/svgbg/clipped.html" title="Open demo in new window" class="newWin"><img src="/wp-content/uploads/2012/01/peter.png" width="175" height="176" alt="peter"/></a></li><li> <a href="/wp-content/static/demos/2012/svgbg/blurred.html" title="Open demo in new window" class="newWin"><img src="/wp-content/uploads/2012/01/paul.png" width="168" height="176" alt="paul"/></a></li></ul><h3>Caveats</h3><p> Linking to an SVG which in return links to a bitmap means more http requests and as we all have learned, this is a BAD thing. Therefore we should encode bitmaps to <a href="/de/2010/07/introducing-spritebaker/" title="spritebaker">base64</a> and embed them directly into the SVG. The SVG itself can be base64 encoded as well and embedded into the CSS.</p><p> Webkit is the only browser I know of that supports embedding utf8 into stylesheets, so there's no need for base64 encoding, we can paste the SVG code directly into the stylesheet (linebreaks aren't allowed of course ):</p> <code> <span>"background-image: url('data:image/svg+xml; charset=utf-8,&lt;svg&gt;&lt;/svg&gt;"</span> </code><p> Using a CSS sprite helps to reduce requests even more. SVG gives us the option to define elements in one place...</p> <code> <span>&lt;defs&gt;</span> <span> &lt;image id=&quot;image&quot; xlink:href=&quot;myimgage.png&quot;/&gt;</span> <span>&lt;/defs&gt;</span> </code><p>...and reuse them across the document:</p> <code> <span>&lt;use xlink:href=&quot;#image&quot; transform=&quot;fancytransformhere&quot;/&gt;</span> </code><p> But this is the web and as you may already have guessed, things are never as rosy as it seems at first glance. There is a certain browser all of you know too well that still needs hacks and tricks to behave like all the other kids. No, I'm not talking of IE, this time Webkit is the black sheep. When embedded as background image, Webkit refuses to load xlink references in the SVG, so images won't show up and external CSS have no effect. This means it is unavoidable to use only inline stylesheets and base64 encoded images if you need proper Webkit support. But even when base64 encoded, there is a bug in webkit that prevents images from showing up in background SVGs. This is because Webkit needs to "see" the SVG at document level at least one time. If this isn't the case, only the vector elements within an SVGs will appear in a background but inline bitmaps will stay invisible.</p><p> There is a hack for that, but it's ugly and advocates of proper semantics will hate it: embed the SVG into the html first, i. e. as an 1x1px sized, invisible SVG object. If you don't like this method, javascript comes to the rescue:</p> <code> <span>(function (svgpath){</span> <span> if( /webkit/gi.test(navigator.userAgent.toLowerCase()) ){</span> <span> var obj = document.createElement("object");</span> <span> obj.setAttribute("type", "image/svg+xml");</span> <span> obj.setAttribute("data", svgpath);</span> <span> obj.setAttribute("width", "1");</span> <span> obj.setAttribute("height", "1");</span> <span> obj.setAttribute("style", "width: 0px; height: 0px; position: absolute;visibility : hidden");</span> <span> document.getElementsByTagName("html")[0].appendChild(obj);</span> <span> }</span> <span>})("../img/mySVG.svg");</span> </code><p> You can remove the SVG object later when css have been loaded.</p><p> Recently I needed SVG sprite support in Webkit and created <a href="https://github.com/dirkweber/flattensvg.js" title="flattensvg.js on github">this little hack</a>. It parses a stylesheet for references to SVG background images, then parses every found SVG for stylesheets and images. It then replaces references to stylesheets with inline declarations and images with base64 encoded versions. Finally it will embed the resulting SVGs into the document and remove them after 1 second. At the same time references in the css are replaced with utf8 encoded SVGs.</p><p> If you pass "true" as a parameter for "viewSourceMode" (default is "false") it will display the source of all the fixed SVGs in teaxtareas for convenient copying.</p><p> Be careful when using it though, it's in alpha state at the moment and speed is an issue when using large and/or many image files, but it can be very helpful during development and for testing.</p>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2012/01/enhancing-css-sprites-and-background-image-with-svg/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Updated: traqball 2.0</title><link>http://www.eleqtriq.com/2011/11/traqball-2-0/</link> <comments>http://www.eleqtriq.com/2011/11/traqball-2-0/#comments</comments> <pubDate>Fri, 25 Nov 2011 23:16:05 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[CSS3D]]></category> <category><![CDATA[free rotation]]></category><guid isPermaLink="false">http://www.eleqtriq.com/2011/11/traqball-2-0/</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/uploads/2011/11/traqballteaserimg.png" width="102"height="96" alt="traqball 2.0"/>Finally updated traqball.js, my little js lib for gimbal lock free 3d rotation to version 2.0. Impress friends and family with deceleration, easier configuration and multiple trackballs on a webpage.]]></description> <content:encoded><![CDATA[<p> <a href="/wp-content/static/demos/2011/traqball2011?iframe=true&amp;width=840&amp;height=500" rel="prettyPhoto[iframe]" id="traqball" title="traqball 2.0"><img src="http://www.eleqtriq.com/wp-content/uploads/2011/11/traqballHead.png" width="682" height="160" title="traqball"/></a><p>Finally updated traqball.js, <a href="http://www.eleqtriq.com/2010/11/natural-object-rotation-with-css3-3d/" title="first traqball article">my little js lib for gimbal-lock-free 3d rotation</a> to version 2.0. Most important improvements:</p><ul><li>Now its's possible to have multiple instances of trackball on one page.</li><li>Comfortable configuration with a config object.</li><li>Existing CSS transforms in a stylesheet will be preserved.</li><li>It is possible to deactivate, reactivate and update a trackball.</li></ul><p>Download from <a href="https://github.com/dirkweber/traqball.js" title="traqball.js repo on github">github</a> and have fun!</p><p><a class="openexample" href="/wp-content/static/demos/2011/traqball2011?iframe=true&amp;width=840&amp;height=500" rel="prettyPhoto[iframe]" title="traqball 2.0">Open Example</a></p></p> ]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2011/11/traqball-2-0/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Fresh from the Lab: CSS3 Text-Warping</title><link>http://www.eleqtriq.com/2011/03/css3-text-warping/</link> <comments>http://www.eleqtriq.com/2011/03/css3-text-warping/#comments</comments> <pubDate>Fri, 04 Mar 2011 08:47:49 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[Design]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Typography]]></category> <category><![CDATA[Web-Applications]]></category> <category><![CDATA[text to path]]></category> <category><![CDATA[text warping]]></category><guid isPermaLink="false">http://www.eleqtriq.com/2011/03/fresh-from-the-lab-css3-text-warping/</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/uploads/2011/03/textwarp_feature.png" width="218"height="128" alt="HTML text warping"/>My latest experiment: this little web application will make it easy for you to "warp"  HTML-text. Create native text that follows the flow of an arbitrary bezier path or wrap it around a circle like you do in Illustrator.]]></description> <content:encoded><![CDATA[<p><p>I got hooked on desktop-publishing the moment when I attached a text to a path for the first time in Freehand 3. It was magic. Suddenly you could create designs that used to take days or even weeks in less than an hour. If you take a look at late 80s/early 90s design, you will see how the new possibilities shaped the visual language of the time: twirlig, flying letters with zero gravity - from todays perspective its very much like the exaggerated stereo effects in records from the early sixties when music producers tried to show off all their new toys.</p><p><iframe src="http://player.vimeo.com/video/20555184" width="658" height="436" frameborder="0"></iframe></p><p>For some time now I have been breaking my head on how to create warped text in HTML. CSS3 has some handy transformations on board: rotate, skew, matrix, translate. Transform every glyph individually, bring it to the right position and you will get some nifty text following a path. Click on the picture below to see the proof of concept. All typography is pure HTML and CSS3, no Bitmap, flash or SVG in sight (fingers crossed the google font directory isn't down again right now).</p> <a class="floatleft" href="/wp-content/static/demos/2011/warpdtext/1.html?iframe=true&amp;width=480&amp;height=400" rel="prettyPhoto[iframe]" id="Warped" title="Warped Text"><img src="http://www.eleqtriq.com/wp-content/uploads/2011/03/textwarp_article.jpg" width="218" height="220"/></a></p><p>Of course it isn't an option to do all this transformations manually, it would kick us back into the pre-DTP-era in terms of labor intensiveness. Therefore  I took the challenge to build a tool for CSS text warping myself. Through my AS3 experiments I already had enough knowledge of bezier-math to find out the proper angles and positions.  Unfortunately CSS3 doesn't offer us something like :nth-letter, so every letter must be wrapped into a new span for now, which is the <a href="http://www.w3.org/TR/WCAG10-CSS-TECHS/#style-text-formatting" title="W3C Web Content Accessibility Guidelines">recommended practice for in-word letter styling by the W3C</a>. Anyway I'm not absolutely happy with this solution and am currently working on a Javascript to do the warping dynamically. I will post it here when I'm finished.</p><p>The tool allows you to attach any text to an arbitrary bezier path or a circle. Click "Generate HTML" to get a chunk of HTML that you can copy and paste into your existing website then. <a href="http://csswarp.eleqtriq.com/" title="Open CSS3Warp">Try it out here</a>.</p><h3>The technology</h3><p>CSSWarp is mainly HTML5 and Javascript with a slight dose of Flash (for font-detection). The HTML5 canvas is used for drawing the curves and circles. jQuery helps with DOM-manipulation. I added some spice with CSS3-animations for Webkit and Fox>3. The App has been successfully tested in Internet Explorer 9, older versions are not supported of course.</p><h3>Use of fonts</h3><p>Font warping isn't worth anything as long as you can't apply it to a wide array of fonts.  As a consequence CSSWarp gives you access to the <a href="http://www.google.com/webfonts" title="Google Font-Directory">google font-directory</a> and it is possible to use your local fonts (which admittedly can be tricky. See in-app documentation for more info). If you have flash installed, the app will show you a listing of the installed local typefaces. I would love to support web font services like Typekit, but right now I don't see how this should be possible without the support of the service providers. For now you're out of luck if you don't have a copy of your webfont installed locally on your machine. Don't forget to embed your fonts with @font-face declarations before you upload your HTML to the web.</p><p>I still have to test how good CSSWarp supports font replacement technologies. For sIFR I predict inconsistent behavior, because not every browser supports CSS transformations on swfs. I wouldn't recommend using sIFR anyway, as this will result in a Flash-Player instance for every single letter, not the worst method to melt your CPU. Cufon will most probably work, but as Cufon will create a bitmap *before* CSSWarp applys any transformation, expect bad kerning and a more or less blurry look.</p><p>Finally some words about file size. Every transform in the CSS for a warped text must be present in up to 4 flavours: -ms-, -o-, -moz- and-webkit-. One would expect that the CSS containing the sum of all these vendor prefixes would be unacceptably large, but still the stylesheet for the example above is only around 3Kb (gZipped) compared to around 30Kb (depending on loss) for the same graphic as jpeg. Seems we do have a clear winner here, but take into account that all the fonts in the graphic will sum up to some additional 200k. In the end it's a trade off: do you use your fonts only in one graphic or multiple times? Is crawlability and readability of text important for your site? If all these aspects have been taken into consideration, this method can help to enrich the visual experience of a website.</p><h3>What's next?</h3><p>Still a lot of work. First I will clean up code. It has gotten a little bit messy under the hood and I apologize in advance for every event-listener I forgot to unbind. Then I will integrate support for kerning tables. And then there are a lot more nice to haves: local storage, undo/redo relative units and last but not least dynamic text warping with Javascript.</p><p>Please take your time to play around with the app. I would be glad if you send me some feedback to help me improve it and of course bug reports are welcome:</p><p><a class="openexample" href="http://csswarp.eleqtriq.com/" id="CSSWarp" title="CSSWarp">Open Example</a></p></p> ]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2011/03/css3-text-warping/feed/</wfw:commentRss> <slash:comments>20</slash:comments> </item> <item><title>Showcase: Pop-Up Book in HTML and CSS</title><link>http://www.eleqtriq.com/2010/11/showcase-a-pop-up-book-in-html-and-css/</link> <comments>http://www.eleqtriq.com/2010/11/showcase-a-pop-up-book-in-html-and-css/#comments</comments> <pubDate>Thu, 18 Nov 2010 21:44:50 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[Design]]></category> <category><![CDATA[General]]></category> <category><![CDATA[HTML]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Chrome]]></category> <category><![CDATA[CSS 3D]]></category> <category><![CDATA[CSS transforms]]></category> <category><![CDATA[CSS-Animations]]></category> <category><![CDATA[Experiment]]></category> <category><![CDATA[Webkit]]></category><guid isPermaLink="false">http://www.eleqtriq.com/2010/11/showcase-a-pop-up-book-in-html-and-css/</guid> <description><![CDATA[<img class="floatleft" src="/wp-content/uploads/2010/11/popupbook_feature.jpg" width="218"height="128" alt="Pop-up book"/>A little showcase, using all the latest CSS-stuff that makes CSS so much fun to work with these days: animations, transitions, transformations, 3D....]]></description> <content:encoded><![CDATA[<p> <iframe src="http://player.vimeo.com/video/16977165" width="658" height="436" frameborder="0"></iframe><p>This is a little showcase I build yesterday. I had some "leftover" illlustrations from a recent project the client rejected, so I took this as an excuse to cobble together a little demo that uses all the fun CSS stuff: animations, transitions, transforms, 3D...</p><p><a class="openexample" href="/wp-content/static/demos/2010/farm/index.html?iframe=true&amp;width=680&amp;height=600" rel="prettyPhoto[iframe]" id="Pop-Up-Book" title="Pop-Up Book">Open Example</a></p><p>These are cutting edge CSS-tricks. To be able to see it, you will need the latest Webkit- browser (if you are on a Windows-machine I recommend Safari/Win. The latest version of Chromium I tested, 66751, still has big problems with z-sorting and finding the right transform-origin):<ul><li><a href="http://build.chromium.org/f/chromium/snapshots/" title="Download Chromium here">the latest Chromium for Windows</a></li><li><a href="http://www.apple.com/safari/">Safari 5.0.2 for Windows, Mac</a> or iOS</li></ul></p><p><p>Nesting animations was fun (the tractor contains several nested animated block-elements). Z-sorting is still an issue with Webkit CSS3 3D transforms (sometimes you will see hidden elements shine through, though it seems as if the latest Safari-upgrade improved things somewhat - interestingly Safari/Win seems to behave better, Safari iOS behaves best), but in general I'm quite satisfied with the quality and smoothness of the animations. And with <a href="/2010/11/natural-object-rotation-with-css3-3d/">the help of trackball.js</a> you are able to rotate the book freely and enjoy it from all sides.</p></p> ]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2010/11/showcase-a-pop-up-book-in-html-and-css/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Natural Object-Rotation with CSS3 3D</title><link>http://www.eleqtriq.com/2010/11/natural-object-rotation-with-css3-3d/</link> <comments>http://www.eleqtriq.com/2010/11/natural-object-rotation-with-css3-3d/#comments</comments> <pubDate>Tue, 02 Nov 2010 10:17:09 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[HTML]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[CSS transforms]]></category> <category><![CDATA[CSS3 3D]]></category> <category><![CDATA[matrix3d]]></category> <category><![CDATA[move object in 3d space]]></category> <category><![CDATA[object rotation]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=714</guid> <description><![CDATA[<img class="floatleft" src="/wp-content/static/demos/2010/rotation/img/rotationfeature.jpg" width="218"height="112" alt="CSS3 3D Object-Rotation"/><p>I finally found some time to finish the last part in my series on CSS3 3D tutorials. We will learn how to build and style a 3-dimensional packshot with noting more than a few lines of HTML/CSS and then add some Javascript-magic to make it a freely rotatable object. Works even on iPad and iPhone.</p>]]></description> <content:encoded><![CDATA[ <a href="/wp-content/static/demos/2010/rotation/index.html?iframe=true&amp;width=600&amp;height=650" rel="prettyPhoto[iframe]" id="rotation" title="Rotated packshot"><img src="/wp-content/static/demos/2010/rotation/img/rotate_head.jpg" width="682" height="176" title="CSS3 3d Natural Object-Rotation"/></a><p>I finally found some time to finish my short series of tutorials on CSS 3D transforms. If you haven't checked out part <a href="/2010/05/understanding-css-3d-transforms/" title="CSS3 3D-Tutorial Part 1">1</a> & <a href="/2010/05/css-3d-matrix-transformations/" title="CSS3 3D-Tutorial Part 2">2</a> I recommend you to do so, otherwise you will feel lost pretty soon.</p><p>In this tutorial we will learn how to build a 3D packshot in HTML and CSS by applying some CSS 3D-transforms. Then we will add some Javascript to make the object freely rotatable in 3d space. And as we will enhance our Javascript with some touch-interactivity, the packshot will also work nicely in Safari for iOS-platforms like iPhone or iPad. A warning: be prepared that the second part of this tutorial will be quite math-heavy.</p> <a class="openexample" href="/wp-content/static/demos/2010/rotation/index.html?iframe=true&amp;width=600&amp;height=650" rel="prettyPhoto[iframe]" id="rotation" title="Rotated packshot">Open Example</a><p>...or direct your mobile-browser to www.eleqtriq.com/wp-content/static/demos/2010/rotation/ (sorry for the mobile-unfriendly URL).</p><h3>The current State of CSS 3D</h3><p>Since I published my first tutorial a few months ago, more and more sites showed up that actually use CSS3D transforms. But as we all have learned, support for CSS3D-transforms is still marginal outside the iOS world. So what is the use in learning this technique anyway?</p><ul><li><a href="http://www.chromium.org/">Chromium</a> has already integrated experimental support or CSS 3D Transforms on Windows (this is great. Now my Windows-visitors are able to enjoy the demos too! If you are on a windows machine, <a href="http://build.chromium.org/f/chromium/snapshots/" title="Download Chromium here">download a copy of the latest Chromium</a> and come back. Welcome on board, folks :) [<strong>Update:</strong> just found out that <a href="http://www.apple.com/safari/">Safari 5.0.2 for Windows</a> now supports CSS 3D as well. So Windows users do have more options than Mac-users :)] With Chromium and iOS we do not have a large user-base on the desktop, but we will have a real large chunk of the mobile market that will be able to see CSS 3D.</li><li>Apples iAD-Platform will make heavy use of all the advanced Webkit CSS3-tricks. With a current iPhone-market share of 26% of the smartphone market (October 2010) demand for iAD development is expected to continually increase over the next few months. So if you are in the online marketing ad-creation business, CSS3D will be something you should keep in mind.</li></ul><p>Enough said, let's start the tutorial:</p><h3>1. Building the packshot with HTML and CSS:</h3><p>To demonstrate CSS 3D on a real world-example we will create a virtual packshot for <a href="http://www.spritebaker.com/" title="Spritebaker Website">Spritebaker</a>. We start with a basic HTML-"sceleton":</p> <code> <span>&lt;!-- We need something to apply some CSS 3D-perspective to it. Therefore  we set up a section as our stage.  --&gt;</span> <span>&lt;section id="viewport"&gt;</span> <span> &lt;!-- The next container is our box. It consists of 6 sections for every side: --&gt;</span> <span> &lt;article id="box"&gt;</span> <span> &lt;section id="front"&gt;</span> <span> &lt;!-- HTML for the front goes here--&gt;</span> <span> &lt;/section&gt;</span> <span> &lt;section id="top"&gt;</span> <span> &lt;!-- HTML for the top goes here--&gt;</span> <span> &lt;/section&gt;</span> <span> &lt;section id="bottom"&gt;</span> <span> &lt;!-- HTML for the bottom goes here--&gt;</span> <span> &lt;/section&gt;</span> <span> &lt;section id="back"&gt;</span> <span> &lt;!-- HTML for the back goes here--&gt;</span> <span> &lt;/section&gt;</span> <span> &lt;section id="left"&gt;</span> <span> &lt;!-- HTML for the left-side goes here--&gt;</span> <span> &lt;/section;&gt;</span> <span> &lt;section id="right"&gt;</span> <span> &lt;!-- HTML for the inner-side goes here--&gt;</span> <span> &lt;!-- Just kidding :)--&gt;</span> <span> &lt;/section&gt;</span> <span> &lt;/article&gt;</span> <span>&lt;/section&gt;</span> </code><p>In order to style the content we will use a handful of conventional HTML and CSS-techniques, therefore I will not bore you with too much details, you are a gown-up web-developer, right? Some lame 2005 image-replacement and CSS-sprites to make everything fairly accessible and crawlable (as you know I'm a big proponent of Data-URI-Sprites, but I avoid them in my demos most of the time to keep source-code readable).</p><h3>2. Applying the CSS 3D Transforms:</h3><p>More fun to come: let's form a nice 3D-box by rotating and positioning every side. The CSS transforms are straightforward and easy to understand:</p> <code> <span>section#viewport{</span> <span> -webkit-perspective: 700px;</span> <span> -webkit-perspective-origin: 50% 50%;</span> <span>}</span><span>article#box{</span> <span> -webkit-transform-style: preserve-3d;</span> <span>}</span><span>#box section{</span> <span> -webkit-transform-style: flat;</span> <span> /*webkit is a bitch at z-sorting css3d-transforms. Use backface-visibility: hidden as often as you can! */</span> <span> -webkit-backface-visibility: hidden;</span> <span>}</span><span>#front, #back{</span> <span> width:250px;</span> <span> height: 354px;</span> <span> -webkit-transform: translate3d(0px, 0px, 37px);</span> <span>}</span><span>#back{</span> <span> -webkit-transform: rotateY(180deg) translate3d(0px, 0px, 37px);</span> <span>}</span><span>#top, #bottom{</span> <span> width:250px;</span> <span> height: 74px;</span> <span> -webkit-transform: rotateX(90deg) translate3d(0px, 0px, 37px);</span> <span>}</span><span>#bottom{</span> <span> -webkit-transform: rotateX(-90deg) translate3d(0px, 0px, 317px);</span> <span>}</span><span>#left, #right{</span> <span> width: 74px;</span> <span> height: 354px;</span> <span> -webkit-transform: rotateY(-90deg) translate3d(0px, 0px, 37px);</span> <span>}</span><span>#right{</span> <span> -webkit-transform: rotateY(90deg) translate3d(0px, 0px, 213px);</span> <span>}</span> </code><p>We add some spice by adding a webkit-box-reflect below and voila, ready is our box! Attentive readers will see that the reflection is erroneous, with the box-shape accurately reflected but not the typography on the box. This is a bug in webkit for MacOS. Applying a 3D-transform to an element causes that its content can't be reflected properly (strange to say this bug doesn't affect Safari for iOS).</p><h3>3. Making the Box rotatable:</h3> <figure class="w334"><img src="/wp-content/static/demos/2010/rotation/img/trackball_e.jpg" title="Virtual Trackball" alt="The virtual trackball" width="334" height="336" class="floatleft"/><p>Figure 1: the Virtual trackball.</p> </figure><p>It's starting to get interesting: let's add some interactivity with Javascript so we are able to twist and turn the box with the mouse (side-note: we will avoid any Javascript-library like jQuery or Motools and code directly for Webkit instead, as its our sole target-browser. This way the script stays lean and small, <3kb gzipped without comments, mobile browsers will love you for that).</p><h4>Some Words about Object-Rotation in 3D-Space:</h4><p>Rotating and twisting objects in 3D-space might not sound like a big deal: just change the object's angle according to the mouse position on the screen, right? Unfortunately it's not that easy. The movement will feel unnatural and "bumpy" and we will have to deal with the problem of "<a href="http://www.youtube.com/watch?v=zc8b2Jo7mno" title="Go to Video-Explanation of Gimbal Lock">Gimbal-Lock"</a>.</p><p>There exists a better technique for achieving a natural and smooth experience for the user. It's called the "Virtual Trackball". The Virtual Trackball is an imaginary sphere around our 3D-object. Every mouse-click on the screen will be mapped onto this virtual sphere and every dragging-operation will cause a rotation of the virtual trackball and the object inside, resulting in a smooth and intuitive rotation. Let's see how to build a virtual trackball for our box:</p><h3>Mathematics of the Virtual Trackball:</h3><h4>How to construct the virtual trackball:</h4> <figure class="w334"><img src="/wp-content/static/demos/2010/rotation/img/mousecoordinates_e.jpg" title="Virtual Trackball: map mouse-coordinates" alt="The virtual trackball" width="334" height="336" class="floatleft"/><p>Figure 2: Mapping the coordinates of the mouse to the Virtual Trackball.</p> </figure><p>The center of the box and the Sphere must be at the center of the coordinate-system (y=0, y=0, z=0), which is also the center of the stage. The sole purpose of the virtual trackball is calculating angles in 3d-space. We are not interested in distances, it is enough to know their relation. Therefore we will put the sphere into an easy to calculate coordinate-system where its radius is simply "1". Mouse-coordinates on screen can be translated to this new coordinate system easily by dividing all values by the "untranslated" radius. Choosing the right radius is a matter of instinct. Choose a value that "feels right". I decided to make it half of the shortest side of the viewport. This maybe not o. k. in every situation though, you will always have to test and make your decision accordingly.</p><h4>2. On mouse down, detect the mouse-coordinates and map them onto the trackball:</h4> <figure class="w334"><img src="/wp-content/static/demos/2010/rotation/img/rotationaxis_e.jpg" alt="Determining the rotation axis on the virtual trackball" width="334" height="336" class="floatleft"/><p>Figure 3: determining the rotation-axis from the vector at the moment of mousedown and the vector during rotation.</p> </figure><p>we translate screen-coordinates to trackball coordinates:</p><p>sphereX*2=mouseX/radius<br/> sphereY*2=mouseY/radius</p><p>..and then move [0,0] to the center of the trackball coordinate-system:</p><p>x = x - 1;<br/> y = y - 1;</p><p>We already know the radius of our sphere (it's 1, remember?) so it's quite easy to determine the z-coordinate of the translated point with the help of some good old trigonometry:</p><p>2*Z<sup>2</sup>=1-x<sup>2</sup>-y<sup>2</sup></p><p>Now that  we have everything in place, we can start building the rest of the logic. I will give an overview in pseudocode. One more remark: the script makes heavy use of 3d transformation-matrices and rotate3D, but avoids "rotateX, Y, Z". If we would use single-axis-rotations it would be necessary to calculate the rotation in <a href="http://www.genesis3d.com/~kdtop/Quaternions-UsingToRepresentRotation.htm" title="Learn about Quaternions.">quaternion-space</a> to avoid <a href="http://www.youtube.com/watch?v=zc8b2Jo7mno" title="Go to Video-Explanation of Gimbal Lock">gimbal-lock</a>. If we use rotate3D or matrix3d, webkit will handle the quaternion stuff for us.</p><p>At first-run or at the moment the user releases the mouse (or lifts his hand) we create a new matrix3D from the last axis-vector and angle, store it in a variable and apply it to our box. When the user decides to click and rotate again, we will apply this startmatrix together with rotate3D to our box. This way we prevent our box from flipping back to it's initial, "unrotated" state on every mousedown/touchstart-event.</p> <code> <span>function init(){</span> <span> set up the virtual trackball;</span> <span> search the viewport-html-element for something to rotate;</span> <span> add mousedown- or touchstart-listener to prepare rotation;</span> <span> add mouseup- or touchend-listener to finish rotation;</span> <span> add mousemove- or touchmove-listener to rotate;</span> <span> calculate initial matrix3d from initial angle and rotation axis;</span> <span> }</span> <span></span> <span>function startrotation(){</span> <span> track click-position and translate it to trackball;</span> <span> store resulting 3d-vector in variable "mouseDownVect";</span> <span> }</span><span>function rotate(){</span> <span> track current mouse-position and translate it to trackball;</span> <span> store resulting 3d-vector in variable "mouseMoveVect";</span> <span> </span> <span> find rotation-axis by determining normal on mouseDownVect and mouseMoveVect;</span> <span> </span> <span> find rotation-angle between mouseMoveVect and mouseDownVect;</span> <span> apply startmatrix and rotate3d(axis, rotation-angle) to the box;</span> <span> }</span><span>function finishrotation(){</span> <span> calculate new matrix3d from last angle and rotation axis;</span> <span> combine the last start-matrix and this new matrx to a combined matrix by multiplication;</span> <span> make current matrix3d new start-matrix;</span> <span>}</span> </code><p>This is an overview of the actual logic. If you want to dig deeper, you should check out the <a href="https://github.com/dirkweber/traqball.js" title="Open Javascript">Javascript</a>, I gave my best to comment every step.</p><p>The script (I call it "traqball.js" by the way) is released under MIT- and GPL-license and you are alllowed to use it in your projects as long as you stick to the terms of license. Implementation is easy:</p><ul><li>Create some HTML-element (div, scection, article etc.) as viewport</li><li>Apply some -webkit-perspective to it (values around 600 are o.k.)</li><li>Pass the id of viewport over to the "init"-function along with an initial rotation-axis in vector-form ([a, b,c]) and an initial rotation-angle (in radians) and...</li><li>...place your rotation-"target" block-element inside the viewport. It must be the first block-child, then the script will find it.</li></ul><p>Ok, we're through! Hope you enjoyed this little lesson. If you have used the script in your projects I would be more than glad if you send me a link.</p><p><strong>Update</strong> updated traqball.js to version2.0. Source now is on <a href="https://github.com/dirkweber/traqball.js" title="traqball 2.0">Github</a>. <a href="http://www.eleqtriq.com/2011/11/traqball-2-0/" title="traqball 2.0">Read more here.</a>.</p>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2010/11/natural-object-rotation-with-css3-3d/feed/</wfw:commentRss> <slash:comments>41</slash:comments> </item> <item><title>Sqetch, an Illustrator Wireframe Toolkit</title><link>http://www.eleqtriq.com/2010/08/sqetch-wireframe-toolkit/</link> <comments>http://www.eleqtriq.com/2010/08/sqetch-wireframe-toolkit/#comments</comments> <pubDate>Tue, 24 Aug 2010 16:18:14 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[Design]]></category> <category><![CDATA[General]]></category> <category><![CDATA[UX]]></category> <category><![CDATA[Free Wireframe Stencil]]></category> <category><![CDATA[Illustrator-Templates]]></category> <category><![CDATA[interface design]]></category> <category><![CDATA[Usability UX]]></category> <category><![CDATA[Wireframing]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=629</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/uploads/2010/08/sqetch-teaser-image.jpg" width="218"height="160" alt="Thumb" title="Sqetch Wireframe Toolit"/><p>Sqetch is a little "sketchy", looking collection of Illustrator-wireframing-templates I created over the last several months. It consists of several templates for browser, iPad, smartphone and a collection of UI-elements.</p><p>It brings back some "artistry" to the wireframing-process which makes it ideal for early-stage wireframes.</p>]]></description> <content:encoded><![CDATA[<img src="http://www.eleqtriq.com/wp-content/uploads/2010/08/header-Image.jpg" width="682" height="304" title="Spritebaker" alt="Sqetch Wireframe Toolkit"/><p>Sqetch is a little Illustrator-toolkit I built over time, consisting of several templates and elements:<p><ul><a href="http://www.eleqtriq.com/wp-content/uploads/2010/08/browser.jpg?iframe=true&amp;width=712&amp;height=614" title="Webbrowser" rel="prettyPhoto[iframe]"><li>Browser</li><li><a href="http://www.eleqtriq.com/wp-content/uploads/2010/08/ipadup.jpg?iframe=true&amp;width=584&amp;height=614" title="iPad upright" rel="prettyPhoto[iframe]">iPad upright</a></li><li><a href="http://www.eleqtriq.com/wp-content/uploads/2010/08/iPadlandscape.jpg?iframe=true&amp;width=712&amp;height=590" title="iPad landscape" rel="prettyPhoto[iframe]">iPad landscape</a></li><li><a href="http://www.eleqtriq.com/wp-content/uploads/2010/08/smartphone.jpg?iframe=true&amp;width=466&amp;height=535" title="Smartphone" rel="prettyPhoto[iframe]">Smartphone</a></li><li><a href="http://www.eleqtriq.com/wp-content/uploads/2010/08/tiles1.jpg?iframe=true&amp;width=712&amp;height=747" title="GUI Elements" rel="prettyPhoto[iframe]">GUI-Elements</a></li><li><a href="http://www.eleqtriq.com/wp-content/uploads/2010/08/tiles2.jpg?iframe=true&amp;width=712&amp;height=747" title="Form Elements" rel="prettyPhoto[iframe]">Form-Elements</a></li></ul><p>It evolved one by one as an answer to several problems I encountered related to wireframing:</p><p>Like many designers I frequently experienced that clients did not understand my wireframes. More than once they were not able to distinguish between a layout and a wireframe. Suddenly I found myself debating about colors and font-sizes, when it would have been appropriate to talk about processes and information-architecture instead.</p><p>Presenting wireframes can be arduous. Sometimes you must go through countless screens with slight variations of one single situation. This requires a lot of discipline by the designer as well as the client.</p><p>Even experienced clients often react disappointed or bored to wireframes. Clients want us designers to "wow" them. Wireframes do a bad job at wowing anybody. Using Omnigraffle or keynote doesn't help either. Some clients do not understand the labour that is involved and think we are overpaid. I remember a client who actually told me he would prefer to do the wireframing himself, as he saw no reason to "pay a designer for pushing some boxes around in word".</p><p>As a consequence I began to create high-quality versions of my hand-drawn wireframes and use them in client-presentations. The hand-crafted, artistic component helped circumvent many of the problems described above. Unfortunately it came for a price: labour-intensiveness. Drawing a lot of variants of one screen is much more time-consuming than making changes in a digital document.</p><p>Therefore I began transferring my drawings to illustrator. And after some time a little wireframe-toolkit had evolved, which you can download here. For maximum flexibility everything was created with vectors, no bitmap in sight. Every element can be scaled without loss of quality, every single stroke can be edited separately, to adapt the look of a sketch as ever you like. Colors are in CMYK for easy printing. And if you are a CS5 user you will be pleased to find out that all symbols are attached to a 9-slice scaling grid.</p><p>The font in use is <a href="http://www.nymfont.com/2009/04/nymphs-handwriting.html" title="Nymph's Handwriting">Nymph's Handwriting</a>, a beautiful font from talented Lauren Thompson, which you can download <a href="http://www.nymfont.com/2009/04/nymphs-handwriting.html" title="Download Nymph's Handwriting">from her blog</a>. And as you are already there you should take a look at her other fonts, it's worth it.</p><p><a href="http://downloads.eleqtriq.net/sqetch/sqetch_CS4.zip" title="Download Toolkit">Download of sqetch</a> is free and you are allowed to use the toolkit in commercial projects. Anyway, should you use it on a website or in a printed publication I expect you to give me credit and link to www.eleqtriq.com (respectively mention the internet-address in printed publications). If this shouldn't be possible for some reason, contact me and we work something out. Happy wireframing!</p><p>Update! Thanks to <a href="http://wireframes.linowski.ca">Jakub</a> and Smashingmag for linking. Anyway, as traffic increased over the last few hours I decided to test a mirror server. If you experience problems, please send me a note in the comments.</p> <a class="downloadexample" href="http://downloads.eleqtriq.net/sqetch/sqetch_CS4.zip" title="Download Toolkit">Download Toolkit</a>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2010/08/sqetch-wireframe-toolkit/feed/</wfw:commentRss> <slash:comments>80</slash:comments> </item> <item><title>Introducing Spritebaker</title><link>http://www.eleqtriq.com/2010/07/introducing-spritebaker/</link> <comments>http://www.eleqtriq.com/2010/07/introducing-spritebaker/#comments</comments> <pubDate>Wed, 21 Jul 2010 10:27:57 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[Actionscript]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[HTML]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Web-Applications]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=607</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/uploads/2010/07/spritebaker_mini.png" width="102" height="80" alt="Thumb" title="spritebaker"/>For some time now I had planned to build an online app that makes creating data URI-sprites in CSS less painful. As a special feature I wanted it to be pure HTML/Javascript...]]></description> <content:encoded><![CDATA[ <a href="http://www.spritebaker.com/" title="Visit spritebaker.com"><img src="http://www.eleqtriq.com/wp-content/uploads/2010/07/spritebaker.png" width="682" height="160" title="Spritebaker" alt="Spritebaker Logo"/></a><p>Over time Data URI Sprites have more and more become an indispensable tool for my work. For the rookies: <a href="http://www.nczonline.net/blog/2010/07/06/data-uris-make-css-sprites-obsolete/" title="Nicholas C. Zakas Blog">data URI-sprites</a> is the name of the method to encode all kind of binary resources to <a href="http://en.wikipedia.org/wiki/Base64" title="Base64 at Wikipedia.de">base64</a> and embed the resulting text-files into a HTML-document or a stylesheet. Unfortunately the process is somehow unelegant: first you must encode your binary-file <a href="http://www.motobit.com/util/base64-decoder-encoder.asp" title="online base64 encoder">with</a> <a href="http://www.javazoom.net/services/base64/base64.jsp" title="online base64 encoder">some</a> <a href="http://www.opinionatedgeek.com/dotnet/tools/base64encode/" title="online base64 encoder">adequate</a> <a href="http://base64-encoder-online.waraxe.us/" title="online base64 encoder">tool</a>, then you will need to paste the resulting string into your css. As a base 64 encoded dataset can be some 100 lines of text easily, this process is quite error prone. Additionally most of this tools add linebreaks into the encoded text, but most browsers can't interpret data URI-Sprites with linebreaks which means you have to remove alle the linebreaks after encoding (and there can be a lot of them).</p><p>To make life easier for me I cobbled together a Flash-tool that does this job: feed a CSS-file to it and it will scan it for fonts, images and svg, encode them and return a new CSS-file.</p><p>All in all this works quite o.k. for me, as long as I stick to some rules: all URLs in quotes, no empty url() in attribute etc. But as the tool doesn't tolerate any errors and expects everything to be in place from the beginning, it would most propably drive a lot of other designers insane.</p><p>For some time now I had planned to convert the tool into an online-app. At first my intention was to refactor the actionscript and offer it as a downloadable Air-application. But then I got adventureous: would it be possible to get this done with pure HTML and Javascript? Javascript is not the best tool for processing binary-data, but an ajax-request together with overrideMimeType('text/plain; charset=x-user-defined') made it possible in the end,</p><p>You will find the fruits of my labour on <a href="http://www.spritebaker.com" title="visit spritebaker.com">www.spritebaker.com</a>. You will also get some more Info about data-URIs and Gzip-compression. I hope the app is helpful for some of you. The whole thing was created on the google app-engine (which is a great tool, btw.).<a href="http://www.spritebaker.com" title="visit spritebaker.com"> Have Fun!</a></p>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2010/07/introducing-spritebaker/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>The Matrix Revolutions (CSS 3D &#8211; 2)</title><link>http://www.eleqtriq.com/2010/05/css-3d-matrix-transformations/</link> <comments>http://www.eleqtriq.com/2010/05/css-3d-matrix-transformations/#comments</comments> <pubDate>Tue, 18 May 2010 17:06:32 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[Advanced]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[CSS 3Dimensional Transformations]]></category> <category><![CDATA[iPad-Development]]></category> <category><![CDATA[Mobile Web]]></category> <category><![CDATA[Web 3D]]></category> <category><![CDATA[Webstandards]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=522</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/teaser_2.jpg" width="218" height="80" alt="Thumb" title="CSS 3D Transforms"/>The second part in this mini-series on css 3d covers matrix-transformations. What is this mysterious thing and how can we use it?]]></description> <content:encoded><![CDATA[ <img src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/gallery.jpg" width="682" height="224" title="CSS 3D Gallery" alt="CSS 3D Gallery"/><p>This is the second part of a mini-series covering css 3d-transformations. <a href="/2010/05/understanding-css-3d-transforms/" title="CSS 3D-Transformationen, Teil 1">If you missed the first part, you can read it here</a>.</p><p>Suddenly they were here: with the increasing adoption of CSS3 in modern web-browsers a strange instument showed up in our toolbox, but nobody knew exactly how to use it: transformation-matrices. How could this mathematical object, obviously invented by some crazy geek with a bias for 90ies science-fiction movies happen to get lost in a CSS-proposal?</p> <a class="openexample" href="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/matrix2dExplorer.html?iframe=true&amp;width=720&amp;height=580" rel="prettyPhoto[iframe]" id="matrixexplorer" title="Explore CSS Transformations">Open Example</a><p>The good news first: even though "transformation-matrix" may be difficult to spell, it's less difficult to grasp the concept. Even better: If you don't want to, you don't <strong>need</strong> to understand it and still can use it anyway. But if you take your time to get the principle behind it you will have a really powerful method at your fingertips to manipulate DOM elements. Flash developers do have an advantage again, as they are already familiar with transformation matrices since flash 8.</p><p>Unfortunately there is not too much documentation on the web regarding transformation-matrices for mathematical illiterate folks like us designers. Therefore this little tutorial. Hopefully it is useful for some of you.</p><h3>What are Matrices?</h3><p>Matrices are like the warp engine in star-trek: space-time-continuum is changed from the outside, but the people in the star-craft don't notice anything.</p><p>Matrices are used for vector calculations (if you don't have any clue what this is, consult a <a href="http://emweb.unl.edu/math/mathweb/vectors/vectors.html" title="vector tutorial">math tutorial near you</a>. At least you should be aware that the green arrows in the graphics on this page are vectors). Programmers do know that vectors and matrices are an important part of game programming. Why? Well, it is possible to alter an object with matrices and still keep its "inner" properties. Think of an airplane: we turn the airplane to the left. Now we want it to fly into the direction of its head, so we command "fly left". We have to do this every time the direction is altered: turn the plane first, then store the new direction and adjust the movement. This can quickly become a complicated task, i. e. if the airplane has to fly a complex path. Here matrices can be really helpful. It is enough to put the airplane into a matrix. From then on we simply tell the airplane to fly straight ahead and apply all the positioning, turning and twisting to the matrix.</p><p>Matrices do have some more advantages:</p><ul><li>Its possible to accomplish a lot of manipulations (turning, scaling, shearing, moving) at the same time. And as we have to add vendor specific prefixes for every transformation, it doesn't harm that we can "compress" them into one matrix. This will help keeping our code lean and saving CPU at the same time.</li><li>It is quite easy to combine matrices by using low level math operations: addition, subtraction, multiplication.</li></ul><h3>How does it look?</h3><p>A matrix is a sequence of numbers that usually will be stored within an array: i. e. [0.5, 4, 2.3, 1.5] is a simple cubic two-dimensional matrix. As this kind of syntax is difficult to read, it is common to list them line by line:</p><table class="matrix"><tr><td>0.5</td><td>4</td></tr><tr><td>2.3</td><td>1.5</td></tr></table><h4>What's the meaning behind these numbers?</h4><p>Let's think of a square on a piece of paper. Every point within the square has an x- and an y-coordinate. The first row in our Matrix represents the x-vector, the second one the y-vector. Each vector determines how this point will be transformed along the corresponding axis.</p> <img src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/matrixdia_1_e.jpg" width="682" height="224" title="Matrix-Distortions" alt="Showing some matrix-distortions"/><p>The matrix of an undistorted  square must scale it along the x axis by the factor of 1 and along the y-axis by the factor of 1. This is called the "identity-matrix":</p><table class="matrix"><tr><td>1</td><td>0</td></tr><tr><td>0</td><td>1</td></tr></table><p>This matrix will narrow the square into half:</p><table class="matrix"><tr><td>0.5</td><td>0</td></tr><tr><td>0</td><td>1</td></tr></table><p>Now let's shear the square along the x-axis, similar to the "skew"-tool in Illustrator. We have to alter the y-value of the X-vector as well:</p><table class="matrix"><tr><td>1</td><td>0</td></tr><tr><td>0.5</td><td>1</td></tr></table><p>You can rotate objects with the matrix as well. In this case it is important to maintain a certain relation of every value in the matrix. Having an idea of <a href="http://en.wikipedia.org/wiki/Trigonometry" title="Trigonometrie bei Wikipedia">trigonometry</a> is beneficial:</p><table class="matrix"><tr><td>cos(&alpha;)</td><td>sin(&alpha;)</td></tr><tr><td>-sin(&alpha;)</td><td>cos(&alpha;)</td></tr></table><p>"&alpha;” is the rotation-angle (important: in <a href="http://en.wikipedia.org/wiki/Radian" title= "wikipedia radians article">radian</a>, not degree). Consult <a href="http://www.intmath.com/Trigonometric-functions/Trig-functions-intro.php" title="Trigonometry Online Course">Wikipedia</a> for the derivation.</p><p>Everything we have demonstrated until now for two dimensional matrices can be applied to three-dimensional space as well. In this case we need one more line for the z-axis and one more column for the z-values of the three vectors in our matrix.</p><p>We already learned that the vectors for the undistorted identity-matrix must have a value of "1" along their corresponding axes. Accordingly the identity-matrix for a 3d-transformation will look like this:</p><table class="matrix"><tr><td>1</td><td>0</td><td>0</td><td>0</td></tr><tr><td>0</td><td>1</td><td>0</td><td>0</td></tr><tr><td>0</td><td>0</td><td>1</td><td>0</td></tr><tr><td>0</td><td>0</td><td>0</td><td>1</td></tr></table><p>I prepared a little demo to play with the values (please use a browser that is capable of displaying 3d CSS transforms):</p> <a class="openexample" href="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/matrix3dexplorer.html?iframe=true&amp;width=720&amp;height=640" rel="prettyPhoto[iframe]" id="matrix3dexplorer" title="Explore CSS 3dtransformations">Open Example</a><h4>Wait — this is a 4 x 4 matrix. Wouldn't be a 3 x 3 matrix enough?</h4> <img src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/matrixdia_2_e.jpg" width="334" height="239" title="Z-shearing with 3d matrix" alt="Z-shearing with 3d matrix" class="floatleft"/><p>Until now we used simplified matrices. But usually a matrix will contain some more information besides the vector-coordinates:</p><table class="matrix"><tr><td>x</td><td>x</td><td>x</td><td> Wx</td></tr><tr><td>y</td><td>y</td><td>y</td><td>Wy</td></tr><tr><td>z</td><td>z</td><td>z</td><td>Wz</td></tr><tr><td>Tx</td><td>Ty</td><td>Tz</td><td>W</td></tr></table><p>The T-row will re-position the center of the transformation in pixels, allowing us to move the object.</p><p>The W-row is tricky. A perspective-projection is determined here. It is our viewpoint along the corresponding axis. Usually you will want this values to be zero except the last one. Play around with this values in the demo. If you're feeling adventurous, google for <a href="http://www.google.com/search?rls=en&amp;q=homogeneous+coordinates" title="homogenous Coordinates at google">"homogenous coordinates"</a> ;-).</p><h3>Example: Coverflow in CSS</h3><a class="openexample" href="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/matrix3dgallery.html?iframe=true&amp;width=850&amp;height=626" rel="prettyPhoto[iframe]" id="matrix3dgallery" title="Cover-Flow Gallery Animated with CSS Transformations">Open Example</a><p>Let's test our knowledge with a little example: a picture-gallery in cover-flow style. I will not go into details but post the essential CSS here instead. Everything will work without javascript and additional graphical elements (except the images of course). This special result could be achieved with "rotate-y" as well but, hey, it's a demo, right? Use a CSS 3d capable browser for viewing. Everyone who doesn't have a Webkit nightly on mac, iDevice OS >2 or Safari Leopard can at least watch a video instead:</p><code> <span>div#stage{</span> <span> -webkit-perspective: 600px;</span> <span>}</span> <span></span> <span>img {</span> <span> -webkit-transition-property: -webkit-transform;</span> <span> -webkit-transition-duration: 0.7s;</span> <span> -webkit-transform: matrix3d(0.7109, 0, -0.703279, 0, </span> <span> 0, 1, 0, 0, </span> <span> 0.703279, 0, 0.7109, 0,</span> <span> 0, 0, 0, 1);</span> <span> -webkit-box-reflect:below 15px</span> <span> -webkit-gradient(linear, left top, left bottom, from(transparent),</span> <span> color-stop(0.7, transparent), to(#ff0000));</span> <span>}</span> <span></span> <span>img:hover {</span> <span> -webkit-transition-property: -webkit-transform;</span> <span> -webkit-transition-duration: 0.7s;</span> <span> -webkit-transform: matrix3d(1, 0, 0, 0, </span> <span> 0, 1, 0, 0, </span> <span> 0, 0, 1, 0, </span> <span> 0, 0, 200, 1);</span> <span>}</span> </code><p>That's it. Where we usually would have needed some 50 lines of javascript-code, a few CSS-properties are enough right now. Isn't technical evolution a wonderful thing?</p>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2010/05/css-3d-matrix-transformations/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Understanding CSS 3D Transforms (CSS 3D &#8211; 1)</title><link>http://www.eleqtriq.com/2010/05/understanding-css-3d-transforms/</link> <comments>http://www.eleqtriq.com/2010/05/understanding-css-3d-transforms/#comments</comments> <pubDate>Tue, 04 May 2010 13:42:03 +0000</pubDate> <dc:creator>Dirk</dc:creator> <category><![CDATA[CSS3]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[3D]]></category> <category><![CDATA[Butterfly Animation]]></category> <category><![CDATA[CSS 3D Transfromations]]></category> <category><![CDATA[Demo]]></category> <category><![CDATA[Web Development]]></category><guid isPermaLink="false">http://www.eleqtriq.com/?p=460</guid> <description><![CDATA[<img class="floatleft" src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/teaser.jpg" width="218" height="80" alt="Thumb" title="CSS 3D Transforms"/>I had a lot of fun last week playing with the new CSS 3D Transforms. This short mini-series is intended to help developers get ready for the next generation of Webkit-browsers.]]></description> <content:encoded><![CDATA[ <img src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/chocolatebar.jpg" width="682" height="224" title="CSS 3D Transform Eye-Candy" alt="CSS Chocolate-Bar"/><p>Bevel, Dropshadow, Gloss and Glow are designers chocolate-bar - everybody knows they should be avoided, but sometimes we can't resist. The biggest calorie-bomb is everything 3-D. Ahhh 3D - think of all the things it could make possible for us: palettes appearing out of the deep like spaceships, unfolding their menus like roboter-arms, then gliding majestically into the orbit...</p><p>Considered a curiosity for nerds by the most, right now <a href="http://www.w3.org/TR/css3-3d-transforms/" title="CSS 3D Transforms Module Level 3 beim W3C">a working draft for 3-dimensional transformation of css-elemets</a> is proposed to the W3C and this draft is promising: open the example below to see what can be achieved with 4 divs (no further javascript necessary):</p> <a class="openexample" href="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/butterfly.html?iframe=true&amp;width=850&amp;height=626" rel="prettyPhoto[iframe]" id="butterfly" title="Butterfly, animated with CSS 3D-transformations">Beispiel öffnen</a><p>Anyway, before you launch your editor to build the ultimate startrekmatrixminorityreport-navigation you alway dreamt of since you pinned this millenium-falcon poster onto your wall at the age of 14: of course there's a catch. As it's only a draft right now, browser-support is still homeopathic. To be concrete: Safari on iPad, iPod-Touch and Leopard. But this could change soon: expect most webkit-based browsers to catch up one by one over the next time. Especially developers for mobile platforms will benefit from more options in their arsenal, so they should listen carefully. I'll try to give a short overview of the current state of CSS 3D-Transformations in this mini-series. This first part is mainly about the basic CSS 3D-properties. In the second part I will talk about transformation matrixes. And in the last part we will learn about higher mathematics (Quaternions anybody?) and natural object rotation.</p><h3>My DIVs in 3D???</h3><p>The purpose of CSS 3D transformations is to allow the designer the manipulation of DOM-Objects not only in the plane (x, y, top, left, right, bottom), but in 3-D space (z) as well. You may think of this as some gimmick without substance but, used properly, it can add value. CSS-3D Transformations can, especially when used in conjunction with CSS-Transitions, help to structure Interfaces into different sections and make the transition between this sections more comprehensible.</p><p>What's more: I prefer having a lot of tools in my box. If a utility helps to enrich a user-experience it is welcome. In particular I'm thankful for every instrument that supports me in budgeting the precious commodity screen-estate on mobile devices.</p><h3>The Situation</h3><p>To be able to see the examples you will need a browser that is able to understand CSS 3D-transformations. Currently this are:</p><ul><li>Safari on MacOSX 10.6</li><li><a href="http://nightly.webkit.org/" title="Download Webkit nightly here">Webkit Nightly Build on MacOSX &lt;10.6</a></li><li>Safari Mobile on iPad, iPod-Touch & iPhone</li></ul><p>Unfortunately the current <a href="http://nightly.webkit.org/" title="Download Webkit nightly here">Nightly build of Webkit for Windows</a> doesn't support CSS3D-Transformations. I can only recommend  to check from time to time wether the functionality has changed.<p><p>As you can see, currently CSS 3D Transformations are of particular interest to developers who do HTML-apps for the iDevice-Platform.<p><h3>Which Browsers will Support The Standard?</h3><p>It's most likely other webkit-based browsers will be the first to catch up. Besides Apples Safari, Webkit is also the foundation for Google's Chrome. Webkit may be not very dominant on the desktop, but on smartphones it is the prevalent rendering-engine, although the difference between implementations can be substancial.</p><h3>Step by Step Walkthrough:</h3><p>Designers with a background in 3-D Animations should not have too high expectations: the standard doesn't know anything about light sources, cameras, or shaders. 3D-Navigation is very limited, as viewpoint-rotation is not possible. On the other hand: even designers who already have been involved into 3-D may find some of the concepts quite abstract and unintuitive (what are transformation-matrixes?) and the interaction of the 3D-Element and other elements on the page is not always feasible (how will floats behave? What are margins?).</p><p>Before we carry on, I recommend to play with this demo. You can manipulate the CSS-properties independently and watch the result in real-time. Hopefully this will give you a better understanding of the abstract subject.</p><a class="openexample" href="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/css3dexplorer.html?iframe=true&amp;width=720&amp;height=640" rel="prettyPhoto[iframe]" id="tridiexplorer" title="Explore 3D CSS transformations">Open Example</a><p>A side note: we can learn something about the disappointing SVG-implementation in Safari in this example: all background-images are svg, so you should expect them to be razorsharp all the time. Unfortunately this isn't the case, as Safari only uses a cached bitmap for distortion.</p><p>So let's start with our html-document:</p> <code> <span>&lt;div id="container"&gt;</span> <span> &lt;div id="child"&gt;</span> <span> &lt;/div&gt;</span> <span>&lt;/div&gt;</span> </code><p>The next thing we want to do is to rotate, scale and reposition div#child. Before we can do this, we have to tell div#parent that its children now live in 3-D space (notice the vendor-specific prefix "-webkit-" prepended to all CSS-properties:</p> <code> <span>div#container{</span> <span> -webkit-perspective: 250px;</span> <span> -webkit-perspective-origin: 50% 80%;</span> <span>}</span> </code> <img src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/perspective_e.jpg" class="floatleft" title="How the perspective-property works" alt="How the perspective-property works"/><p>Both declarations set the stage. None of them will cause any changes to the appearance of "parent". The only thing we do here is determine how children of "container" will be rendered.</p><p>The concept behind perspective is not very intuitive. Imagine a pyramid between the viewer and the z-plane. "perspective" would be the distance between the top of the pyramid and the z-plane. "Perspective" can be compared to the field viewing angle of your camera. The higher "perspective", the steeper the pyramid, so the transformed objects size will be nearer to it's untransformed size. A rule of thumb: values from 700 to 1000 will be recognized as "normal" and are a good starting-point.</p><p>"perspective-origin" determines the coordinates for the perspective-centers x- and y- values. It is like positioning a camera: "perspective" is the field-viewing-angle, "perspective-origin the x- and y-coordinates of the camera. Here we do use a percent-value, but absolute (px, cm, in, em etc..) or other relative (left, top, right, bottom, center) units would be allowed as well.</p><p>After setting the stage, we will now transform the child-element:</p><ul><li>We want the origin of the transformation to be positioned at the center.</li><li>We want the Element to be moved 50px along the x-, 40px along the y- and 80px along the z-axis.</li><li>Afterward we will double its width and rotate it 45 degrees around its y-axis</li><li>We want the children of the Element to live in the same 3D coordinate-space.</li></ul> <code> <span>div#child{</span> <span>-webkit-transform-origin: 50% 50% 50%;</span> <span>-webkit-transform: perspective(0)</span> <span> translate3d(50px, 40px, 80px)</span> <span> scale3d(1, 2, 0)</span> <span> rotate3d(0, 1, 0, 45deg);</span> <span>-webkit-transform-style: preserve-3d;</span> <span>}</span> </code><h4>transform-origin:</h4><p>This is the center for the transformation. Units allowed are the same as for "perspective". Values for "z" are allowed, but didn't have any effect in my experiments.</p><h4>transform: ...</h4><p>Here we will group all transformations:</p><ul><li>perspective(val)</li><li>translate3d(x, y, z)</li><li>scale3d(x, y, z)</li><li>rotate3d(x, y, z, winkel)</li></ul><h4>transform: perspective(val)</h4><p>A kind of short-version of "perspective:val". This time it is not applied to the container but directly to the child. In contradiction to "pespective" it will alter the appearance of the object, not its children. If the container does have a "perspective" declaration, both values will multiply.</p><h4>transform: translate3d(x, y, z):</h4><p>Moves the object along the corresponding axis.</p><h4>transform: scale3d(x, y, z)</h4><p>Will scale the object along the corresponding axis. A value of 1 will preserve the original value. A need for scaling along the z-axis seems unnecessary first, as DOM-Elements usually do not have any depth. Anyway situations are possible where a z-scaling can be reasonable, for example if you arrange a group of divs in cube-form. This group could indeed be scaled z-wise.</p><img src="http://www.eleqtriq.com/wp-content/static/demos/2010/css3d/img/rotation3d_e.jpg" class="floatleft" title="Vector-rotation with rotate3d" alt="Vector-rotation with rotate3d"/><h4>transform: rotate3d(x-vektor, y-vektor, z-vektor, angle)</h4><p>A rotation around a vector-axis. First we will determine a vector by setting its x, y, and z values. Its important to know that not the values themselves are important, but the <strong>relation</strong> of the values: rotate3d(5, 6, 10, 45deg) will give the same effect as rotate3d(50, 60, 100, 45 deg). The 4th value determines the angle of the rotation. Degrees(deg) and radian(rad) are allowed as units for the angle. I. e. rotate3d(0, 1, 0, 90deg) will rotate he object 90 degrees around the y-axis.</p><h4  class="clearfixblock">-webkit-transform-style:</h4><p>One more CSS-property that will have only an effect on its children. The 2 possible values are "preserve-3d" and "flat" with "preserve-3d" being default.</p><ul><li>"preserve-3d" will treat child elements as 3-D objects living in the same coordinate-space.</li><li>"flat" will treat child-elements as texture that are mapped flat onto their parent.</li></ul><p>There are some more transformations I didn't mention because I think they are fairly self-explaining:</p><ul><li>translateX(x)</li><li>translateY(y)</li><li>translateZ(z)</li><li>rotateX(angle)</li><li>rotateY(angle)</li><li>rotateZ(angle)</li><li>backface-visibility: visible | hidden</li></ul><p>So there's only transformation-matrix matrix3d(…)  left, which I will discuss in <a href="http://www.eleqtriq.com/2010/05/css-3d-matrix-transformations/" title="part 2">part 2 of this series.</a></p>]]></content:encoded> <wfw:commentRss>http://www.eleqtriq.com/2010/05/understanding-css-3d-transforms/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 2/9 queries in 0.008 seconds using disk
Object Caching 810/815 objects using disk
Content Delivery Network via N/A

Served from: www.eleqtriq.com @ 2013-05-24 16:37:22 -->