<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/make-a-sculpture-in-lego-from-a-photo-with-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2018/04/lego-sculpture.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>The entrance to our office in Redmond in is adorned with this sculpture of our department logo, rendered in LEGO:</p>
<blockquote class="twitter-tweet" data-lang="en">
<p dir="ltr" lang="en">We had fun with LEGO bricks at work this week. APEX is our internal team name, this was fun. Oh and we're hiring for all roles in Azure! <a rel="nofollow" href="https://t.co/VlNNaTexA5" target="_blank">pic.twitter.com/VlNNaTexA5</a></p>
<p>— Jeff Sandquist (@jeffsand) <a rel="nofollow" href="https://twitter.com/jeffsand/status/847499483071959040?ref_src=twsrc%5Etfw" target="_blank">March 30, 2017</a></p></blockquote>
<p></p>
<p>Our team, the <a rel="nofollow" href="https://developer.microsoft.com/en-us/advocates/" target="_blank">Cloud Developer Advocates</a>, has a <a rel="nofollow" href="https://github.com/ashleymcnamara/Developer-Advocate-Bit/blob/master/BitDevAdvocate.png" target="_blank">logo</a> as well, created by the multitalented <a rel="nofollow" href="https://developer.microsoft.com/en-us/advocates/ashley-mcnamara" target="_blank">Ashley Macnamara</a>. (The mascot's name is Bit: he's a raccoon because, like developers, <a rel="nofollow" href="https://github.com/ashleymcnamara/Developer-Advocate-Bit" target="_blank">he's into everything</a>.) It would be nice to have a LEGO rendition of Bit for the wall as well, but converting an image into LEGO bricks isn't easy … until now.</p>
<p>This <a rel="nofollow" href="http://www.ryantimpe.com/2018/04/23/lego-mosaic1/" target="_blank">R script by Ryan Timpe</a> provides everything you need render an image in LEGO. It will downscale the image to a size that meets your bricks budget, convert the colors to those available as LEGO bricks, and divide the image up into LEGO-sized pieces, ready to lay out on a flat tray. The script is super easy to use: just source a file of <a rel="nofollow" href="https://github.com/ryantimpe/LEGOMosaics/blob/master/0_Functions.R" target="_blank">utility functions</a> and then:</p>
<p></p>
<p>(You can also use <a rel="nofollow" href="https://www.rdocumentation.org/packages/png/versions/0.1-7/topics/readPNG?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">readJPEG</a> to read in JPG images; I just loaded in the <a rel="nofollow" href="https://www.rdocumentation.org/packages/png/versions/0.1-7?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">png package</a> and used <a rel="nofollow" href="https://www.rdocumentation.org/packages/png/versions/0.1-7/topics/readPNG?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">readPNG</a> which works just as well.) Here's what the output looks like. (Click to see the original, for comparison.)</p>
<p><a rel="nofollow" href="https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/azure.png" target="_blank"><img border="0" alt="Bit-azure-64" title="Bit-azure-64" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b0224df2eeb43200b-800wi"></a></p>
<p>The script also provides a shopping list of the bricks you need by color and size: this particular project will require 1842 LEGO bricks in 19 different colors to create the 48×48 image. It will even provide a series of step-by-step instructions showing how the project will look in various stages of completion:</p>
<p><a rel="nofollow" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b0223c8473579200c-pi" target="_blank"><img border="0" alt="Bit-instr-64" title="Bit-instr-64" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b0223c8473579200c-800wi"></a><br>The R script is <a rel="nofollow" href="https://github.com/ryantimpe/LEGOMosaics" target="_blank">available on GitHub</a>, here, and works with any recent version of R and with up-to-date <a rel="nofollow" href="http://tidyverse.org/" target="_blank">tidyverse</a> installation. (I used R 3.5.0.) You can find a complete walkthrough of using the scripts in the blog post at the link below.</p>
<p>Ryan Timple: <a rel="nofollow" href="http://www.ryantimpe.com/2018/04/23/lego-mosaic1/" target="_blank">How To: LEGO mosaics from photos using R &amp; the tidyverse</a></p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2018/04/lego-sculpture.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/XA_nNsPEakI" height="1"></a></div>