<?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>The Simple Part</title>
	<atom:link href="https://karlagius.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://karlagius.com</link>
	<description>It&#039;s not rocket science</description>
	<lastBuildDate>Thu, 04 Nov 2021 17:24:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
<site xmlns="com-wordpress:feed-additions:1">6452373</site>	<item>
		<title>How to make your own miniature building templates</title>
		<link>https://karlagius.com/2020/04/20/how-to-make-your-own-miniature-building-templates/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Mon, 20 Apr 2020 18:03:19 +0000</pubDate>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Other Stuff]]></category>
		<guid isPermaLink="false">https://karlagius.com/?p=731</guid>

					<description><![CDATA[Using 3d modelling software and an image editor makes it pretty easy to make model templates. Since most buildings are generally based on boxes, you don't even need to be a modelling expert!]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Using 3d modelling software and an image editor makes it pretty easy to make model templates. Since most buildings are generally based on boxes, you don&#8217;t even need to be a modelling expert!<br><br>Watch the video below. You can also download the template files from <a href="https://karlagius.com/wp-content/uploads/2020/04/watchtower-template.pdf">here</a>!</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How to make your own miniature building templates" width="525" height="295" src="https://www.youtube.com/embed/TSjZ3W3kHWo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">731</post-id>	</item>
		<item>
		<title>From hand drawn sketch to vector &#8211; fast!</title>
		<link>https://karlagius.com/2019/10/27/from-hand-drawn-sketch-to-vector-fast/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Sun, 27 Oct 2019 21:35:18 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://karlagius.com/?p=709</guid>

					<description><![CDATA[This post is about turning a hand drawn sketch into a vector image, though you could just as well use a photo. The software I will be using is Inkscape, a free, open source vector graphics application which you can get from inkscape.org; however the principles should apply to pretty much any vector graphics application &#8230; <p class="link-more"><a href="https://karlagius.com/2019/10/27/from-hand-drawn-sketch-to-vector-fast/" class="more-link">Continue reading<span class="screen-reader-text"> "From hand drawn sketch to vector &#8211; fast!"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">This post is about turning a hand drawn sketch into a vector image, though you could just as well use a photo. The software I will be using is Inkscape, a free, open source vector graphics application which you can get from <a rel="noreferrer noopener" aria-label="inkscape.org (opens in a new tab)" href="https://inkscape.org/" target="_blank">inkscape.org</a>; however the principles should apply to pretty much any vector graphics application you might prefer.</p>



<div class="wp-block-image"><figure class="aligncenter"><img fetchpriority="high" decoding="async" width="1360" height="1360" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?fit=525%2C525&amp;ssl=1" alt="" class="wp-image-726" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?w=1360&amp;ssl=1 1360w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?resize=300%2C300&amp;ssl=1 300w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?resize=768%2C768&amp;ssl=1 768w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?resize=1024%2C1024&amp;ssl=1 1024w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/output2.png?resize=100%2C100&amp;ssl=1 100w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure></div>



<span id="more-709"></span>



<p class="wp-block-paragraph">If you prefer to watch this in video format, I got you covered!</p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="From hand drawn sketch to vector - fast!" width="525" height="295" src="https://www.youtube.com/embed/_7p3VHIGFjw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">The source file for this tutorial can be found at here:<a href="https://karlagius.com/wp-content/uploads/2019/10/sketch-e1572187076542.jpg" target="_blank" rel="noreferrer noopener" aria-label=" Source file (opens in a new tab)"> Source file</a>.</p>



<p class="wp-block-paragraph">The finished file, which you can use for reference, is:  <a href="https://karlagius.com/wp-content/uploads/2019/10/bunny-vector.svg" target="_blank" rel="noreferrer noopener" aria-label="SVG file (opens in a new tab)">SVG file</a>.</p>



<p class="wp-block-paragraph">Once you have the sketch open Inkscape,  lock the layer with the sketch and create a new layer to work in. We will be hiding the sketch layer later, so we don&#8217;t want to be drawing in it.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="322" height="186" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image.png?resize=322%2C186&#038;ssl=1" alt="" class="wp-image-710" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image.png?w=322&amp;ssl=1 322w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image.png?resize=300%2C173&amp;ssl=1 300w" sizes="auto, (max-width: 322px) 100vw, 322px" /></figure></div>



<p class="wp-block-paragraph">With the new layer selected, use the bezier curve tool to draw the outline of the bunny. Just click to place a node, then hold the left mouse button down and drag to adjust the curve.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="337" height="276" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-1.png?resize=337%2C276&#038;ssl=1" alt="" class="wp-image-711" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-1.png?w=337&amp;ssl=1 337w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-1.png?resize=300%2C246&amp;ssl=1 300w" sizes="auto, (max-width: 337px) 100vw, 337px" /></figure></div>



<p class="wp-block-paragraph"> Don&#8217;t worry too much about getting an exact outline, you can go back and tweak it later. Of course if something looks really off, you can always ctrl-z to undo back to the previous node.</p>



<p class="wp-block-paragraph">Once you close the curve, you should get an outline. We want to turn this into a silhouette, so change the fill color to solid black and set the stroke color to none. We still need to be able to see the sketch under this for now, so let&#8217;s temporarily make this translucent by dropping the opacity for the layer down low.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="332" height="143" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-2.png?resize=332%2C143&#038;ssl=1" alt="" class="wp-image-712" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-2.png?w=332&amp;ssl=1 332w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-2.png?resize=300%2C129&amp;ssl=1 300w" sizes="auto, (max-width: 332px) 100vw, 332px" /></figure></div>



<p class="wp-block-paragraph">Next, lock the layer we were working on and add a new layer where we will draw in the white area on the bunny. This time we&#8217;re only vaguely following the outline and only drawing around the areas that would be getting a lot of light &#8211; in a very stylized way of course. Other than that, it&#8217;s exactly the same as the black outline we just did. This time, set the fill to white.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="623" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-3.png?resize=525%2C623&#038;ssl=1" alt="" class="wp-image-713" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-3.png?w=541&amp;ssl=1 541w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-3.png?resize=253%2C300&amp;ssl=1 253w" sizes="auto, (max-width: 525px) 100vw, 525px" /></figure></div>



<p class="wp-block-paragraph">If you need to make any adjustments to the curves, you can use he node editing tool. The control points move the curve around, while the two handles attached to these points to alter the curve. </p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="341" height="407" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-4.png?resize=341%2C407&#038;ssl=1" alt="" class="wp-image-714" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-4.png?w=341&amp;ssl=1 341w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-4.png?resize=251%2C300&amp;ssl=1 251w" sizes="auto, (max-width: 341px) 100vw, 341px" /><figcaption>Nodes let you move points on the curve around.</figcaption></figure></div>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="327" height="368" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-5.png?resize=327%2C368&#038;ssl=1" alt="" class="wp-image-715" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-5.png?w=327&amp;ssl=1 327w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-5.png?resize=267%2C300&amp;ssl=1 267w" sizes="auto, (max-width: 327px) 100vw, 327px" /><figcaption>Handles let you alter the shape of the curve between two nodes.</figcaption></figure></div>



<p class="wp-block-paragraph">You can also add control points by selecting two adjacent points and clicking add node at the top of the window, or remove excess control points.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="359" height="119" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-6.png?resize=359%2C119&#038;ssl=1" alt="" class="wp-image-716" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-6.png?w=359&amp;ssl=1 359w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-6.png?resize=300%2C99&amp;ssl=1 300w" sizes="auto, (max-width: 359px) 100vw, 359px" /></figure></div>



<p class="wp-block-paragraph">Once it looks decent, it’s time to color in the bunny’s head and ears. Exact same procedure.</p>



<p class="wp-block-paragraph">Ok, layer locked, and it&#8217;s time to start adding some details. Before that, drop the opacity of this layer to make it translucent &#8211; easier than setting the transparency for each individual component. The translucency allows you to see the sketch under your drawing.</p>



<p class="wp-block-paragraph">This step is fairly quick, as we&#8217;re just drawing lines, and pressing enter or right clicking to end the curve without closing the path.</p>



<p class="wp-block-paragraph">Add a sublayer for the stitches, as this will allow you to select and modify them in one go. </p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="245" height="146" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-7.png?resize=245%2C146&#038;ssl=1" alt="" class="wp-image-717"/></figure></div>



<p class="wp-block-paragraph">Use the stroke style to thicken up these lines, and make their ends round.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="285" height="303" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-8.png?resize=285%2C303&#038;ssl=1" alt="" class="wp-image-718" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-8.png?w=285&amp;ssl=1 285w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-8.png?resize=282%2C300&amp;ssl=1 282w" sizes="auto, (max-width: 285px) 100vw, 285px" /><figcaption>The stroke style panel allows you to set the thickness of a line, as well as the line endings, dashes and so on.</figcaption></figure></div>



<p class="wp-block-paragraph">Moving on, add a nose, and some color to the belly and ears. Same as before, new layer and bezier tool.</p>



<p class="wp-block-paragraph">Next up, the eyes. Use the ellipse tool to get the overall shape of the buttons. By holding down shift, we can draw the ellipse around a point. <br></p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="418" height="367" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-9.png?resize=418%2C367&#038;ssl=1" alt="" class="wp-image-719" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-9.png?w=418&amp;ssl=1 418w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-9.png?resize=300%2C263&amp;ssl=1 300w" sizes="auto, (max-width: 418px) 100vw, 418px" /><figcaption>When drawing shapes in Inkscape, hold down SHIFT to draw around a point. Holding down CTRL creates a constrained shape (for example, a circle in the case of the Ellipse tool.</figcaption></figure></div>



<p class="wp-block-paragraph">Using the bezier tool, add a little patch here. Lower the alpha so that the patch shades the underlying color. repeat on the other eye, and add more little ellipses to simulate button holes. Use CTRL-D to duplicate them, then move them in place. For the stitches, you guessed it, bezier tool.</p>



<p class="wp-block-paragraph">With the eyes done, group each eye separately by selecting the components and pressing CTRL-G. This lets you select and move them around in one unit, rather than having to move every single component. The reason we&#8217;re doing this is to find a good position for them, because eye position can make the difference between creepy, funny, and stuff. Just move them around till it looks ok to you.</p>



<p class="wp-block-paragraph">As a final step, let&#8217;s add some shading.  To add shading, I just draw shapes where I want the shading to go, turn alpha pretty low, and pick a color. You can also readjust the position of the shape as you prefer.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="299" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-10.png?resize=525%2C299&#038;ssl=1" alt="" class="wp-image-720" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-10.png?w=877&amp;ssl=1 877w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-10.png?resize=300%2C171&amp;ssl=1 300w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/10/image-10.png?resize=768%2C438&amp;ssl=1 768w" sizes="auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure></div>



<p class="wp-block-paragraph">Ok, that’s it for this post &#8211; I hope you found it useful, and if you know someone who might enjoy this please share the video with them! If you have any questions or ideas, please drop me a comment below or on my <a href="https://www.facebook.com/karlmakesstuff/">facebook page</a>! </p>



<p class="wp-block-paragraph">Thank you for reading, and see you around!</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">709</post-id>	</item>
		<item>
		<title>Pain free Tables of Contents in most word processors</title>
		<link>https://karlagius.com/2019/07/01/pain-free-tables-of-contents-in-most-word-processors/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Mon, 01 Jul 2019 12:49:51 +0000</pubDate>
				<category><![CDATA[Other Stuff]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[table of contents]]></category>
		<category><![CDATA[word processing]]></category>
		<guid isPermaLink="false">https://karlagius.com/?p=687</guid>

					<description><![CDATA[In this post I will show you how to make a pain-free table of contents for your documents. I will be using Google Docs but the exact same techniques apply to Microsoft Word, Pages, and Libre Office, with just some things being labelled differently.&#160; If you prefer to follow along with a video, you can &#8230; <p class="link-more"><a href="https://karlagius.com/2019/07/01/pain-free-tables-of-contents-in-most-word-processors/" class="more-link">Continue reading<span class="screen-reader-text"> "Pain free Tables of Contents in most word processors"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this post I will show you how to make a pain-free table of contents for your documents. I will be using Google Docs but the  exact same techniques apply to Microsoft Word, Pages, and Libre Office, with just some things being labelled differently.&nbsp;  If you prefer to follow along with a video, you can watch that here: </p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Making Tables of Contents" width="525" height="295" src="https://www.youtube.com/embed/VGr_ZTpVcD0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">This is a very simple operation but a lot of people seem to miss it, and try to build their table of contents manually. This might work ok if you’re working on a short document, but if you’re writing anything longer it very quickly becomes a mess. And even if you manage to nail it down, you add an image or change the font size, and boom, you have to renumber all the entries.</p>



<span id="more-687"></span>



<p class="wp-block-paragraph">So what can you do instead? First off, make sure all the headings you want in your table of contents are marked with Heading styles. </p>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="400" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/apply_style.jpg?resize=525%2C400&#038;ssl=1" alt="" class="wp-image-690" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/apply_style.jpg?w=775&amp;ssl=1 775w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/apply_style.jpg?resize=300%2C228&amp;ssl=1 300w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/apply_style.jpg?resize=768%2C585&amp;ssl=1 768w" sizes="auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p class="wp-block-paragraph">Then, you go to the place in your document where you want your table of contents to go, head to the “Insert” menu and head to the table of contents. Select “Table of contents” and you’re good to go.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="469" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/add_table_of_contents.jpg?resize=525%2C469&#038;ssl=1" alt="" class="wp-image-689" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/add_table_of_contents.jpg?w=774&amp;ssl=1 774w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/add_table_of_contents.jpg?resize=300%2C268&amp;ssl=1 300w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/add_table_of_contents.jpg?resize=768%2C687&amp;ssl=1 768w" sizes="auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure></div>



<p class="wp-block-paragraph">creates the following:</p>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="152" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/toc-1.png?resize=525%2C152&#038;ssl=1" alt="" class="wp-image-699" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/toc-1.png?w=704&amp;ssl=1 704w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/toc-1.png?resize=300%2C87&amp;ssl=1 300w" sizes="auto, (max-width: 525px) 100vw, 525px" /></figure>



<p class="wp-block-paragraph"> Headers creating using Heading 2, Heading 3 styles etc will be indented under their parent heading, which lets you have a nice hierarchical table of contents.</p>



<p class="wp-block-paragraph">If you move stuff around later, you will just need to head back to your table and select refresh table &#8211; and easy as that, all the page numbers are updated.</p>



<p class="wp-block-paragraph">This is the same way I built the table of contents for <a href="https://karlagius.com/2014/09/15/the-little-book-of-javascript/" target="_blank" rel="noreferrer noopener" aria-label="my book (opens in a new tab)">my book</a> a few years ago, and let me tell you there&#8217;s no way I would have been able to do it manually. </p>



<p class="wp-block-paragraph">There&#8217;s another bonus that comes with styles: styles let you change all items of the same type in one go, so if at some point you decided that all your headings should be in a particular font (in the video I set it to comic sans, here I&#8217;m changing it back because comic sans is an abomination), you can just go ahead and edit one heading, right click, and hit “Update `heading 1` to match”. And all the headings of the same type will get updated to match. Again, simple tip but one that many people seem to miss so I hope this will save a lot of frustration.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="253" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/update_styles.jpg?resize=525%2C253&#038;ssl=1" alt="" class="wp-image-688" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/update_styles.jpg?w=742&amp;ssl=1 742w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/update_styles.jpg?resize=300%2C145&amp;ssl=1 300w" sizes="auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure></div>



<p class="wp-block-paragraph">I hope this was helpful, and if you enjoyed this content please consider sharing this post with someone who might find it useful. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p> <em>Want to host your own website? Check out </em><a href="https://www.bluehost.com/track/kagius/painfreetocs" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">Bluehost (full disclosure &#8211; affiliate link)</a><em> &#8211; I have been using their services for all of my sites for some time and so far I&#8217;ve only got good things to say about them!</em> </p></blockquote>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">687</post-id>	</item>
		<item>
		<title>3D Scanning at home</title>
		<link>https://karlagius.com/2019/06/29/3d-scanning-at-home/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Sat, 29 Jun 2019 11:04:52 +0000</pubDate>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Other Stuff]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3d modelling]]></category>
		<category><![CDATA[3d scanning]]></category>
		<category><![CDATA[blender3d]]></category>
		<category><![CDATA[meshroom]]></category>
		<category><![CDATA[photogrammetry]]></category>
		<guid isPermaLink="false">https://karlagius.com/?p=670</guid>

					<description><![CDATA[I used to think that 3d scanning was something that had to be done in a lab or using some very expensive equipment, but thanks to Steve from CG Geek, I learnt that it can be done with some awesome free software and equipment I already have. In his tutorial, Steve demonstrates how you can &#8230; <p class="link-more"><a href="https://karlagius.com/2019/06/29/3d-scanning-at-home/" class="more-link">Continue reading<span class="screen-reader-text"> "3D Scanning at home"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"> I used to think that 3d scanning was something that had to be done in a lab or using some very expensive equipment, but thanks to <a rel="noreferrer noopener" href="https://youtu.be/k4NTf0hMjtY" target="_blank">Steve from CG Geek</a>, I learnt that it can be done with some awesome free software and equipment I already have. </p>



<p class="wp-block-paragraph">In his tutorial, Steve demonstrates how you can capture a large object, and I highly recommend watching it because he explains the process very well. What I’ll be discussing in this post is capturing a <strong>small</strong> object using a slightly different technique which should be easier for this size. If you prefer to follow along with a video, I got you covered:</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Nearly free 3d scans - home photogrammetry for everyone" width="525" height="295" src="https://www.youtube.com/embed/cys3mFmg404?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<span id="more-670"></span>



<p class="wp-block-paragraph">I am going to use is a technique called photogrammetry, where you can take a bunch of reference pictures, run them through your software, and get a 3d model out the other end. Below is a sample of the scanned miniature after it was run through Blender:</p>



<figure class="wp-block-embed is-type-rich is-provider-instagram wp-block-embed-instagram"><div class="wp-block-embed__wrapper">
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/By2-eC8nqg1/?utm_source=ig_embed&amp;utm_campaign=loading" data-instgrm-version="14" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:525px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <a href="https://www.instagram.com/p/By2-eC8nqg1/?utm_source=ig_embed&amp;utm_campaign=loading" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;" target="_blank"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-511.000000, -20.000000)" fill="#000000"><g><path d="M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631"></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;">View this post on Instagram</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"></div></div></a><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/By2-eC8nqg1/?utm_source=ig_embed&amp;utm_campaign=loading" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">A post shared by Karl Agius (@agius_k)</a></p></div></blockquote><script async src="//platform.instagram.com/en_US/embeds.js"></script>
</div></figure>



<h2 class="wp-block-heading">1. Pick your subject</h2>



<p class="wp-block-paragraph">First, choose your subject. Miniatures are almost a worst case scenario for this kind of work&nbsp; because they are very small, and the detail is tiny. We&#8217;re talking fractions of a millimeter here. Add that to the fact that I&#8217;m going to be running a painted miniature through this process, and it makes it even worse.&nbsp;</p>



<p class="wp-block-paragraph">The first miniature I tried to scan was this one I sculpted about 20 years ago. </p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1137" height="1496" src="https://i2.wp.com/karlagius.com/wp-content/uploads/2019/06/S1010355-3.jpg?fit=525%2C691&amp;ssl=1" alt="" class="wp-image-672" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/S1010355-3.jpg?w=1137&amp;ssl=1 1137w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/S1010355-3.jpg?resize=228%2C300&amp;ssl=1 228w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/S1010355-3.jpg?resize=768%2C1010&amp;ssl=1 768w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/S1010355-3.jpg?resize=778%2C1024&amp;ssl=1 778w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/S1010355-3.jpg?w=1050&amp;ssl=1 1050w" sizes="auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p class="wp-block-paragraph">Unfortunately, it has very little detail for the software to latch on to, and it includes parts covered in metallic paint and a layer of varnish, which totally confused the software. The results were, let&#8217;s say trippy.</p>



<figure class="wp-block-embed is-type-rich is-provider-instagram wp-block-embed-instagram"><div class="wp-block-embed__wrapper">
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/ByvAYU4nFgC/?utm_source=ig_embed&amp;utm_campaign=loading" data-instgrm-version="14" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:525px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <a href="https://www.instagram.com/p/ByvAYU4nFgC/?utm_source=ig_embed&amp;utm_campaign=loading" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;" target="_blank"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-511.000000, -20.000000)" fill="#000000"><g><path d="M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631"></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;">View this post on Instagram</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"></div></div></a><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/ByvAYU4nFgC/?utm_source=ig_embed&amp;utm_campaign=loading" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">A post shared by Karl Agius (@agius_k)</a></p></div></blockquote><script async src="//platform.instagram.com/en_US/embeds.js"></script>
</div></figure>



<p class="wp-block-paragraph">Instead, now I&#8217;m going to try with this Games Workshop zombie, purely for experiment; people, do not copy copyrighted stuff. It&#8217;s not cool. This model has more clearly defined detail and color variations, which should help.</p>



<figure class="wp-block-embed is-type-rich is-provider-instagram wp-block-embed-instagram"><div class="wp-block-embed__wrapper">
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/BuPTf6EndJB/?utm_source=ig_embed&amp;utm_campaign=loading" data-instgrm-version="14" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:525px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <a href="https://www.instagram.com/p/BuPTf6EndJB/?utm_source=ig_embed&amp;utm_campaign=loading" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;" target="_blank"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-511.000000, -20.000000)" fill="#000000"><g><path d="M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631"></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;">View this post on Instagram</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"></div></div></a><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/BuPTf6EndJB/?utm_source=ig_embed&amp;utm_campaign=loading" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">A post shared by Karl Agius (@agius_k)</a></p></div></blockquote><script async src="//platform.instagram.com/en_US/embeds.js"></script>
</div></figure>



<h2 class="wp-block-heading">2. Lighting</h2>



<p class="wp-block-paragraph">Step two, lighting. To begin with, I taped down my <a href="https://youtu.be/Xjm_DT0ei2E" target="_blank" rel="noreferrer noopener" aria-label="home made light box (opens in a new tab)">home made light box</a> to a solid surface so it wouldn’t move as I worked. The light box ensures that the lighting is consistent and that the object is properly illuminated. I am not using a background in the light box here since the depth of field seems to help the process. Also… well, the results with a background were kind of funky.</p>



<figure class="wp-block-embed is-type-rich is-provider-instagram wp-block-embed-instagram"><div class="wp-block-embed__wrapper">
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/Byum-lynslN/?utm_source=ig_embed&amp;utm_campaign=loading" data-instgrm-version="14" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:525px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <a href="https://www.instagram.com/p/Byum-lynslN/?utm_source=ig_embed&amp;utm_campaign=loading" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;" target="_blank"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-511.000000, -20.000000)" fill="#000000"><g><path d="M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631"></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;">View this post on Instagram</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"></div></div></a><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/Byum-lynslN/?utm_source=ig_embed&amp;utm_campaign=loading" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">A post shared by Karl Agius (@agius_k)</a></p></div></blockquote><script async src="//platform.instagram.com/en_US/embeds.js"></script>
</div></figure>



<p class="wp-block-paragraph">If you do not have a light box and don&#8217;t fancy making or buying one, don&#8217;t worry &#8211; just use indirect sunlight &#8211; an overcast day is perfect for this. What you are looking for here is even lighting with no weird shadows.</p>



<h2 class="wp-block-heading">3. Set up the camera and subject</h2>



<p class="wp-block-paragraph">Third, photograph the mini at consistent angle intervals. From experiments I did yesterday, I determined that my hands are not good at this level of precision. Instead, I made a small jig I can use to turn the mini 10 degrees each time. This is literally just two paper circles with angle markings held together with a pin </p>



<p class="wp-block-paragraph">This allowed me to rotate the miniature around a fixed center, and by lining up the markings on the smaller and the larger circle I could guarantee that the rotation was a consistent 10 degrees. The numbers on the segments were added in case I had to re-take any angles. Since the pin stuck some way out of the surface, I also added a bottle cap so the mini would sit flat, and taped the mini on top.</p>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="403" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-1-29-06-2019-12-48.png?resize=525%2C403&#038;ssl=1" alt="" class="wp-image-676" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-1-29-06-2019-12-48.png?w=652&amp;ssl=1 652w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-1-29-06-2019-12-48.png?resize=300%2C230&amp;ssl=1 300w" sizes="auto, (max-width: 525px) 100vw, 525px" /></figure>



<p class="wp-block-paragraph">With the subject in place, I set up the camera on a tripod and made sure that all the settings were set to manual. This ensures that all the settings remain the same through the shooting. I used my video camera to take stills here, though you should be able to get better results from a photo camera or even some  mobile cameras since the sensor tends to be larger.&nbsp;</p>



<h2 class="wp-block-heading">4. Start snapping photos</h2>



<p class="wp-block-paragraph">Step four, I started snapping photos. After every photo, I rotated the subject 10 degrees. Then I repeated this a couple of times from different heights.</p>



<h2 class="wp-block-heading">5. Run the photos through Meshroom</h2>



<p class="wp-block-paragraph">Step five, I took my SD card and imported all the photos into <a rel="noreferrer noopener" aria-label="Meshroom (opens in a new tab)" href="https://alicevision.github.io/#meshroom" target="_blank">Meshroom</a>. This software is free to download and use, and you can find the link in the description below. It is a magnificent tool, honestly, to the team who made this: you blew my mind. It&#8217;s literally a case of dropping the photos in the application and hitting start.</p>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="296" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-2-29-06-2019-12-52.png?resize=525%2C296&#038;ssl=1" alt="" class="wp-image-677" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-2-29-06-2019-12-52.png?w=890&amp;ssl=1 890w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-2-29-06-2019-12-52.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-2-29-06-2019-12-52.png?resize=768%2C432&amp;ssl=1 768w" sizes="auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p class="wp-block-paragraph">In my first run through, most of the model looked great but was missing some parts like the jaw and the fingers on the left hand. This corresponds to areas where the software couldn&#8217;t extract enough information from the image. I was still very impressed by the quality of what did get modelled, so I tried to bump up the definer preset to high and made another run with the same set of images to see if I could get a better model.</p>



<p class="wp-block-paragraph">Unfortunately that stopped working because it ran into a known issue, a known bug in version 2019.01. No big deal. What I did was I went back and downloaded version 2018.01 and set it running again, and worked fine with the high preset.</p>



<p class="wp-block-paragraph">I don’t think that’s a big deal for me and to be honest, if I had used a better camera in the first place, I don’t think I would have needed the high preset anyway.</p>



<p class="wp-block-paragraph">I’m also told that the next version with the fix for this will be out in the coming months; to be honest though, if you’re going to try this what I would suggest is get 2019 anyway and chances are that if you’re using a decent camera you’re not going to have this problem anyway.</p>



<p class="wp-block-paragraph">The model was completely scanned this time, with only a couple of artefacts around the armpits and near the crotch; this is great for a scan of a miniature, and it’s stuff I can clean up in blender anyway. </p>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="525" height="296" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-3-29-06-2019-12-53.png?resize=525%2C296&#038;ssl=1" alt="" class="wp-image-678" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-3-29-06-2019-12-53.png?w=890&amp;ssl=1 890w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-3-29-06-2019-12-53.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-3-29-06-2019-12-53.png?resize=768%2C432&amp;ssl=1 768w" sizes="auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p class="wp-block-paragraph">When importing a model scanned with Meshroom into Blender, it&#8217;s a good idea to switch to the Cycles renderer, as this allows it to import and attach all the texture nodes. </p>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="470" height="391" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-4-29-06-2019-12-53.png?resize=470%2C391&#038;ssl=1" alt="" class="wp-image-679" srcset="https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-4-29-06-2019-12-53.png?w=470&amp;ssl=1 470w, https://i0.wp.com/karlagius.com/wp-content/uploads/2019/06/Snapshot-4-29-06-2019-12-53.png?resize=300%2C250&amp;ssl=1 300w" sizes="auto, (max-width: 470px) 100vw, 470px" /></figure>



<p class="wp-block-paragraph">Considering this is a photo scan of a 28mm mini with an ok camera, what the software did was pretty amazing. </p>



<p class="wp-block-paragraph">And that’s it for this experiment. Of course I barely scratched the surface here and there&#8217;s a lot I need to learn about preparing images and tweaking settings. However I am now confident that this is doable. </p>



<p class="wp-block-paragraph">I hope you found this useful and if you have any comments or suggestions, I’d love to hear them so do leave a comment. </p>



<p class="wp-block-paragraph">Before I close this off, I’d just like to thank the people who made Meshroom, they really made a fantastic product &#8211; maximum respect. Thanks also go to CG Geek for the smashing tutorial.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Want to host your own website? Check out <a rel="noreferrer noopener" aria-label="Bluehost (affiliate link) (opens in a new tab)" href="https://www.bluehost.com/track/kagius/simple-3d-footer" target="_blank">Bluehost (full disclosure &#8211; affiliate link)</a> &#8211; I have been using their services for all of my sites for some time and so far I&#8217;ve only got good things to say about them!</p></blockquote>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">670</post-id>	</item>
		<item>
		<title>Playing with bit masks</title>
		<link>https://karlagius.com/2018/09/21/playing-with-bit-masks/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Fri, 21 Sep 2018 10:36:49 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">http://karlagius.com/?p=669</guid>

					<description><![CDATA[With storage and bandwidth being easily available, compressing data for general use is less of a concern today than it was 20 years ago. However neither is free or unlimited, and with large scale applications a few bits can get multiplied over a few million connections; similarly, we may be talking to a client living on a smart toaster which doesn't have much in the way of storage space. In both situations, reducing the size of the data we are storing or sending may be technically necessary, and save on operational costs.

One way to do this is to use bit operations to reduce a state to a single number. This is nothing new; anyone who has ever used flags knows how it works. The catch is that you cannot crunch detailed information in this way; it only works for boolean values. Even so, depending on the structure of your data you should be able to leverage it rather easily.
]]></description>
										<content:encoded><![CDATA[<p>With storage and bandwidth being easily available, compressing data for general use is less of a concern today than it was 20 years ago. However neither is free or unlimited, and with large scale applications a few bits can get multiplied over a few million connections; similarly, we may be talking to a client living on a smart toaster which doesn&#8217;t have much in the way of storage space. In both situations, reducing the size of the data we are storing or sending may be technically necessary, and save on operational costs.</p>
<p>One way to do this is to use bit operations to reduce a state to a single number. This is nothing new; anyone who has ever used flags knows how it works. The catch is that you cannot crunch detailed information in this way; it only works for boolean values. Even so, depending on the structure of your data you should be able to leverage it rather easily.</p>
<p>For these examples we&#8217;ll use JavaScript; however the concepts apply to any language.<span id="more-669"></span><!--more--></p>
<p>Let&#8217;s start with a JSON object. JSON is great, but even if it&#8217;s a massive step up from good old XML, it can still be rather verbose. Say we have the following state object we want to save or send.</p>
<pre>var gameStateFlags = {
	"mission.abc.complete": false,
	"mission.xyz.complete": true,
	"mission.123.complete": false,
	"collected.gizmo.123": true,
	"talked.to.npc.ssadf": false,
	"talked.to.npc.eoesk": true
}</pre>
<p>We can easily compress this, as long as we have a set of numeric values we can map to each property. Let&#8217;s say:</p>
<pre>var states = {
	"mission.abc.complete": 1,
	"mission.xyz.complete": 2,
	"mission.123.complete": 4,
	"collected.gizmo.123": 8,
	"talked.to.npc.ssadf": 16,
	"talked.to.npc.eoesk": 32
}
</pre>
<p>Each successive property name is mapped to 2 to the power of n. You could even autogenerate this, though I&#8217;m not a fan of that approach; changing the order would cause different values to be mapped, leading to glitches when reading data stored using a different map.</p>
<p>Now that we have a numeric value for the properties, we can OR them together where they are true:</p>
<pre>var serialize = function(state) {
	var serializedState = 0;

	Object.keys(state).forEach(function(flag) {
		if (state[flag]) serializedState |= states[flag];
	});

	return serializedState;
}
</pre>
<p>Let&#8217;s call serialize(gameStateFlags). We start with a serializedState of 0 (or 00000000 if we assume an 8 bit number). If we try to process each property in turn:<br />
&#8220;mission.abc.complete&#8221; is false so nothing happens.<br />
&#8220;mission.xyz.complete&#8221; is true, so we find its value (2, or 00000010) and OR it into the state. 00000000 | 00000010 gives us 00000010.<br />
&#8220;mission.123.complete&#8221; is false so nothing happens.<br />
&#8220;collected.gizmo.123&#8221;: is true, so we find its value (8, or 00001000) and OR it into the state. 00000010 | 00001000 gives us 00001010.<br />
&#8220;talked.to.npc.ssadf&#8221;: is false so nothing happens.<br />
&#8220;talked.to.npc.eoesk&#8221;: is true, so we find its value (32, or 00100000) and OR it into the state. 00001010 | 00100000 gives us 00101010.</p>
<p>The end result is 00101010, or 42. (Sure, we could have found this just by doing 2 + 8 + 32, but bear with me &#8211; it will help understand the reading later). We can send this over the wire, or store it, using much less space than it would have taken to store the entire object.</p>
<p>Now, how do we turn our number back into a usable object? Provided (and this is important) that the reader has the same set of mapped values, we can just reverse the process using the AND operator:</p>
<pre>var deserialize = function(stateValue) {
	var deserializedState = {};

	Object.keys(states).forEach(function(flag) {
		deserializedState[flag] = ((stateValue &amp; states[flag]) != 0);
	});

	return deserializedState;
}
</pre>
<p>If we deserialize(42), we will compare the bit for each property against the bits that make up our number. The &amp; will work as a bit mask, and the result will only contain bits which appear in both numbers. Let&#8217;s take the first one, &#8220;mission.abc.complete&#8221;. The value for that is 1, or 00000001.</p>
<p>42: 00101010<br />
01: 00000001<br />
&#8212;&#8212;&#8212;&#8212;<br />
&amp;: 00000000</p>
<p>In this case, since there are no matching bits we get 0, which we interpret as false.</p>
<p>Taking the second one (&#8220;mission.xyz.complete&#8221;, value 2):</p>
<p>42: 00101010<br />
01: 00000010<br />
&#8212;&#8212;&#8212;&#8212;<br />
&amp;: 00000010</p>
<p>This time we do have a matching bit at position 2, so we get a non-zero value which we interpret as 2.</p>
<p>This is the reason we only use 2^n for the mapping, rather than just picking any which number. &#8220;3&#8221; would be ambiguous, since it can be the result of both 1 and 2 being present. That said, the reader can use this to advantage if it is only interested in knowing some facts without processing the whole thing. Let&#8217;s say your reader only needs to know if &#8220;mission.abc.complete&#8221; or &#8220;collected.gizmo.123&#8221; are true. Rather than desrializing the whole thing, you could just use the following:</p>
<pre>var missionAbcCompleteOrCollectedGizmo123Mask = states["mission.abc.complete"] + states["collected.gizmo.123"];
</pre>
<p>This will set the value to 9 (1 + 8). Checking this against our original value, 42:</p>
<pre>var missionAbcCompleteOrCollectedGizmo123 = (42 &amp; missionAbcCompleteOrCollectedGizmo123Mask) != 0;
</pre>
<p>42: 00101010<br />
01: 00001001<br />
&#8212;&#8212;&#8212;&#8212;<br />
&amp;: 00001000</p>
<p>This gives 8 (the matching bit), a non-zero value, so we know that one of the two criteria was met.</p>
<p>While this is a pretty old school way of doing things, it&#8217;s still a useful trick to have up one&#8217;s sleeve, especially if one is working with smaller, low power devices. If you have any questions or thoughts on the subject, let me know in the comments below!</p>
<div class="alert"><strong>Moar JavaScript?</strong> Check out <a title="The Little Book of JavaScript" href="https://karlagius.com/2014/09/15/the-little-book-of-javascript/">The Little Book of JavaScript</a>!</div>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">669</post-id>	</item>
		<item>
		<title>The Little Book of JavaScript</title>
		<link>https://karlagius.com/2014/09/15/the-little-book-of-javascript/</link>
					<comments>https://karlagius.com/2014/09/15/the-little-book-of-javascript/#comments</comments>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Mon, 15 Sep 2014 09:54:59 +0000</pubDate>
				<category><![CDATA[Other Stuff]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[Javascript]]></category>
		<guid isPermaLink="false">http://karlagius.com/?p=587</guid>

					<description><![CDATA[I finally bit the bullet, sat down to do some writing again, and had a go at self publishing. The result is The Little Book of JavaScript, a short book containing a few odds and ends which I believe are useful for a novice or intermediate scripter. It won&#8217;t take you through writing a complete &#8230; <p class="link-more"><a href="https://karlagius.com/2014/09/15/the-little-book-of-javascript/" class="more-link">Continue reading<span class="screen-reader-text"> "The Little Book of JavaScript"</span></a></p>]]></description>
										<content:encoded><![CDATA[<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-592 alignright" style="border: none; margin-top: -8px;" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2014/09/product_thumbnail.jpg?resize=212%2C320&#038;ssl=1" alt="product_thumbnail" width="212" height="320" />I finally bit the bullet, sat down to do some writing again, and had a go at self publishing. The result is The Little Book of JavaScript, a short book containing a few odds and ends which I believe are useful for a novice or intermediate scripter.</p>
<p><span id="more-587"></span>It won&#8217;t take you through writing a complete application, and I&#8217;m assuming that the people who read it are a bit past the &#8220;hello world&#8221; phase. It&#8217;s aimed at people who have dabbled a little, but need a few gaps filled in. The book focuses on raw JavaScript concepts as opposed to their use in any particular framework.</p>
<p>The print version of &#8220;The Little Book of JavaScript&#8221; is available from <a title="The Little Book of JavaScript [Paperback] at Amazon" href="http://www.amazon.co.uk/Little-Book-JavaScript-Karl-Agius/dp/1312466022/" target="_blank">Amazon</a> and <a title="The Little Book of JavaScript [Paperback] at lulu.com" href="http://www.lulu.com/shop/karl-agius/the-little-book-of-javascript/paperback/product-21807034.html" target="_blank">Lulu.com</a>.</p>
<p>The eBook is available from <a title="The Little Book of JavaScript [eBook] at lulu.com" href="http://www.lulu.com/shop/karl-agius/the-little-book-of-javascript/ebook/product-21806641.html" target="_blank">Lulu.com</a>, <a title="The Little Book of JavaScript [eBook] at Amazon.co.uk" href="http://www.amazon.co.uk/Little-Book-Javascript-Karl-Agius-ebook/dp/B00NT65UW0/" target="_blank">Amazon</a>, <a title="The Little Book of JavaScript [eBook] at Nook" href="http://www.barnesandnoble.com/w/the-little-book-of-javascript-karl-agius/1120416543?ean=9781312520493" target="_blank">Nook</a> and <a title="The Little Book of JavaScript [eBook] at Kobo" href="http://store.kobobooks.com/en-US/ebook/the-little-book-of-javascript" target="_blank">Kobo</a></p>
<p>[Edit 30/09/2014]Just received my printed copy, and it looks great! I&#8217;d happily recommend lulu.com for anyone who wants to publish something.</p>
<style>
.toc ul { margin-left:4em; }
</style>
<p>Here&#8217;s a list of topics covered:</p>
<ul class="toc">
<li>Some basics
<ul>
<li>Variable definition</li>
<li>Undefined variables</li>
<li>Strict and Lenient Equality</li>
<li>Logical and Bitwise operators
<ul>
<li>And: &amp; and &amp;&amp;</li>
<li>Or: | and ||</li>
<li>The Negation Operator</li>
</ul>
</li>
<li>The Ternary Operator</li>
<li>Scopes
<ul>
<li>Redefining variables in a scope</li>
</ul>
</li>
<li>Closures</li>
</ul>
</li>
<li>Functions
<ul>
<li>Declaring functions</li>
<li>Function parameters
<ul>
<li>Value and reference arguments</li>
</ul>
</li>
<li>Return values
<ul>
<li>Fluent APIs</li>
</ul>
</li>
<li>Functions as variables</li>
<li>“this”
<ul>
<li>Preserving context using closures</li>
<li>Bind</li>
</ul>
</li>
<li>Callbacks</li>
</ul>
</li>
<li>Object Oriented JavaScript
<ul>
<li>Classes
<ul>
<li>Constructors</li>
<li>Creating instances</li>
<li>“Singleton” constructors</li>
</ul>
</li>
<li>Objects
<ul>
<li>Adding Properties or Functions to Objects</li>
<li>Namespaces</li>
</ul>
</li>
<li>Prototypes
<ul>
<li>The Constructor property</li>
</ul>
</li>
<li>Inline Definitions and JSON</li>
</ul>
</li>
<li>Strict Mode JavaScript
<ul>
<li>Enabling Strict Mode</li>
<li>Effects of Strict Mode</li>
</ul>
</li>
</ul>
<p>I&#8217;d like to thank Claire, Chris, David and Matthew for checking the book and making sure nothing in it can accidentally awaken Chtulhu or cause a rain of angry goats or anything.</p>
<p>The print version of &#8220;The Little Book of JavaScript&#8221; is available from  <a title="The Little Book of JavaScript [Paperback] at Amazon" href="http://www.amazon.co.uk/Little-Book-JavaScript-Karl-Agius/dp/1312466022/" target="_blank">Amazon</a> and <a title="The Little Book of JavaScript [Paperback] at lulu.com" href="http://www.lulu.com/shop/karl-agius/the-little-book-of-javascript/paperback/product-21807034.html" target="_blank">Lulu.com</a>.</p>
<p>The eBook is available from <a title="The Little Book of JavaScript [eBook] at lulu.com" href="http://www.lulu.com/shop/karl-agius/the-little-book-of-javascript/ebook/product-21806641.html" target="_blank">Lulu.com</a>, <a title="The Little Book of JavaScript [eBook] at Amazon.co.uk" href="http://www.amazon.co.uk/Little-Book-Javascript-Karl-Agius-ebook/dp/B00NT65UW0/" target="_blank">Amazon</a>, <a title="The Little Book of JavaScript [eBook] at Nook" href="http://www.barnesandnoble.com/w/the-little-book-of-javascript-karl-agius/1120416543?ean=9781312520493" target="_blank">Nook</a> and <a title="The Little Book of JavaScript [eBook] at Kobo" href="http://store.kobobooks.com/en-US/ebook/the-little-book-of-javascript" target="_blank">Kobo</a></p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://karlagius.com/2014/09/15/the-little-book-of-javascript/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">587</post-id>	</item>
		<item>
		<title>Some further thoughts on templating WordPress</title>
		<link>https://karlagius.com/2013/04/13/some-further-thoughts-on-templating-wordpress/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Sat, 13 Apr 2013 10:51:05 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">http://karlagius.com/?p=577</guid>

					<description><![CDATA[In the last post, we looked at getting a Twig generated WordPress theme up and running. I&#8217;ll soon begin looking at styling it with SASS and then getting it&#160;JavaScript&#160;dependencies loaded via Require.js, but first, I&#8217;d like to clean up the&#160;template&#160;code a little. See, last time we were doing something like this to get the posts: &#8230; <p class="link-more"><a href="https://karlagius.com/2013/04/13/some-further-thoughts-on-templating-wordpress/" class="more-link">Continue reading<span class="screen-reader-text"> "Some further thoughts on templating WordPress"</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>In the <a title="Templating a WordPress theme with Twig" href="https://karlagius.com/2013/04/06/templating-a-wordpress-theme-with-twig/">last post</a>, we looked at getting a Twig generated WordPress theme up and running. I&#8217;ll soon begin looking at styling it with SASS and then getting it&nbsp;JavaScript&nbsp;dependencies loaded via Require.js, but first, I&#8217;d like to clean up the&nbsp;template&nbsp;code a little.<span id="more-577"></span> See, last time we were doing something like this to get the posts:</p>
<pre>{% for post in posts %}
	{% set format = site.get_post_format() %}
	{% include format 
              ? "content-" ~ format ~ ".html.twig" 
              : "content.html.twig" %}
{% else %} 
	{% include "content-none.html.twig" %}
{% endfor %&gt;</pre>
<p>Where &#8220;posts&#8221; was a php iterator that used the WordPress loop. We were also using a proxy class to access wordpress functions in the template. While this works, I wasn&#8217;t too happy with the situation in general. The template was making too many decisions and calling functions. Templates shouldn&#8217;t be heavy on logic, because their only purpose should be to display stuff, not to decide what gets displayed.</p>
<p>It also fails to address another problem that I find annoying in wordpress &#8211; the content tree is generated during the construction of the page, not before it. That means that certain information isn&#8217;t normally available while building the header, for example. In the past, I&#8217;ve used a workaround which involves multiple queries and resetting the loop, but this time, I wanted it built into the theme.</p>
<p>The solution is as simple as iterating through the loop completely before starting to render the templates. In this way, we can build up everything the template needs beforehand, so it does not need to make any additional calls. Data is accessible all through the template, and the template itself becomes much simpler. Here&#8217;s the part of index.php where we&#8217;re building up the content:</p>
<pre>	
if (have_posts()) {
    while (have_posts()) {
        the_post();

        $additional_classes = (is_sticky() &amp;&amp; is_home() &amp;&amp; !is_paged()) ? "featured" : "";

        $p = array(
            'id' =&gt; get_the_ID(),
            'template' =&gt; $site-&gt;get_format(),
            'title' =&gt; get_the_title(),
            'permalink' =&gt; get_permalink(),
            'author' =&gt; get_the_author(),	
            'classes' =&gt; get_post_class($additional_classes),
            'date' =&gt; get_the_time(get_option('date_format'))
        );

        if (is_single()) {
            $p['content'] = get_the_content();				
            $meta['description'] = get_the_excerpt();
        } else {
            $p['content'] = get_the_excerpt();

            if (has_post_thumbnail()) {
                $image_attributes = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
                $p['thumbnail'] = $image_attributes[0];
            }
        }

        if ($editable) {
            $p['editlink'] = get_edit_post_link();	
        }

        array_push($content, $p);
    }
}</pre>
<p>In the excerpt above, you can see that we&#8217;re pulling data in from wordpress itself, and adding some metadata of our own. For example,</p>
<pre>'template' =&gt; $site-&gt;get_format()</pre>
<p>tells the post which template file it should use, for example, content.html.twig, summary-gallery.html.twig, and so on. The template doesn&#8217;t need to make any decisions. We&#8217;re also taking the opportunity to make the fields consistent. In</p>
<pre>	if (is_single()) {
		$p['content'] = get_the_content();				
		$meta['description'] = get_the_excerpt();
	} else {
		$p['content'] = get_the_excerpt();
		...
	}</pre>
<p>We&#8217;re setting the post content to the value of content if we&#8217;re showing a single post, or the value of the summary if we&#8217;re showing a list of posts. Both the summary and the full post templates will receive a &#8216;content&#8217; property that represents their primary content:</p>
<pre>&lt;article id="post-{{ p.id ?: "0" }}" class="{{ p.classes|join(" ") ?: "post no-results not-found" }}"&gt;
	&lt;header class="entry-header row-fluid"&gt;
		&lt;h1 class="entry-title"&gt;
			{% block articleHeader %}
				&lt;a href="{{ p.permalink }}" title="{{ site.text('Permalink to %s')|format(p.title)|e }}" rel="bookmark"&gt;{{ p.title }}&lt;/a&gt;
			{% endblock %}
		&lt;/h1&gt;
	&lt;/header&gt;

	&lt;div class="entry-content row-fluid"&gt;{% block articleContent %}{{ p.content|raw }}{% endblock %}&lt;/div&gt;

	&lt;footer class="entry-meta row-fluid"&gt;
		{% block articleFooter %}
			&lt;div class="meta"&gt;{{ site.text('Posted on &lt;span class="date"&gt;%s&lt;/span&gt;'|format(p.date))|raw }} {{ site.text('by &lt;span class="author"&gt;%s&lt;/span&gt;')|format(p.author)|raw }}&lt;/div&gt;
			{% if meta.editable %}&lt;a href="{{ p.editlink }}" class="edit"&gt;{{ site.text("Edit") }}&lt;/a&gt;{% endif %}
		{% endblock %}
	&lt;/footer&gt;
&lt;/article&gt;</pre>
<p><small>content-master.html.twig</small></p>
<pre>&lt;article
	id="post-{{ p.id }}" 
	class="{{ p.classes|join(" ") }} summary row-fluid"&gt;

	&lt;a href="{{ p.permalink }}" title="{{ site.text('Permalink to %s')|format(p.title)|e }}" rel="bookmark"&gt;

	{% if p.thumbnail %}
		&lt;img src="{{ p.thumbnail }}" class="thumbnail span2" title="{{ p.title()|e }}" /&gt;
	{% else %}
		&lt;div class="no thumbnail span2"&gt;{{ site.text("no thumbnail") }}&lt;/div&gt;
	{% endif %}

	&lt;article class="summary span8"&gt;
		&lt;header class="entry-header row-fluid"&gt;
			&lt;h1 class="entry-title"&gt;
				{% block articleHeader %}{{ p.title }}{% endblock %}
			&lt;/h1&gt;
		&lt;/header&gt;

		&lt;section class="entry-content row-fluid"&gt;
			{% block articleContent %}{{ p.content|raw }}{% endblock %}
		&lt;/section&gt;

		&lt;footer class="entry-meta row-fluid"&gt;
			{% block articleFooter %}
				{% if meta.editable %}
					&lt;a href="{{ p.editlink }}" class="edit"&gt;{{ site.text("Edit") }}&lt;/a&gt;
				{% endif %}
			{% endblock %}
		&lt;/footer&gt;
	&lt;/article&gt;
&lt;/a&gt;
&lt;/article&gt;</pre>
<p><small>summary-master.html.twig</small></p>
<p>While the main template now simply looks like this:</p>
<pre>{% extends "master.html.twig" %}
{% block pageContent %}</pre>
<section id="content" role="main">{% for p in posts %} {% include p.template %} {% else %} {% include &#8220;content-none.html.twig&#8221; %} {% endfor %}</section>
<p>{% endblock %}</p>
<p><small>index.html.twig</small></p>
<p>The only function I&#8217;m still calling directly is site.text, which wraps the wordpress __ function for text localization. This is intentional as I&#8217;m planning to replace it at a later stage. Most plugins and systems which are used to support localization depend scan the theme files for uses of that function, and wrapping it in this way can prevent them from working properly. I&#8217;ll probably make some sort of localization file for the theme which sets up the localized values, but it&#8217;s not something I&#8217;ll be looking at right now.</p>
<p>Next up: Styling the template</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">577</post-id>	</item>
		<item>
		<title>Templating a WordPress theme with Twig</title>
		<link>https://karlagius.com/2013/04/06/templating-a-wordpress-theme-with-twig/</link>
					<comments>https://karlagius.com/2013/04/06/templating-a-wordpress-theme-with-twig/#comments</comments>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Fri, 05 Apr 2013 23:00:57 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">http://karlagius.com/?p=568</guid>

					<description><![CDATA[Well, that wasn&#8217;t as painful as I thought it would be. Some googling and a couple of experiments went a long way, and now I have a partial, unstyled, Twig-based theme happily running on WordPress. Twig is a templating engine for php. It has more than enough features to get me going, setting it up &#8230; <p class="link-more"><a href="https://karlagius.com/2013/04/06/templating-a-wordpress-theme-with-twig/" class="more-link">Continue reading<span class="screen-reader-text"> "Templating a WordPress theme with Twig"</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>Well, that wasn&#8217;t as painful as I thought it would be. Some googling and a couple of experiments went a long way, and now I have a partial, unstyled, Twig-based theme happily running on WordPress.</p>
<p><a title="Twig homepage" href="http://twig.sensiolabs.org/" target="_blank" rel="noopener">Twig </a>is a templating engine for php. It has more than enough features to get me going, setting it up is as easy as falling off a tree, and I haven&#8217;t used it much, which makes it a good candidate for me.<span id="more-568"></span></p>
<h3>Making WordPress call Twig</h3>
<p>Once we&#8217;ve downloaded Twig and put it somewhere convenient (in my case, in my theme folder &#8211; I&#8217;d like to move it out eventually, but it can stay there while I work it out), we need to tell WordPress to initialize the Twig engine. Darko Goles&#8217; blog post, <a href="http://inchoo.net/wordpress/twig-with-wordpress-part1/" target="_blank" rel="noopener">TWIG with WordPress part 1</a>, covers this admirably. In his post, he&#8217;s initializing the engine through a plugin, which I wanted to avoid as I didn&#8217;t want a theme to depend on a plugin. Luckily the mechanism is the same, since the hooking mechanism in WordPress papers over these issues &#8211; we can initialize from a theme exactly like we do from a plugin, by specifying the actions in a functions.php file:</p>
<pre>&lt;?php 
    // theme functions.php
    require_once dirname(__FILE__).'/twig.helper.php';
?&gt;</pre>
<pre>&lt;?php
    // twig.helper.php
    require_once dirname(__FILE__).'/lib/Twig/Autoloader.php';

    class Twig_Helper {
	public static function register() {
	    ini_set('unserialize_callback_func', 
                'spl_autoload_call');
            spl_autoload_register(array(new self, 'autoload'));
	}

	public static function autoload($class) {

            if (0 !== strpos($class, 'Wp_TwigEngine'))
	        return;

            if (file_exists($file = dirname(__FILE__) . '/../' 
                . str_replace(array('_', "\0"), array('/', ''), 
                $class) . '.php')) {
		     echo($file);
		     exit;
                     require $file;
	    }
	}

	...
	...
    }

    ...

    function autoload_twig() {
        Twig_Autoloader::register();
	Twig_Helper::register();
    }

    add_action('init', 'autoload_twig');
?&gt;</pre>
<p>The above is copied nearly verbatim from the post I mentioned above, and works fine. It registers twig and loads all the classes it needs to work. I put this in a separate file and referenced it from functions.php so it wouldn&#8217;t get mixed in with any theming functions I might need to add later.</p>
<h3>Getting to the data</h3>
<p>Now we&#8217;re able to load templates, but we still need to be able to pass data to them. The solution came, again, from Mr. Goles&#8217; blog, this time from <a href="http://inchoo.net/wordpress/twig-wordpress-part2/" target="_blank" rel="noopener">TWIG with WordPress part 2</a> &#8211; we pass a proxy object to the template, which it can then use to call functions on. Again, I used the code from this post almost as provided, except that I used the same TwigHelper class to provide this proxy. I also added another method, text, to wrap the __(string, key) function used for localization.</p>
<h3>Writing templates</h3>
<p>The template file looks like this:</p>
<pre>{% extends "master.html.twig" %}
{% block pageContent %}
	&lt;section id="content" role="main"&gt;
		{% for post in posts %}
			{% set format = site.get_post_format() %}
			{% include format 
                               ? "content-" ~ format ~ ".html.twig" 
                               : "content.html.twig" %}
		{% else %} 
			{% include "content-none.html.twig" %}
		{% endfor %&gt;	
	&lt;/section&gt;
{% endblock %}</pre>
<p>Not much of it, is there? In reality, that&#8217;s because most of the layout is defined in master.html.twig, which we&#8217;re extending in the first line. This file has placeholders for the pageContent block which is being filled up here, and the rest of the page around it. I&#8217;ve also delegated the no-content section to its own file. The snippet above is the equivalent of:</p>
<pre>	&lt;div id="content" role="main"&gt;
	    &lt;?php if ( have_posts() ) : ?&gt;	
	        &lt;?php while ( have_posts() ) : the_post(); ?&gt;
	            &lt;?php get_template_part('content', 
                                 get_post_format() ); ?&gt;
	        &lt;?php endwhile; ?&gt;
	&lt;?php else : ?&gt;
		&lt;?!-- stuff to show if there's no content --&gt;
	&lt;?php endif; ?&gt;
	&lt;/div&gt;</pre>
<p>It may not be significantly shorter, but it&#8217;s a damn sight easier to read. The readability and size gains are much greater when you have more markup, but I don&#8217;t want this to be a templating post.</p>
<h3>While&#8230; hang on, where&#8217;s while?</h3>
<p>As I was working on the loop, I realized that Twig doesn&#8217;t have a &#8220;while&#8221; control. This was a problem as WordPress is heavily dependent on The Loop. This can be worked around, as demonstrated in <a href="http://www.craftitonline.com/2011/10/closured-iterator-the-secret-while-twig-tag/" target="_blank" rel="noopener">this blog post by Luis Cordova</a>, by making an iterator and using it in a for loop. It&#8217;s a good enough solution and the template doesn&#8217;t look bad.</p>
<h3>Current status</h3>
<p>At this point I have a barely functional them (still need to port over a lot of stuff) but getting here took a lot less time than I thought it would. My next step will probably be to port over as much of the old theme as I can, and then work from there.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://karlagius.com/2013/04/06/templating-a-wordpress-theme-with-twig/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">568</post-id>	</item>
		<item>
		<title>The blog refactoring of 2013</title>
		<link>https://karlagius.com/2013/04/05/the-blog-refactoring-of-2013/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Thu, 04 Apr 2013 22:54:47 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">http://karlagius.com/?p=562</guid>

					<description><![CDATA[While I was writing the last few posts, the messiness of the blog&#8217;s code base started grating. A while back I&#8217;d rebuilt the template from scratch so I wouldn&#8217;t have pieces of page all over &#8211; I hate having elements opening in one file and closing in another &#8211; but even so, the structure of the scripts and styles &#8230; <p class="link-more"><a href="https://karlagius.com/2013/04/05/the-blog-refactoring-of-2013/" class="more-link">Continue reading<span class="screen-reader-text"> "The blog refactoring of 2013"</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>While I was writing the last few posts, the messiness of the blog&#8217;s code base started grating. A while back I&#8217;d rebuilt the template from scratch so I wouldn&#8217;t have pieces of page all over &#8211; I hate having elements opening in one file and closing in another &#8211; but even so, the structure of the scripts and styles isn&#8217;t all that great. Today I started reorganizing stuff so I can bring it up to shape with shiny new toys. And this time, I&#8217;ll try to do it in a more organized way; writing about it helps, as I have to get my thoughts in order to do that &#8211; and I can&#8217;t write text and code at the same time. The pauses will be handy.</p>
<p><span id="more-562"></span><span style="font-size: 10px; letter-spacing: 0.1em; line-height: 2.6em; text-transform: uppercase;">The Plan</span></p>
<blockquote><p>&#8220;Whut&#8217;s the plan, Rob?&#8221; said one of them.<br />
&#8220;OK lads, this is what we&#8217;ll do. As soon as we see somethin&#8217;, we&#8217;ll attack it. Right?&#8221;<br />
&#8211; Sir Terry Pratchett, &#8220;The Wee Free Men&#8221;</p></blockquote>
<p>Right now I have a few ideas and tools I want to experiment with, which will somehow get roped into this project.</p>
<p>On the scripting side, I want to organize all the loose scripts I have running around. Some of them will inevitably added by WordPress plugins &#8211; that can&#8217;t be helped, but I&#8217;d like to keep the internal stuff as tight as possible. <a href="http://requirejs.org/" target="_blank">Require.js</a> seems to be a good idea &#8211; might even be able to modularize some of the external scripts and load them through it.</p>
<p>For my own stuff I want to use <a href="http://coffeescript.org/" target="_blank">Coffeescript </a>as much as possible, so I get in as much practice as I can. The more I use it, the more I&#8217;m liking it.</p>
<p>The stylesheets will get redone in <a href="http://sass-lang.com/" target="_blank">Sass</a>, and compiled in <a href="http://compass-style.org/" target="_blank">Compass</a>. Again, it&#8217;s partly because it&#8217;s more efficient, and partly because I need the practice.</p>
<p>I also want the page to be a bit more fluid, so it can be read more easily on devices of different size. I&#8217;ve had a play around with <a href="http://twitter.github.com/bootstrap/" target="_blank">Bootstrap</a>, and that seems to do nicely, so in it goes.</p>
<p>The final item on this shopping list is really the first one I&#8217;m tackling right now. I&#8217;d really like to clean up the templates; right now it&#8217;s really just php code, but I&#8217;d much rather cut it up into templates of some kind. Some digging around here will be needed, but I&#8217;ll allocate a time limit of two or three evenings so I don&#8217;t get stuck on that, or wander off bored when my attention span catches up with me.</p>
<p>So far, I&#8217;ve set up a local Git repository, cobbled together a Node script to sort out the different apps I&#8217;ll be using (CoffeeScript compiler, Compass, and later on the Require.js optimizer) and gathered all the dependencies mentioned above. We&#8217;ll see how this goes.</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="aligncenter size-full wp-image-563" alt="update-blog" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2013/04/update-blog.jpg?resize=415%2C523&#038;ssl=1" width="415" height="523" /></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">562</post-id>	</item>
		<item>
		<title>Canvas Animation using interpolation</title>
		<link>https://karlagius.com/2013/04/04/canvas-animation-using-interpolation/</link>
		
		<dc:creator><![CDATA[Karl]]></dc:creator>
		<pubDate>Wed, 03 Apr 2013 22:14:28 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[user experience]]></category>
		<category><![CDATA[web]]></category>
		<guid isPermaLink="false">http://karlagius.com/?p=549</guid>

					<description><![CDATA[While drawing things on the canvas and scooting around them is nice, it gets old very fast. Instantaneously, if you're an end user (unless you're on a page for looking at things, in which case, no foul). On the other hand, there are far more efficient ways of rendering porn and/or amusing pictures of cats, so I'm going to go ahead and assume that we want to liven things up with some animation.]]></description>
										<content:encoded><![CDATA[<p>While <a title="Reading Tiled maps for Canvas" href="https://karlagius.com/2013/03/25/reading-tiled-maps-for-canvas/">drawing things on the canvas</a> and <a title="A 2d Viewport for Canvas" href="https://karlagius.com/2013/03/23/a-2d-viewport-for-canvas/">scooting around them</a> is nice, it gets old very fast. Instantaneously, if you&#8217;re an end user (unless you&#8217;re on a page for looking at things, in which case, no foul). On the other hand, there are far more efficient ways of rendering porn and/or amusing pictures of cats, so I&#8217;m going to go ahead and assume that we want to liven things up with some animation.</p>
<p><span id="more-549"></span></p>
<p><a href="https://karlagius.com/files/html5/examples/interpolation/" target="_blank">You can see a demo for this post here</a>.</p>
<p>There are two kinds of animation I&#8217;m interested in right now. The first kind, that we&#8217;re going to look at today, is moving things around the screen. The other kind, that I&#8217;m still working on (largely because I&#8217;m terrible at image editing) is sprite animation; I&#8217;ll post some more information about that as soon as I&#8217;ve finished something worth seeing.</p>
<p>Moving an object on the screen is as simple as updating its coordinates before redrawing it. That causes it to jump to a new position on screen, which is fantastic if you&#8217;re working on a game where the only means of locomotion is teleportation, but since most of us have to deal with rather more mundane activities, what we really want is for the object to cross the intervening space. We can achieve this by repeatedly updating the position of the object in small jumps, creating the illusion of movement.</p>
<p>Now, we know where the object is before it starts moving, and we know where we want it to end up, but how do we determine all the points in between? And how do we make sure it moves smoothly?</p>
<h3>Simple Interpolation</h3>
<p>Interpolators are a simple answer to both questions. Since we have two points, we can derive a line of travel; if we know the speed at which the object is supposed to travel, we can calculate where the object will be at any time after it started moving. This lets us bind the movement to a timer or a cycle which updates the position every so often.</p>
<p>Let&#8217;s say we have an object at 0,0, and we want it to go to 100,0 at 10 pixels per second. The line it&#8217;s going to travel is 100 pixels long in total, so it will take 10 seconds (distance/speed) to get to the end.</p>
<p>Let&#8217;s set it going and start a stopwatch.</p>
<p>Right at the start, when 0 seconds have elapsed, the distance travelled is 0.<br />
At 5 seconds, or 0.5 of the total time, distance travelled is 50.<br />
At 10 seconds, or 1 whole of the total time, the distance travelled is 100.</p>
<p>In other words, the distance travelled is</p>
<pre>([elapsed time] / [total time]) * [full distance]</pre>
<p>We can also calculate the x and y coordinates from the ratio of elapsed time to total time:</p>
<pre>x = (x2 - x1) * ([elapsed time] / [total time])
y = (y2 - y1) * ([elapsed time] / [total time])</pre>
<p>Where x1 and y1 are the coordinates of the starting point, and x2 and y2 are the coordinates of the destination. Plugging the examples above here:</p>
<p>At 0 seconds:</p>
<pre>x = (100 - 0) * (0/10) = 100 * 0 = 0
y = (0 - 0) * (0/10) = 0 * 0 = 0</pre>
<p>At 5 seconds:</p>
<pre>x = (100 - 0) * (5/10) = 100 * 0.5 = 50
y = (0 - 0) * (0/10) = 0 * 0 = 0</pre>
<p>At 10 seconds:</p>
<pre>x = (100 - 0) * (10/10) = 100 * 1 = 100
y = (0 - 0) * (0/10) = 0 * 0 = 0</pre>
<h3>Easing</h3>
<p>The linear interpolator above does it&#8217;s job well enough, but once you see it in action, you&#8217;ll notice that the rate of movement is perfectly constant across the whole length of the movement. In most cases in the physical world (you know, the one with smells and stuff) when something starts moving it will start off slow, pick up momentum, and eventually slow down to a stop.</p>
<p>Unless you&#8217;re in space, in which case you&#8217;ll just keep hurtling through the void until you crash into something or get sucked into a black hole.</p>
<p>Luckily, modelling different types of acceleration and deceleration isn&#8217;t that tricky (&#8220;it just takes a lot of tweaking or some good math skills&#8221;, he didn&#8217;t say). The interpolation above is defines a line (hence the linear); we can define a basic system of easing by changing it so that it defines a curve.</p>
<p>Suppose you plot the linear interpolation out on a graph: the distance travelled is a straight line based on the elapsed time (blue), and the speed is constant throughout (red, not to scale):</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="aligncenter size-full wp-image-552" alt="linear" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2013/04/linear.png?resize=150%2C150&#038;ssl=1" width="150" height="150" /></p>
<p>It&#8217;s pretty straightforward; y = x stuff. Now let&#8217;s say we change it a little so that y = x<sup>2 </sup>and we have ourselves a nice ease-in:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="aligncenter size-full wp-image-551" alt="ease-in" src="https://i0.wp.com/karlagius.com/wp-content/uploads/2013/04/ease-in.png?resize=150%2C150&#038;ssl=1" width="150" height="150" /></p>
<p>That gives us a nice curve, which means that the movement will start off nice and slow, and pick up speed until the end of the path. Perfect if you ever need to animate someone running face-first into a wall.</p>
<p>As you can see, tweaking the interpolator a little gives you control over the speed and acceleration of your moving objects. I&#8217;ve added ease-out and ease-in-out interpolators in <a href="https://karlagius.com/files/html5/examples/interpolation/" target="_blank">the example</a>, both based on the square of the time coefficient, but there&#8217;s really a cubic buttload of different functions you could use if that&#8217;s the kind of thing you dig.</p>
<h3>Other stuff you can animate</h3>
<p>Although I wrote this for practice with canvas, there are a bunch of different areas you could apply it to besides positioning. For example, you could use an interpolation to smoothly change the opacity or colour of an element; there&#8217;s nothing that ties this concept to the canvas element. If you&#8217;re looking to do this though, you might be better served looking into css3 transitions or jQuery animation.</p>
<p>No, seriously. Don&#8217;t reinvent the wheel.</p>
<div class="alert"><strong>Moar JavaScript?</strong> Check out <a href="https://karlagius.com/2014/09/15/the-little-book-of-javascript/" title="The Little Book of JavaScript">The Little Book of JavaScript</a>!</div>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">549</post-id>	</item>
	</channel>
</rss>
