Merge pull request #12 from ryantimpe/geom_brick

Major updates to brickr. Not yet release-ready, but almost there!
This commit is contained in:
Ryan Timpe
2019-08-20 14:32:50 -04:00
committed by GitHub
213 changed files with 13843 additions and 1578 deletions
+4
View File
@@ -1,3 +1,7 @@
^LICENSE\.md$
^LEGOMosaics\.Rproj$
^\.Rproj\.user$
admin_color_tools
^_pkgdown\.yml$
^docs$
^pkgdown$
+4
View File
@@ -62,3 +62,7 @@ ryanmovie.mp4
ryanweb.mp4
forestmovie.mp4
forestweb.mp4
test_*
brickr.Rproj
brickr_colors.png
inst/doc
Binary file not shown.
-128
View File
@@ -1,128 +0,0 @@
LEGONo,Color,Sample,R,G,B,c_Palette2016,c_Transparent,c_Glow,c_Metallic,t_BW,t_Classic,t_Friends,w_weight,w_Classic
1,White,,242,243,242,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,,1,1.5
5,Brick yellow,,215,197,153,TRUE,FALSE,FALSE,FALSE,,,,2,
18,Nougat,,204,142,104,TRUE,FALSE,FALSE,FALSE,,,,2,
21,Bright red,,196,40,27,TRUE,FALSE,FALSE,FALSE,,TRUE,,2,2
23,Bright blue,,13,105,171,TRUE,FALSE,FALSE,FALSE,,TRUE,,2,2
24,Bright yellow,,245,205,47,TRUE,FALSE,FALSE,FALSE,,TRUE,,2,2
26,Black,,27,42,52,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,,1,1.5
28,Dark green,,40,127,70,TRUE,FALSE,FALSE,FALSE,,,,1.5,
37,Bright green,,75,151,74,TRUE,FALSE,FALSE,FALSE,,TRUE,,1.5,1.5
38,Dark orange,,160,95,52,TRUE,FALSE,FALSE,FALSE,,TRUE,,1.5,1
40,Transparent,,236,236,236,TRUE,TRUE,FALSE,FALSE,,,,1,
41,Tr. Red,,205,84,75,TRUE,TRUE,FALSE,FALSE,,,,1,
42,Tr. Lg blue,,193,223,240,TRUE,TRUE,FALSE,FALSE,,,,1,
43,Tr. Blue,,123,182,232,TRUE,TRUE,FALSE,FALSE,,,,1,
44,Tr. Yellow,,247,241,141,TRUE,TRUE,FALSE,FALSE,,,,1,
47,Tr. Flu. Reddish orange,,217,133,108,TRUE,TRUE,FALSE,FALSE,,,,1,
48,Tr. Green,,132,182,141,TRUE,TRUE,FALSE,FALSE,,,,1,
49,Tr. Flu. Green,,248,241,132,TRUE,TRUE,FALSE,FALSE,,,,1,
102,Medium blue,,110,153,201,TRUE,FALSE,FALSE,FALSE,,,,2,
106,Bright orange,,218,133,64,TRUE,FALSE,FALSE,FALSE,,TRUE,,2,1
111,Tr. Brown,,191,183,177,TRUE,TRUE,FALSE,FALSE,,,,1,
113,Tr. Medi. reddish violet,,228,173,200,TRUE,TRUE,FALSE,FALSE,,,,1,
113,Tr. Medium Violet,,253,142,207,TRUE,TRUE,FALSE,FALSE,,,TRUE,1,
119,Br. yellowish green,,164,189,70,TRUE,FALSE,FALSE,FALSE,,TRUE,,1,1
124,Bright reddish violet,,146,57,120,TRUE,FALSE,FALSE,FALSE,,,TRUE,1,
126,Tr. Bright bluish violet,,165,165,203,TRUE,TRUE,FALSE,FALSE,,,TRUE,1,
135,Sand blue,,116,134,156,TRUE,FALSE,FALSE,FALSE,,,,1.5,
138,Sand yellow,,149,138,115,TRUE,FALSE,FALSE,FALSE,,,,1.5,
140,Earth blue,,32,58,86,TRUE,FALSE,FALSE,FALSE,,,,1.5,
141,Earth green,,39,70,44,TRUE,FALSE,FALSE,FALSE,,,,1.5,
143,Tr. Flu. Blue,,207,226,247,TRUE,TRUE,FALSE,FALSE,,,TRUE,1.5,
151,Sand green,,120,144,129,TRUE,FALSE,FALSE,FALSE,,,,2,
154,Dark red,,123,46,47,TRUE,FALSE,FALSE,FALSE,,,,2,
191,Flame yellowish orange,,232,171,45,TRUE,FALSE,FALSE,FALSE,,,TRUE,2,
192,Reddish brown,,105,64,39,TRUE,FALSE,FALSE,FALSE,,,,2,
194,Medium stone grey,,163,162,164,TRUE,FALSE,FALSE,FALSE,TRUE,,,1,
199,Dark stone grey,,99,95,97,TRUE,FALSE,FALSE,FALSE,TRUE,,,1,
212,Light royal blue,,159,195,233,TRUE,FALSE,FALSE,FALSE,,,TRUE,1,
221,Bright purple,,205,98,152,TRUE,FALSE,FALSE,FALSE,,,TRUE,1.5,
222,Light purple,,228,173,200,TRUE,FALSE,FALSE,FALSE,,,TRUE,1.5,
226,Cool yellow,,253,234,140,TRUE,FALSE,FALSE,FALSE,,,TRUE,1.5,
268,Medium lilac,,51,0,114,TRUE,FALSE,FALSE,FALSE,,,,1.5,
283,Light nougat,,252,200,155,TRUE,FALSE,FALSE,FALSE,,,,1.5,
297,Warm gold,,170,127,46,TRUE,FALSE,FALSE,TRUE,,,,1,
308,Dark brown,,49,38,29,TRUE,FALSE,FALSE,FALSE,,,,1,
311,Tr. Bright Green,,175,210,70,TRUE,TRUE,FALSE,FALSE,,,,1,
312,Medium nougat,,170,125,85,TRUE,FALSE,FALSE,FALSE,,,,1,
315,Silver Metallic,,140,140,140,TRUE,FALSE,FALSE,TRUE,,,,1,
316,Titanium Metallic,,62,60,57,TRUE,FALSE,FALSE,TRUE,,,,1,
321,Dark azur,,51,55,198,TRUE,FALSE,FALSE,FALSE,,,,1,
322,Medium azur,,113,197,232,TRUE,FALSE,FALSE,FALSE,,,TRUE,1,
323,Aqua,,185,220,210,TRUE,FALSE,FALSE,FALSE,,,,1,
324,Med. lavendar,,160,94,181,TRUE,FALSE,FALSE,FALSE,,,,1,
325,Lavendar,,202,162,221,TRUE,FALSE,FALSE,FALSE,,,,1,
326,Spring yellowish green,,212,235,142,TRUE,FALSE,FALSE,FALSE,,,TRUE,1,
329,White glow,,242,243,242,TRUE,FALSE,TRUE,FALSE,,,,1,
330,Olive green,,115,123,76,TRUE,FALSE,FALSE,FALSE,,,,1,
2,Grey,,161,165,162,FALSE,FALSE,FALSE,FALSE,,,,1,
3,Light yellow,,249,233,153,FALSE,FALSE,FALSE,FALSE,,,,1,
6,Light green,,194,218,184,FALSE,FALSE,FALSE,FALSE,,,,1,
9,Light reddish violet,,232,186,199,FALSE,FALSE,FALSE,FALSE,,,,1,
12,Light orange brown,,203,132,66,FALSE,FALSE,FALSE,FALSE,,,,1,
22,Med. reddish violet,,196,112,160,FALSE,FALSE,FALSE,FALSE,,,,1,
25,Earth orange,,98,71,50,FALSE,FALSE,FALSE,FALSE,,,,1,
27,Dark grey,,109,110,108,FALSE,FALSE,FALSE,FALSE,,,,1,
29,Medium green,,161,196,139,FALSE,FALSE,FALSE,FALSE,,,,1,
36,Lig. Yellowich orange,,243,207,155,FALSE,FALSE,FALSE,FALSE,,,,1,
39,Light bluish violet,,193,202,222,FALSE,FALSE,FALSE,FALSE,,,,1,
45,Light blue,,180,210,227,FALSE,FALSE,FALSE,FALSE,,,,1,
50,Phosph. White,,236,232,222,FALSE,FALSE,FALSE,FALSE,,,,1,
100,Light red,,238,196,182,FALSE,FALSE,FALSE,FALSE,,,,1,
101,Medium red,,218,134,121,FALSE,FALSE,FALSE,FALSE,,,,1,
103,Light grey,,199,193,183,FALSE,FALSE,FALSE,FALSE,,,,1,
104,Bright violet,,107,50,123,FALSE,FALSE,FALSE,FALSE,,,,1,
105,Br. yellowish orange,,226,155,63,FALSE,FALSE,FALSE,FALSE,,,,1,
107,Bright bluish green,,0,143,155,FALSE,FALSE,FALSE,FALSE,,,,1,
108,Earth yellow,,104,92,67,FALSE,FALSE,FALSE,FALSE,,,,1,
110,Bright bluish violet,,67,84,147,FALSE,FALSE,FALSE,FALSE,,,,1,
112,Medium bluish violet,,104,116,172,FALSE,FALSE,FALSE,FALSE,,,,1,
115,Med. yellowish green,,199,210,60,FALSE,FALSE,FALSE,FALSE,,,,1,
116,Med. bluish green,,85,165,175,FALSE,FALSE,FALSE,FALSE,,,,1,
118,Light bluish green,,183,215,213,FALSE,FALSE,FALSE,FALSE,,,,1,
120,Lig. yellowish green,,217,228,167,FALSE,FALSE,FALSE,FALSE,,,,1,
121,Med. yellowish orange,,231,172,88,FALSE,FALSE,FALSE,FALSE,,,,1,
123,Br. reddish orange,,211,111,76,FALSE,FALSE,FALSE,FALSE,,,,1,
125,Light orange,,234,184,145,FALSE,FALSE,FALSE,FALSE,,,,1,
127,Gold,,220,188,129,FALSE,FALSE,FALSE,FALSE,,,,1,
128,Dark nougat,,174,122,89,FALSE,FALSE,FALSE,FALSE,,,,1,
131,Silver,,156,163,168,FALSE,FALSE,FALSE,FALSE,,,,1,
133,Neon orange,,213,115,61,FALSE,FALSE,FALSE,FALSE,,,,1,
134,Neon green,,216,221,86,FALSE,FALSE,FALSE,FALSE,,,,1,
136,Sand violet,,135,124,144,FALSE,FALSE,FALSE,FALSE,,,,1,
137,Medium orange,,224,152,100,FALSE,FALSE,FALSE,FALSE,,,,1,
145,Sand blue metallic,,121,136,161,FALSE,FALSE,FALSE,FALSE,,,,1,
146,Sand violet metallic,,149,142,163,FALSE,FALSE,FALSE,FALSE,,,,1,
147,Sand yellow metallic,,147,135,103,FALSE,FALSE,FALSE,FALSE,,,,1,
148,Dark grey metallic,,87,88,87,FALSE,FALSE,FALSE,FALSE,,,,1,
149,Black metallic,,22,29,50,FALSE,FALSE,FALSE,FALSE,,,,1,
150,Light grey metallic,,171,173,172,FALSE,FALSE,FALSE,FALSE,,,,1,
153,Sand red,,149,121,118,FALSE,FALSE,FALSE,FALSE,,,,1,
157,Tr. Flu. Yellow,,255,246,123,FALSE,FALSE,FALSE,FALSE,,,,1,
158,Tr. Flu. Red,,225,164,194,FALSE,FALSE,FALSE,FALSE,,,,1,
168,Gun metallic,,117,108,98,FALSE,FALSE,FALSE,FALSE,,,,1,
176,Red flip/flop,,151,105,91,FALSE,FALSE,FALSE,FALSE,,,,1,
178,Yellow flip/flop,,180,132,85,FALSE,FALSE,FALSE,FALSE,,,,1,
179,Silver flip/flop,,137,135,136,FALSE,FALSE,FALSE,FALSE,,,,1,
180,Curry,,215,169,75,FALSE,FALSE,FALSE,FALSE,,,,1,
190,Fire Yellow,,249,214,46,FALSE,FALSE,FALSE,FALSE,,,,1,
193,Flame reddish orange,,207,96,36,FALSE,FALSE,FALSE,FALSE,,,,1,
195,Royal blue,,70,103,164,FALSE,FALSE,FALSE,FALSE,,,,1,
196,Dark Royal blue,,35,71,139,FALSE,FALSE,FALSE,FALSE,,,,1,
198,Bright reddish lilac,,142,66,133,FALSE,FALSE,FALSE,FALSE,,,,1,
200,Lemon metalic,,130,138,93,FALSE,FALSE,FALSE,FALSE,,,,1,
208,Light stone grey,,229,228,222,FALSE,FALSE,FALSE,FALSE,,,,1,
209,Dark Curry,,176,142,68,FALSE,FALSE,FALSE,FALSE,,,,1,
210,Faded green,,112,149,120,FALSE,FALSE,FALSE,FALSE,,,,1,
211,Turquoise,,121,181,181,FALSE,FALSE,FALSE,FALSE,,,,1,
213,Medium Royal blue,,108,129,183,FALSE,FALSE,FALSE,FALSE,,,,1,
216,Rust,,143,76,42,FALSE,FALSE,FALSE,FALSE,,,,1,
217,Brown,,124,92,69,FALSE,FALSE,FALSE,FALSE,,,,1,
218,Reddish lilac,,150,112,159,FALSE,FALSE,FALSE,FALSE,,,,1,
219,Lilac,,107,98,155,FALSE,FALSE,FALSE,FALSE,,,,1,
220,Light lilac,,167,169,206,FALSE,FALSE,FALSE,FALSE,,,,1,
223,Light pink,,220,144,149,FALSE,FALSE,FALSE,FALSE,,,,1,
224,Light brick yellow,,240,213,160,FALSE,FALSE,FALSE,FALSE,,,,1,
225,Warm yellowish orange,,235,184,127,FALSE,FALSE,FALSE,FALSE,,,,1,
232,Dove blue,,125,187,221,FALSE,FALSE,FALSE,FALSE,,,,1,
1 LEGONo Color Sample R G B c_Palette2016 c_Transparent c_Glow c_Metallic t_BW t_Classic t_Friends w_weight w_Classic
2 1 White 242 243 242 TRUE FALSE FALSE FALSE TRUE TRUE 1 1.5
3 5 Brick yellow 215 197 153 TRUE FALSE FALSE FALSE 2
4 18 Nougat 204 142 104 TRUE FALSE FALSE FALSE 2
5 21 Bright red 196 40 27 TRUE FALSE FALSE FALSE TRUE 2 2
6 23 Bright blue 13 105 171 TRUE FALSE FALSE FALSE TRUE 2 2
7 24 Bright yellow 245 205 47 TRUE FALSE FALSE FALSE TRUE 2 2
8 26 Black 27 42 52 TRUE FALSE FALSE FALSE TRUE TRUE 1 1.5
9 28 Dark green 40 127 70 TRUE FALSE FALSE FALSE 1.5
10 37 Bright green 75 151 74 TRUE FALSE FALSE FALSE TRUE 1.5 1.5
11 38 Dark orange 160 95 52 TRUE FALSE FALSE FALSE TRUE 1.5 1
12 40 Transparent 236 236 236 TRUE TRUE FALSE FALSE 1
13 41 Tr. Red 205 84 75 TRUE TRUE FALSE FALSE 1
14 42 Tr. Lg blue 193 223 240 TRUE TRUE FALSE FALSE 1
15 43 Tr. Blue 123 182 232 TRUE TRUE FALSE FALSE 1
16 44 Tr. Yellow 247 241 141 TRUE TRUE FALSE FALSE 1
17 47 Tr. Flu. Reddish orange 217 133 108 TRUE TRUE FALSE FALSE 1
18 48 Tr. Green 132 182 141 TRUE TRUE FALSE FALSE 1
19 49 Tr. Flu. Green 248 241 132 TRUE TRUE FALSE FALSE 1
20 102 Medium blue 110 153 201 TRUE FALSE FALSE FALSE 2
21 106 Bright orange 218 133 64 TRUE FALSE FALSE FALSE TRUE 2 1
22 111 Tr. Brown 191 183 177 TRUE TRUE FALSE FALSE 1
23 113 Tr. Medi. reddish violet 228 173 200 TRUE TRUE FALSE FALSE 1
24 113 Tr. Medium Violet 253 142 207 TRUE TRUE FALSE FALSE TRUE 1
25 119 Br. yellowish green 164 189 70 TRUE FALSE FALSE FALSE TRUE 1 1
26 124 Bright reddish violet 146 57 120 TRUE FALSE FALSE FALSE TRUE 1
27 126 Tr. Bright bluish violet 165 165 203 TRUE TRUE FALSE FALSE TRUE 1
28 135 Sand blue 116 134 156 TRUE FALSE FALSE FALSE 1.5
29 138 Sand yellow 149 138 115 TRUE FALSE FALSE FALSE 1.5
30 140 Earth blue 32 58 86 TRUE FALSE FALSE FALSE 1.5
31 141 Earth green 39 70 44 TRUE FALSE FALSE FALSE 1.5
32 143 Tr. Flu. Blue 207 226 247 TRUE TRUE FALSE FALSE TRUE 1.5
33 151 Sand green 120 144 129 TRUE FALSE FALSE FALSE 2
34 154 Dark red 123 46 47 TRUE FALSE FALSE FALSE 2
35 191 Flame yellowish orange 232 171 45 TRUE FALSE FALSE FALSE TRUE 2
36 192 Reddish brown 105 64 39 TRUE FALSE FALSE FALSE 2
37 194 Medium stone grey 163 162 164 TRUE FALSE FALSE FALSE TRUE 1
38 199 Dark stone grey 99 95 97 TRUE FALSE FALSE FALSE TRUE 1
39 212 Light royal blue 159 195 233 TRUE FALSE FALSE FALSE TRUE 1
40 221 Bright purple 205 98 152 TRUE FALSE FALSE FALSE TRUE 1.5
41 222 Light purple 228 173 200 TRUE FALSE FALSE FALSE TRUE 1.5
42 226 Cool yellow 253 234 140 TRUE FALSE FALSE FALSE TRUE 1.5
43 268 Medium lilac 51 0 114 TRUE FALSE FALSE FALSE 1.5
44 283 Light nougat 252 200 155 TRUE FALSE FALSE FALSE 1.5
45 297 Warm gold 170 127 46 TRUE FALSE FALSE TRUE 1
46 308 Dark brown 49 38 29 TRUE FALSE FALSE FALSE 1
47 311 Tr. Bright Green 175 210 70 TRUE TRUE FALSE FALSE 1
48 312 Medium nougat 170 125 85 TRUE FALSE FALSE FALSE 1
49 315 Silver Metallic 140 140 140 TRUE FALSE FALSE TRUE 1
50 316 Titanium Metallic 62 60 57 TRUE FALSE FALSE TRUE 1
51 321 Dark azur 51 55 198 TRUE FALSE FALSE FALSE 1
52 322 Medium azur 113 197 232 TRUE FALSE FALSE FALSE TRUE 1
53 323 Aqua 185 220 210 TRUE FALSE FALSE FALSE 1
54 324 Med. lavendar 160 94 181 TRUE FALSE FALSE FALSE 1
55 325 Lavendar 202 162 221 TRUE FALSE FALSE FALSE 1
56 326 Spring yellowish green 212 235 142 TRUE FALSE FALSE FALSE TRUE 1
57 329 White glow 242 243 242 TRUE FALSE TRUE FALSE 1
58 330 Olive green 115 123 76 TRUE FALSE FALSE FALSE 1
59 2 Grey 161 165 162 FALSE FALSE FALSE FALSE 1
60 3 Light yellow 249 233 153 FALSE FALSE FALSE FALSE 1
61 6 Light green 194 218 184 FALSE FALSE FALSE FALSE 1
62 9 Light reddish violet 232 186 199 FALSE FALSE FALSE FALSE 1
63 12 Light orange brown 203 132 66 FALSE FALSE FALSE FALSE 1
64 22 Med. reddish violet 196 112 160 FALSE FALSE FALSE FALSE 1
65 25 Earth orange 98 71 50 FALSE FALSE FALSE FALSE 1
66 27 Dark grey 109 110 108 FALSE FALSE FALSE FALSE 1
67 29 Medium green 161 196 139 FALSE FALSE FALSE FALSE 1
68 36 Lig. Yellowich orange 243 207 155 FALSE FALSE FALSE FALSE 1
69 39 Light bluish violet 193 202 222 FALSE FALSE FALSE FALSE 1
70 45 Light blue 180 210 227 FALSE FALSE FALSE FALSE 1
71 50 Phosph. White 236 232 222 FALSE FALSE FALSE FALSE 1
72 100 Light red 238 196 182 FALSE FALSE FALSE FALSE 1
73 101 Medium red 218 134 121 FALSE FALSE FALSE FALSE 1
74 103 Light grey 199 193 183 FALSE FALSE FALSE FALSE 1
75 104 Bright violet 107 50 123 FALSE FALSE FALSE FALSE 1
76 105 Br. yellowish orange 226 155 63 FALSE FALSE FALSE FALSE 1
77 107 Bright bluish green 0 143 155 FALSE FALSE FALSE FALSE 1
78 108 Earth yellow 104 92 67 FALSE FALSE FALSE FALSE 1
79 110 Bright bluish violet 67 84 147 FALSE FALSE FALSE FALSE 1
80 112 Medium bluish violet 104 116 172 FALSE FALSE FALSE FALSE 1
81 115 Med. yellowish green 199 210 60 FALSE FALSE FALSE FALSE 1
82 116 Med. bluish green 85 165 175 FALSE FALSE FALSE FALSE 1
83 118 Light bluish green 183 215 213 FALSE FALSE FALSE FALSE 1
84 120 Lig. yellowish green 217 228 167 FALSE FALSE FALSE FALSE 1
85 121 Med. yellowish orange 231 172 88 FALSE FALSE FALSE FALSE 1
86 123 Br. reddish orange 211 111 76 FALSE FALSE FALSE FALSE 1
87 125 Light orange 234 184 145 FALSE FALSE FALSE FALSE 1
88 127 Gold 220 188 129 FALSE FALSE FALSE FALSE 1
89 128 Dark nougat 174 122 89 FALSE FALSE FALSE FALSE 1
90 131 Silver 156 163 168 FALSE FALSE FALSE FALSE 1
91 133 Neon orange 213 115 61 FALSE FALSE FALSE FALSE 1
92 134 Neon green 216 221 86 FALSE FALSE FALSE FALSE 1
93 136 Sand violet 135 124 144 FALSE FALSE FALSE FALSE 1
94 137 Medium orange 224 152 100 FALSE FALSE FALSE FALSE 1
95 145 Sand blue metallic 121 136 161 FALSE FALSE FALSE FALSE 1
96 146 Sand violet metallic 149 142 163 FALSE FALSE FALSE FALSE 1
97 147 Sand yellow metallic 147 135 103 FALSE FALSE FALSE FALSE 1
98 148 Dark grey metallic 87 88 87 FALSE FALSE FALSE FALSE 1
99 149 Black metallic 22 29 50 FALSE FALSE FALSE FALSE 1
100 150 Light grey metallic 171 173 172 FALSE FALSE FALSE FALSE 1
101 153 Sand red 149 121 118 FALSE FALSE FALSE FALSE 1
102 157 Tr. Flu. Yellow 255 246 123 FALSE FALSE FALSE FALSE 1
103 158 Tr. Flu. Red 225 164 194 FALSE FALSE FALSE FALSE 1
104 168 Gun metallic 117 108 98 FALSE FALSE FALSE FALSE 1
105 176 Red flip/flop 151 105 91 FALSE FALSE FALSE FALSE 1
106 178 Yellow flip/flop 180 132 85 FALSE FALSE FALSE FALSE 1
107 179 Silver flip/flop 137 135 136 FALSE FALSE FALSE FALSE 1
108 180 Curry 215 169 75 FALSE FALSE FALSE FALSE 1
109 190 Fire Yellow 249 214 46 FALSE FALSE FALSE FALSE 1
110 193 Flame reddish orange 207 96 36 FALSE FALSE FALSE FALSE 1
111 195 Royal blue 70 103 164 FALSE FALSE FALSE FALSE 1
112 196 Dark Royal blue 35 71 139 FALSE FALSE FALSE FALSE 1
113 198 Bright reddish lilac 142 66 133 FALSE FALSE FALSE FALSE 1
114 200 Lemon metalic 130 138 93 FALSE FALSE FALSE FALSE 1
115 208 Light stone grey 229 228 222 FALSE FALSE FALSE FALSE 1
116 209 Dark Curry 176 142 68 FALSE FALSE FALSE FALSE 1
117 210 Faded green 112 149 120 FALSE FALSE FALSE FALSE 1
118 211 Turquoise 121 181 181 FALSE FALSE FALSE FALSE 1
119 213 Medium Royal blue 108 129 183 FALSE FALSE FALSE FALSE 1
120 216 Rust 143 76 42 FALSE FALSE FALSE FALSE 1
121 217 Brown 124 92 69 FALSE FALSE FALSE FALSE 1
122 218 Reddish lilac 150 112 159 FALSE FALSE FALSE FALSE 1
123 219 Lilac 107 98 155 FALSE FALSE FALSE FALSE 1
124 220 Light lilac 167 169 206 FALSE FALSE FALSE FALSE 1
125 223 Light pink 220 144 149 FALSE FALSE FALSE FALSE 1
126 224 Light brick yellow 240 213 160 FALSE FALSE FALSE FALSE 1
127 225 Warm yellowish orange 235 184 127 FALSE FALSE FALSE FALSE 1
128 232 Dove blue 125 187 221 FALSE FALSE FALSE FALSE 1
+33 -7
View File
@@ -1,25 +1,51 @@
Package: brickr
Title: Create Simulated LEGO Models from Images or Data Frames
Version: 0.0.0.9200
Title: Tools to emulate the LEGO® System in R
Version: 0.1.0.9014
Authors@R:
person(given = "Ryan",
family = "Timpe",
role = c("aut", "cre"),
email = "ryan.timpe@gmail.com")
Description: Generate digital LEGO-eque models using tidyverse functions. Convert image files into 2D and 3D mosaics, along with piece counts and instructions. Build 3D models using data frames with rayshader.
License: MIT + file LICENSE
Description:
Generate digital LEGO-esque models using tidyverse functions. Convert image files into 2D and 3D mosaics, along with piece counts and instructions.
Build 3D models using data frames with rayshader. Create brick bar charts with ggplot2.
License: GPL-3
Encoding: UTF-8
LazyData: true
Depends: R (>= 3.0.2)
Depends: R (>= 3.0.2), ggplot2
Imports:
magrittr,
dplyr,
tidyr,
purrr,
ggplot2
ggplot2,
scales,
farver
Suggests:
rayshader
rayshader,
knitr,
rmarkdown
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
URL: https://github.com/ryantimpe/brickr
BugReports: https://github.com/ryantimpe/brickr/issues
Collate:
'bricks-from-mosaic.R'
'bricks-from-rayshader.R'
'bricks-from-tables.R'
'build-bricks.R'
'build-instructions.R'
'build-mosaic.R'
'collect-bricks.R'
'colors-and-themes.R'
'coord-brick.R'
'draw-key.R'
'geom-brick-col.R'
'geom-brick-rect.R'
'image-to-mosaic.R'
'image-to-prep-mosaic.R'
'piece-count.R'
'scale-brick.R'
'theme-brick.R'
'utils-pipe.R'
VignetteBuilder: knitr
Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

+591 -17
View File
@@ -1,21 +1,595 @@
# MIT License
GNU General Public License
==========================
Copyright (c) 2019 Ryan Timpe
_Version 3, 29 June 2007_
_Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
## Preamble
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The GNU General Public License is a free, copyleft license for software and other
kinds of works.
The licenses for most software and other practical works are designed to take away
your freedom to share and change the works. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change all versions of a
program--to make sure it remains free software for all its users. We, the Free
Software Foundation, use the GNU General Public License for most of our software; it
applies also to any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General
Public Licenses are designed to make sure that you have the freedom to distribute
copies of free software (and charge for them if you wish), that you receive source
code or can get it if you want it, that you can change the software or use pieces of
it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or
asking you to surrender the rights. Therefore, you have certain responsibilities if
you distribute copies of the software, or if you modify it: responsibilities to
respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee,
you must pass on to the recipients the same freedoms that you received. You must make
sure that they, too, receive or can get the source code. And you must show them these
terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: **(1)** assert
copyright on the software, and **(2)** offer you this License giving you legal permission
to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is
no warranty for this free software. For both users' and authors' sake, the GPL
requires that modified versions be marked as changed, so that their problems will not
be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of
the software inside them, although the manufacturer can do so. This is fundamentally
incompatible with the aim of protecting users' freedom to change the software. The
systematic pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we have designed
this version of the GPL to prohibit the practice for those products. If such problems
arise substantially in other domains, we stand ready to extend this provision to
those domains in future versions of the GPL, as needed to protect the freedom of
users.
Finally, every program is threatened constantly by software patents. States should
not allow patents to restrict development and use of software on general-purpose
computers, but in those that do, we wish to avoid the special danger that patents
applied to a free program could make it effectively proprietary. To prevent this, the
GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
## TERMS AND CONDITIONS
### 0. Definitions
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this
License. Each licensee is addressed as “you”. “Licensees” and
“recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in
a fashion requiring copyright permission, other than the making of an exact copy. The
resulting work is called a “modified version” of the earlier work or a
work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on
the Program.
To “propagate” a work means to do anything with it that, without
permission, would make you directly or secondarily liable for infringement under
applicable copyright law, except executing it on a computer or modifying a private
copy. Propagation includes copying, distribution (with or without modification),
making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through a computer
network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the
extent that it includes a convenient and prominently visible feature that **(1)**
displays an appropriate copyright notice, and **(2)** tells the user that there is no
warranty for the work (except to the extent that warranties are provided), that
licensees may convey the work under this License, and how to view a copy of this
License. If the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
### 1. Source Code
The “source code” for a work means the preferred form of the work for
making modifications to it. “Object code” means any non-source form of a
work.
A “Standard Interface” means an interface that either is an official
standard defined by a recognized standards body, or, in the case of interfaces
specified for a particular programming language, one that is widely used among
developers working in that language.
The “System Libraries” of an executable work include anything, other than
the work as a whole, that **(a)** is included in the normal form of packaging a Major
Component, but which is not part of that Major Component, and **(b)** serves only to
enable use of the work with that Major Component, or to implement a Standard
Interface for which an implementation is available to the public in source code form.
A “Major Component”, in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system (if any) on which
the executable work runs, or a compiler used to produce the work, or an object code
interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the
source code needed to generate, install, and (for an executable work) run the object
code and to modify the work, including scripts to control those activities. However,
it does not include the work's System Libraries, or general-purpose tools or
generally available free programs which are used unmodified in performing those
activities but which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for the work, and
the source code for shared libraries and dynamically linked subprograms that the work
is specifically designed to require, such as by intimate data communication or
control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate
automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
### 2. Basic Permissions
All rights granted under this License are granted for the term of copyright on the
Program, and are irrevocable provided the stated conditions are met. This License
explicitly affirms your unlimited permission to run the unmodified Program. The
output from running a covered work is covered by this License only if the output,
given its content, constitutes a covered work. This License acknowledges your rights
of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without
conditions so long as your license otherwise remains in force. You may convey covered
works to others for the sole purpose of having them make modifications exclusively
for you, or provide you with facilities for running those works, provided that you
comply with the terms of this License in conveying all material for which you do not
control copyright. Those thus making or running the covered works for you must do so
exclusively on your behalf, under your direction and control, on terms that prohibit
them from making any copies of your copyrighted material outside their relationship
with you.
Conveying under any other circumstances is permitted solely under the conditions
stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law
No covered work shall be deemed part of an effective technological measure under any
applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of
technological measures to the extent such circumvention is effected by exercising
rights under this License with respect to the covered work, and you disclaim any
intention to limit operation or modification of the work as a means of enforcing,
against the work's users, your or third parties' legal rights to forbid circumvention
of technological measures.
### 4. Conveying Verbatim Copies
You may convey verbatim copies of the Program's source code as you receive it, in any
medium, provided that you conspicuously and appropriately publish on each copy an
appropriate copyright notice; keep intact all notices stating that this License and
any non-permissive terms added in accord with section 7 apply to the code; keep
intact all notices of the absence of any warranty; and give all recipients a copy of
this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer
support or warranty protection for a fee.
### 5. Conveying Modified Source Versions
You may convey a work based on the Program, or the modifications to produce it from
the Program, in the form of source code under the terms of section 4, provided that
you also meet all of these conditions:
* **a)** The work must carry prominent notices stating that you modified it, and giving a
relevant date.
* **b)** The work must carry prominent notices stating that it is released under this
License and any conditions added under section 7. This requirement modifies the
requirement in section 4 to “keep intact all notices”.
* **c)** You must license the entire work, as a whole, under this License to anyone who
comes into possession of a copy. This License will therefore apply, along with any
applicable section 7 additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no permission to license the
work in any other way, but it does not invalidate such permission if you have
separately received it.
* **d)** If the work has interactive user interfaces, each must display Appropriate Legal
Notices; however, if the Program has interactive interfaces that do not display
Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are
not by their nature extensions of the covered work, and which are not combined with
it such as to form a larger program, in or on a volume of a storage or distribution
medium, is called an “aggregate” if the compilation and its resulting
copyright are not used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work in an aggregate
does not cause this License to apply to the other parts of the aggregate.
### 6. Conveying Non-Source Forms
You may convey a covered work in object code form under the terms of sections 4 and
5, provided that you also convey the machine-readable Corresponding Source under the
terms of this License, in one of these ways:
* **a)** Convey the object code in, or embodied in, a physical product (including a
physical distribution medium), accompanied by the Corresponding Source fixed on a
durable physical medium customarily used for software interchange.
* **b)** Convey the object code in, or embodied in, a physical product (including a
physical distribution medium), accompanied by a written offer, valid for at least
three years and valid for as long as you offer spare parts or customer support for
that product model, to give anyone who possesses the object code either **(1)** a copy of
the Corresponding Source for all the software in the product that is covered by this
License, on a durable physical medium customarily used for software interchange, for
a price no more than your reasonable cost of physically performing this conveying of
source, or **(2)** access to copy the Corresponding Source from a network server at no
charge.
* **c)** Convey individual copies of the object code with a copy of the written offer to
provide the Corresponding Source. This alternative is allowed only occasionally and
noncommercially, and only if you received the object code with such an offer, in
accord with subsection 6b.
* **d)** Convey the object code by offering access from a designated place (gratis or for
a charge), and offer equivalent access to the Corresponding Source in the same way
through the same place at no further charge. You need not require recipients to copy
the Corresponding Source along with the object code. If the place to copy the object
code is a network server, the Corresponding Source may be on a different server
(operated by you or a third party) that supports equivalent copying facilities,
provided you maintain clear directions next to the object code saying where to find
the Corresponding Source. Regardless of what server hosts the Corresponding Source,
you remain obligated to ensure that it is available for as long as needed to satisfy
these requirements.
* **e)** Convey the object code using peer-to-peer transmission, provided you inform
other peers where the object code and Corresponding Source of the work are being
offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the
Corresponding Source as a System Library, need not be included in conveying the
object code work.
A “User Product” is either **(1)** a “consumer product”, which
means any tangible personal property which is normally used for personal, family, or
household purposes, or **(2)** anything designed or sold for incorporation into a
dwelling. In determining whether a product is a consumer product, doubtful cases
shall be resolved in favor of coverage. For a particular product received by a
particular user, “normally used” refers to a typical or common use of
that class of product, regardless of the status of the particular user or of the way
in which the particular user actually uses, or expects or is expected to use, the
product. A product is a consumer product regardless of whether the product has
substantial commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
“Installation Information” for a User Product means any methods,
procedures, authorization keys, or other information required to install and execute
modified versions of a covered work in that User Product from a modified version of
its Corresponding Source. The information must suffice to ensure that the continued
functioning of the modified object code is in no case prevented or interfered with
solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for
use in, a User Product, and the conveying occurs as part of a transaction in which
the right of possession and use of the User Product is transferred to the recipient
in perpetuity or for a fixed term (regardless of how the transaction is
characterized), the Corresponding Source conveyed under this section must be
accompanied by the Installation Information. But this requirement does not apply if
neither you nor any third party retains the ability to install modified object code
on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to
continue to provide support service, warranty, or updates for a work that has been
modified or installed by the recipient, or for the User Product in which it has been
modified or installed. Access to a network may be denied when the modification itself
materially and adversely affects the operation of the network or violates the rules
and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with
this section must be in a format that is publicly documented (and with an
implementation available to the public in source code form), and must require no
special password or key for unpacking, reading or copying.
### 7. Additional Terms
“Additional permissions” are terms that supplement the terms of this
License by making exceptions from one or more of its conditions. Additional
permissions that are applicable to the entire Program shall be treated as though they
were included in this License, to the extent that they are valid under applicable
law. If additional permissions apply only to part of the Program, that part may be
used separately under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any
additional permissions from that copy, or from any part of it. (Additional
permissions may be written to require their own removal in certain cases when you
modify the work.) You may place additional permissions on material, added by you to a
covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a
covered work, you may (if authorized by the copyright holders of that material)
supplement the terms of this License with terms:
* **a)** Disclaiming warranty or limiting liability differently from the terms of
sections 15 and 16 of this License; or
* **b)** Requiring preservation of specified reasonable legal notices or author
attributions in that material or in the Appropriate Legal Notices displayed by works
containing it; or
* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that
modified versions of such material be marked in reasonable ways as different from the
original version; or
* **d)** Limiting the use for publicity purposes of names of licensors or authors of the
material; or
* **e)** Declining to grant rights under trademark law for use of some trade names,
trademarks, or service marks; or
* **f)** Requiring indemnification of licensors and authors of that material by anyone
who conveys the material (or modified versions of it) with contractual assumptions of
liability to the recipient, for any liability that these contractual assumptions
directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further
restrictions” within the meaning of section 10. If the Program as you received
it, or any part of it, contains a notice stating that it is governed by this License
along with a term that is a further restriction, you may remove that term. If a
license document contains a further restriction but permits relicensing or conveying
under this License, you may add to a covered work material governed by the terms of
that license document, provided that the further restriction does not survive such
relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in
the relevant source files, a statement of the additional terms that apply to those
files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a
separately written license, or stated as exceptions; the above requirements apply
either way.
### 8. Termination
You may not propagate or modify a covered work except as expressly provided under
this License. Any attempt otherwise to propagate or modify it is void, and will
automatically terminate your rights under this License (including any patent licenses
granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a
particular copyright holder is reinstated **(a)** provisionally, unless and until the
copyright holder explicitly and finally terminates your license, and **(b)** permanently,
if the copyright holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently
if the copyright holder notifies you of the violation by some reasonable means, this
is the first time you have received notice of violation of this License (for any
work) from that copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of
parties who have received copies or rights from you under this License. If your
rights have been terminated and not permanently reinstated, you do not qualify to
receive new licenses for the same material under section 10.
### 9. Acceptance Not Required for Having Copies
You are not required to accept this License in order to receive or run a copy of the
Program. Ancillary propagation of a covered work occurring solely as a consequence of
using peer-to-peer transmission to receive a copy likewise does not require
acceptance. However, nothing other than this License grants you permission to
propagate or modify any covered work. These actions infringe copyright if you do not
accept this License. Therefore, by modifying or propagating a covered work, you
indicate your acceptance of this License to do so.
### 10. Automatic Licensing of Downstream Recipients
Each time you convey a covered work, the recipient automatically receives a license
from the original licensors, to run, modify and propagate that work, subject to this
License. You are not responsible for enforcing compliance by third parties with this
License.
An “entity transaction” is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an organization, or
merging organizations. If propagation of a covered work results from an entity
transaction, each party to that transaction who receives a copy of the work also
receives whatever licenses to the work the party's predecessor in interest had or
could give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if the predecessor
has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or
affirmed under this License. For example, you may not impose a license fee, royalty,
or other charge for exercise of rights granted under this License, and you may not
initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
that any patent claim is infringed by making, using, selling, offering for sale, or
importing the Program or any portion of it.
### 11. Patents
A “contributor” is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The work thus
licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or
controlled by the contributor, whether already acquired or hereafter acquired, that
would be infringed by some manner, permitted by this License, of making, using, or
selling its contributor version, but do not include claims that would be infringed
only as a consequence of further modification of the contributor version. For
purposes of this definition, “control” includes the right to grant patent
sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
under the contributor's essential patent claims, to make, use, sell, offer for sale,
import and otherwise run, modify and propagate the contents of its contributor
version.
In the following three paragraphs, a “patent license” is any express
agreement or commitment, however denominated, not to enforce a patent (such as an
express permission to practice a patent or covenant not to sue for patent
infringement). To “grant” such a patent license to a party means to make
such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the
Corresponding Source of the work is not available for anyone to copy, free of charge
and under the terms of this License, through a publicly available network server or
other readily accessible means, then you must either **(1)** cause the Corresponding
Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the
patent license for this particular work, or **(3)** arrange, in a manner consistent with
the requirements of this License, to extend the patent license to downstream
recipients. “Knowingly relying” means you have actual knowledge that, but
for the patent license, your conveying the covered work in a country, or your
recipient's use of the covered work in a country, would infringe one or more
identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you
convey, or propagate by procuring conveyance of, a covered work, and grant a patent
license to some of the parties receiving the covered work authorizing them to use,
propagate, modify or convey a specific copy of the covered work, then the patent
license you grant is automatically extended to all recipients of the covered work and
works based on it.
A patent license is “discriminatory” if it does not include within the
scope of its coverage, prohibits the exercise of, or is conditioned on the
non-exercise of one or more of the rights that are specifically granted under this
License. You may not convey a covered work if you are a party to an arrangement with
a third party that is in the business of distributing software, under which you make
payment to the third party based on the extent of your activity of conveying the
work, and under which the third party grants, to any of the parties who would receive
the covered work from you, a discriminatory patent license **(a)** in connection with
copies of the covered work conveyed by you (or copies made from those copies), or **(b)**
primarily for and in connection with specific products or compilations that contain
the covered work, unless you entered into that arrangement, or that patent license
was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied
license or other defenses to infringement that may otherwise be available to you
under applicable patent law.
### 12. No Surrender of Others' Freedom
If conditions are imposed on you (whether by court order, agreement or otherwise)
that contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot convey a covered work so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not convey it at all. For example, if you
agree to terms that obligate you to collect a royalty for further conveying from
those to whom you convey the Program, the only way you could satisfy both those terms
and this License would be to refrain entirely from conveying the Program.
### 13. Use with the GNU Affero General Public License
Notwithstanding any other provision of this License, you have permission to link or
combine any covered work with a work licensed under version 3 of the GNU Affero
General Public License into a single combined work, and to convey the resulting work.
The terms of this License will continue to apply to the part which is the covered
work, but the special requirements of the GNU Affero General Public License, section
13, concerning interaction through a network will apply to the combination as such.
### 14. Revised Versions of this License
The Free Software Foundation may publish revised and/or new versions of the GNU
General Public License from time to time. Such new versions will be similar in spirit
to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that
a certain numbered version of the GNU General Public License “or any later
version” applies to it, you have the option of following the terms and
conditions either of that numbered version or of any later version published by the
Free Software Foundation. If the Program does not specify a version number of the GNU
General Public License, you may choose any version ever published by the Free
Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU
General Public License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no
additional obligations are imposed on any author or copyright holder as a result of
your choosing to follow a later version.
### 15. Disclaimer of Warranty
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
### 16. Limitation of Liability
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
### 17. Interpretation of Sections 15 and 16
If the disclaimer of warranty and limitation of liability provided above cannot be
given local legal effect according to their terms, reviewing courts shall apply local
law that most closely approximates an absolute waiver of all civil liability in
connection with the Program, unless a warranty or assumption of liability accompanies
a copy of the Program in return for a fee.
_END OF TERMS AND CONDITIONS_
## How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to
the public, the best way to achieve this is to make it free software which everyone
can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them
to the start of each source file to most effectively state the exclusion of warranty;
and each file should have at least the “copyright” line and a pointer to
where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2019 Ryan Timpe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this
when it starts in an interactive mode:
brickr Copyright (C) 2019 Ryan Timpe
This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'show c' for details.
The hypothetical commands `show w` and `show c` should show the appropriate parts of
the General Public License. Of course, your program's commands might be different;
for a GUI interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to
sign a “copyright disclaimer” for the program, if necessary. For more
information on this, and how to apply and follow the GNU GPL, see
&lt;<http://www.gnu.org/licenses/>&gt;.
The GNU General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may consider it
more useful to permit linking proprietary applications with the library. If this is
what you want to do, use the GNU Lesser General Public License instead of this
License. But first, please read
&lt;<http://www.gnu.org/philosophy/why-not-lgpl.html>&gt;.
+16 -14
View File
@@ -3,19 +3,21 @@
export("%>%")
export(bricks_from_coords)
export(bricks_from_excel)
export(bricks_from_mosaic)
export(bricks_from_rayshader)
export(bricks_from_table)
export(collect_3d)
export(collect_bricks)
export(convert_to_match_color)
export(display_3d)
export(display_bricks)
export(display_colors)
export(display_pieces)
export(display_set)
export(generate_instructions)
export(image_to_bricks)
export(layer_from_bricks)
export(legoize)
export(scale_image)
export(table_pieces)
export(build_bricks)
export(build_colors)
export(build_instructions)
export(build_mosaic)
export(build_pieces)
export(build_pieces_table)
export(build_themes)
export(coord_brick)
export(coord_brick_flip)
export(geom_brick_col)
export(geom_brick_rect)
export(image_to_mosaic)
export(scale_fill_brick)
export(theme_brick)
importFrom(magrittr,"%>%")
+55
View File
@@ -1,8 +1,63 @@
# brickr 0.1.1.0000
* **Breaking:** Pretty much *EVERY* function. Seriously, check out the README and start fresh.
* **Breaking:** Data "lego_colors.rda" has been updated with more accurate RGB values and new `brickrID` numbers. This will impact previously created mosaics and 3D models.
## Documentation
* pkgdown site
* Vignettes
## Mosaics
* New rendering of mosaics in ggplot2. Includes embossed text with custom labels.
* Color_palette allows option to choose brick colors by rarity. 'universal' (most common), 'generic', and 'special' (least common).
* New color matching options to convert image to available brick colors. Previous option still available, but results will look different due to changed RGB values.
* Color [dithering](https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering) option for large, photo-realistic mosaics.
* Updated brick collection algorithm to allow for custom brick input.
* 3D mosaics have been rewritten as 3D models using plates with `bricks_from_mosaic()`.
## 3D Models
* `brick_res` input options to render models in higher definition ('sd', 'hd', 'uhd')
* `bricks_from_rayshader()` to render LEGO models from rayshader plot_3d() input.
* Option to use plates rather than bricks. Combining the two involves some hacking.
* Updated brick collection algorithm to allow for custom brick input.
* Updated brick collection algorithm staggers bricks over layer, though still prioritizes larger bricks.
* `build_instructions` generates building instructions for 3D models, as well as mosaics.
## ggplot Extension
* `geom_brick_col` for bar charts in the shape of bricks. Negative values are fine, but `position = stack` is not available.
* `coord_brick` to prevent chart brick distortion. `coord_brick_flip` for horizontal bars.
* `scale_fill_brick` and `theme_brick` for different LEGO color options.
## TO DO
* ggplot - continuous scale
* Vignettes
- 3D model from mosaics + rayshader
- IRL
* Website
* Check() breaks at the size check
## TO DO in the future
* Negative bricks are "underside"
* bricks_from_models
* CRAN!
----
# brickr 0.0.0.9200
* Added `bricks_from_excel()` as a way to decrease the starting cost of using brickr.
* See [https://github.com/ryantimpe/brickr_toybox](https://github.com/ryantimpe/brickr_toybox)
----
# brickr 0.0.0.9150
* Added `bricks_from_coords()` function to convert a long data frame with x, y, z, and Color columns into input for `display_bricks()`.
+52
View File
@@ -0,0 +1,52 @@
#' Convert a 2D LEGO mosaic into a brickr 3D object
#'
#' @param mosaic_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @param mosaic_height Number of layers in the 3D image.
#' @param highest_el Brick height is determined by brightness of color. Use \code{highest_el = 'dark'} for darkest bricks to have \code{mosaic_height}.
#' @return A list with elements \code{threed_elevation} and \code{threed_hillshade} to created 3D mosiacs with the \code{rayshader} package.
#' @family 3D Models
#' @export
#'
bricks_from_mosaic <- function(mosaic_list, mosaic_height = 6, highest_el = "light"){
#Get previous data
in_list <- mosaic_list
BrickIDs <- in_list$ID_bricks
img_lego <- in_list$Img_lego
img_sorted_by_lum <- mosaic_list$Img_lego %>%
dplyr::left_join(lego_colors %>% dplyr::select(Lego_name = Color, lum), by = "Lego_name") %>%
dplyr::mutate(Level = as.numeric(as.factor(cut(lum, mosaic_height)))) %>%
dplyr::do(
if(highest_el == "dark"){
dplyr::mutate(., Level = max(Level) - Level + 1)
} else {.}
)
#For each Level, create a full based mosaic Level
img_all_levels <- 1:mosaic_height %>%
purrr::map_df(function(lvl){
dat <- img_sorted_by_lum %>%
#Only get colors at or above the current level
dplyr::filter(Level >= lvl) %>%
#Replace any higher levels with colors in this level
dplyr::mutate(Lego_name = ifelse(Level > lvl, NA_character_, Lego_name),
Lego_color = ifelse(is.na(Lego_name), NA_character_, Lego_color),
Level = lvl)
most_common_color <- dat %>%
dplyr::filter(!is.na(Lego_name)) %>%
dplyr::count(Lego_name, Lego_color, sort = TRUE)
dat %>%
dplyr::mutate(Lego_name = ifelse(is.na(Lego_name), as.character(most_common_color[1, "Lego_name"]), Lego_name),
Lego_color = ifelse(is.na(Lego_color), as.character(most_common_color[1, "Lego_color"]), Lego_color)) %>%
dplyr::select(-color) %>%
dplyr::rename(color = Lego_name, z = Level)
})
return(img_all_levels %>% bricks_from_coords() )
}
+68
View File
@@ -0,0 +1,68 @@
#' Build a brickr 3D object from rayshader hillshade & heightmap matrices
#'
#' @param hillshade Same as \code{rayshader::plot_3d()}. Hillshade/image to be added to 3D surface map.
#' @param heightmap Same as \code{rayshader::plot_3d()}. A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#' @param img_size Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. \code{48}) for a square image with 48 pixels on each side.
#' Use an array of two values for a rectangular image \code{c(width, height)}.
#' @param max_height Maximum height of plot in LEGO bricks or plates.
#' @return A list with elements \code{threed_elevation} and \code{threed_hillshade} to created 3D mosiacs with the \code{rayshader} package.
#' @family 3D Models
#' @export
#'
bricks_from_rayshader <- function(hillshade, heightmap, max_height = 12, img_size = 48){
#Convert RGB matrix into a mosaic. Nothing special here.
#Users can do the same to make 2D rayshader map
in_list <- hillshade %>%
image_to_mosaic(img_size)
BrickIDs <- in_list$ID_bricks
img_lego <- in_list$Img_lego
#Bad hack to scale heightmap the same way
hghtmp_list <- (array(c(heightmap, heightmap, heightmap), dim = c(nrow(heightmap), ncol(heightmap), 3)) / max(heightmap)) %>%
image_to_scaled(img_size)
hghtmp <- hghtmp_list[[1]] %>%
dplyr::select(x, y, height = R) %>%
dplyr::mutate(Level = round(height * (max_height))+1) %>%
dplyr::select(-height)
#New levels for the image
img_sorted_by_lum <- in_list$Img_lego %>%
dplyr::select(-Level) %>%
dplyr::left_join(hghtmp, by = c("x", "y")) %>%
dplyr::group_by(y) %>%
tidyr::fill(Level) %>%
tidyr::fill(Level, .direction = "up") %>%
dplyr::ungroup() %>% dplyr::group_by(x) %>%
tidyr::fill(Level) %>%
tidyr::fill(Level, .direction = "up") %>%
dplyr::ungroup()
#For each Level, create a full based mosaic Level
img_all_levels <- 1:max_height %>%
purrr::map_df(function(lvl){
dat <- img_sorted_by_lum %>%
#Only get colors at or above the current level
dplyr::filter(Level >= lvl) %>%
#Replace any higher levels with colors in this level
dplyr::mutate(Lego_name = ifelse(Level > lvl, NA_character_, Lego_name),
Lego_color = ifelse(is.na(Lego_name), NA_character_, Lego_color),
Level = lvl)
most_common_color <- dat %>%
dplyr::filter(!is.na(Lego_name)) %>%
dplyr::count(Lego_name, Lego_color, sort = TRUE)
dat %>%
dplyr::mutate(Lego_name = ifelse(is.na(Lego_name), as.character(most_common_color[1, "Lego_name"]), Lego_name),
Lego_color = ifelse(is.na(Lego_color), as.character(most_common_color[1, "Lego_color"]), Lego_color)) %>%
dplyr::select(-color) %>%
dplyr::rename(color = Lego_name, z = Level)
})
return(img_all_levels %>% bricks_from_coords() )
}
+17 -12
View File
@@ -1,4 +1,4 @@
#' Convert a data frame in 3D matrix format into bricks for 3D Model
#' Convert a matrix table into a brickr 3D object
#'
#' @param matrix_table A data frame of a 3D brick model desigh. Left-most column is level/height/z dimension, with rows as Y axis and columns as X axis. See example. Use \code{tribble} for ease.
#' @param color_guide A data frame linking numeric \code{.value} in \code{matrix_table} to official LEGO color names. Defaults to data frame 'lego_colors'.
@@ -12,6 +12,7 @@
#' @param exclude_color Numeric array of color ID numbers to exclude.
#' @param exclude_level Numeric array of Level/z dimensions to exclude.
#' @return A list with elements \code{Img_lego} to pass to \code{collect_bricks()}.
#' @family 3D Models
#' @export
#'
bricks_from_table <- function(matrix_table, color_guide = lego_colors, .re_level = TRUE,
@@ -36,9 +37,9 @@ bricks_from_table <- function(matrix_table, color_guide = lego_colors, .re_level
if(ncol(color_guide) < 2){stop(color_guide_error_msg)}
if(!(".value" %in% names(color_guide)) | !("Color" %in% names(color_guide))){stop(color_guide_error_msg)}
if(!all(color_guide$Color %in% display_colors(.names_only = TRUE))){
stop(paste("At least one color name supplied does not match allowed brick color names. See display_colors().\n\n",
paste(color_guide$Color[!(color_guide$Color %in% display_colors(.names_only = TRUE))],collapse = ", ")
if(!all(color_guide$Color %in% build_colors(.names_only = TRUE))){
stop(paste("At least one color name supplied does not match allowed brick color names. See build_colors().\n\n",
paste(color_guide$Color[!(color_guide$Color %in% build_colors(.names_only = TRUE))],collapse = ", ")
))
}
@@ -97,15 +98,17 @@ bricks_from_table <- function(matrix_table, color_guide = lego_colors, .re_level
#Return an object from collect_bricks()
return(
list(Img_lego = brick_set) %>% collect_bricks
list(Img_lego = brick_set,
brickr_object = "3dmodel") %>% collect_bricks
)
}
#' Convert an Excel {brickr} template into a 3D model. https://github.com/ryantimpe/brickr_toybox
#' Convert an Excel {brickr} template into a brickr 3D object
#' @param excel_table Sheet imported from a brickr Excel template to build model. Contains stud placement and colors.
#' @param repeat_levels How many times to repeat a level. Can save time in model planning. Default is 1.
#' @inheritParams bricks_from_table
#' @return A list with elements \code{Img_lego} to pass to \code{collect_bricks()}.
#' @family 3D Models
#' @export
#'
bricks_from_excel <- function(excel_table, repeat_levels = 1,
@@ -152,9 +155,9 @@ bricks_from_excel <- function(excel_table, repeat_levels = 1,
return(brickr_out)
}
#' Convert a data frame with x, y, & z coordinates & Color into bricks for 3D Model
#' Convert a data frame with x, y, z & Color columns into a brickr 3D object
#'
#' @param coord_table A data frame of a 3D brick model design. Contains x, y, and z (vertical height) dimensions, as well as Color from official LEGO color names. See \code{display_colors()}.
#' @param coord_table A data frame of a 3D brick model design. Contains x, y, and z (vertical height) dimensions, as well as Color from official LEGO color names. See \code{build_colors()}.
#' @param increment_level Default '0'. Use in animations. Shift Level/z dimension by an integer.
#' @param max_level Default 'Inf'. Use in animations. Any Level/z values above this value will be cut off.
#' @param increment_x Default '0'. Use in animations. Shift x dimension by an integer.
@@ -164,6 +167,7 @@ bricks_from_excel <- function(excel_table, repeat_levels = 1,
#' @param exclude_color Numeric array of color ID numbers to exclude.
#' @param exclude_level Numeric array of Level/z dimensions to exclude.
#' @return A list with elements \code{Img_lego} to pass to \code{collect_bricks()}.
#' @family 3D Models
#' @export
#'
bricks_from_coords <- function(coord_table, color_guide = lego_colors,
@@ -180,7 +184,7 @@ bricks_from_coords <- function(coord_table, color_guide = lego_colors,
names(bricks_raw)[tolower(names(bricks_raw)) == "color"] <- "Color"
if(!all(c("x", "y", "z", "Color") %in% names(bricks_raw))){
stop("Input 'coord_table' must include the columns x, y, z, and Color. z should be >1. Color uses offical brick color names. See display_colors().")
stop("Input 'coord_table' must include the columns x, y, z, and Color. z should be >1. Color uses offical brick color names. See build_colors().")
}
#x, y, z, must be whole numbers and unique
@@ -210,9 +214,9 @@ bricks_from_coords <- function(coord_table, color_guide = lego_colors,
dplyr::rename(Level = z) %>%
dplyr::left_join(brickr::lego_colors %>% dplyr::select(Color, dplyr::contains("_lego")),
by = "Color") %>%
dplyr::mutate_at(dplyr::vars(dplyr::contains("_lego")), dplyr::funs(ifelse(is.na(.), 0, .))) %>%
dplyr::mutate_at(dplyr::vars(dplyr::contains("_lego")), list(~ifelse(is.na(.), 0, .))) %>%
dplyr::mutate(Lego_color = grDevices::rgb(R_lego, G_lego, B_lego)) %>%
dplyr::mutate(Lego_color = ifelse(is.na(Color),NA, Lego_color)) %>%
dplyr::mutate(Lego_color = ifelse(is.na(Color), NA, Lego_color)) %>%
dplyr::rename(Lego_name = Color) %>%
dplyr::arrange(Level) %>%
#Exclusions
@@ -231,6 +235,7 @@ bricks_from_coords <- function(coord_table, color_guide = lego_colors,
#Return an object from collect_bricks()
return(
list(Img_lego = brick_set) %>% collect_bricks
list(Img_lego = brick_set,
brickr_object = "3dmodel") %>% collect_bricks
)
}
+75 -25
View File
@@ -1,11 +1,19 @@
#' Helper function to convert a level from a 3D model into a rayshader-friendly object.
#' Display a brickr object as a 3D model
#'
#' @param brick_list List output from table_to_bricks(). Contains an element \code{Img_lego}.
#' @param brick_list A 3D brickr object from a bricks_from_*() function..
#' @param brick_type Type of brick to use. Default is 'brick'. Other option is
#' 'plate', which is 1/3 the height of a brick.
#' @param lev z-level of 3D model
#' @return A list with elements \code{threed_elevation} and \code{threed_hillshade} to created 3D mosiacs with the \code{rayshader} package.
#' @export
#'
layer_from_bricks <- function(brick_list, lev=1){
#' @param brick_res Resolution, expressed at number of pixels on one side of a
#' 1x1 brick. Defaults to 'sd' (15px). Use 'hd' for 30px per brick, and 'uhd'
#' for 60px. Enter a value for a custom resolution. High resolutions take
#' longer to render.
#' @return A list with elements \code{threed_elevation} and
#' \code{threed_hillshade} to created 3D mosiacs with the \code{rayshader}
#' package.
#' @keywords internal
layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res = "sd"){
#Get previous data
in_list <- brick_list
@@ -15,12 +23,37 @@ layer_from_bricks <- function(brick_list, lev=1){
img_lego <- in_list$Img_lego %>%
dplyr::filter(Level == lev)
if(brick_type == 'plate'){
brick_depth = 1L
} else {
brick_depth = 3L
}
#Increment elevation - a brick is 3 plates tall
up_el = (lev-1)*3
up_el = (lev-1)*brick_depth
#Number of 'pixels' on a side of a single-stud brick. I think this should be fixed for now
ex_size <- 15
#Number of 'pixels' on a side of a single-stud brick. Set by brick_res.
if(is.numeric(brick_res)){
if(brick_res > 100) warning("brick_res capped at 100px per brick.")
ex_size <- min(100, abs(round(brick_res)))
} else {
if(!(brick_res %in% c('sd', 'hd', 'uhd'))) stop("brick_res must be 'sd', 'hd', 'uhd', or a number.")
ex_size <- switch(brick_res,
sd = 15,
hd = 30,
uhd = 60)
}
#Use below is edge calculation
# Optimized color only in HD bricks >20 pixels
if(ex_size >= 20){
edge_offset <- 0:1
} else {
edge_offset <- 0
}
#Increase data frame into the correct resolution
lego_expand <- img_lego %>%
dplyr::select(Level, x, y, Lego_name, Lego_color) %>%
dplyr::mutate(stud_id = dplyr::row_number())
@@ -31,29 +64,36 @@ layer_from_bricks <- function(brick_list, lev=1){
y_comp = y %/% ex_size) %>%
dplyr::left_join(lego_expand %>% dplyr::rename(x_comp = x, y_comp = y),
by = c("x_comp", "y_comp")) %>%
dplyr::left_join(BrickIDs %>% dplyr::select(brick_id, x_comp = x, y_comp = y),
dplyr::left_join(BrickIDs %>% dplyr::select(brick_name, x_comp = x, y_comp = y),
by = c("x_comp", "y_comp")) %>%
dplyr::select(-x_comp, -y_comp) %>%
dplyr::left_join(lego_colors %>% dplyr::select(Lego_name = Color, R_lego, G_lego, B_lego),
by = "Lego_name") %>%
#Round elevation to nearest 1/height
dplyr::mutate(elevation = ifelse(is.na(brick_id),NA, 3 + up_el),
dplyr::mutate(elevation = ifelse(is.na(brick_name),NA, brick_depth + up_el),
elevation = ifelse(is.na(Lego_name),NA, elevation)) %>%
dplyr::group_by(brick_id) %>%
#Create the edges of bricks... Brick base begins at 0.01 to avoid complete overlap with previous brick
dplyr::group_by(brick_name) %>%
dplyr::mutate(elevation = dplyr::case_when(
x == min(x) | x == max(x) ~ 0.1+up_el,
y == min(y) | y == max(y) ~ 0.1+up_el,
x %in% (min(x) + edge_offset) ~ 0.01+up_el,
x %in% (max(x) - edge_offset) ~ 0.01+up_el,
y %in% (min(y) + edge_offset) ~ 0.01+up_el,
y %in% (max(y) - edge_offset) ~ 0.01+up_el,
TRUE ~ elevation
)) %>%
dplyr::ungroup() %>%
dplyr::mutate(y = max(y)-y) %>%
#Calculate stud placement... radius of 1/3 and height of 0.5 plate
#Calculate stud placement... radius of 5/8 * (1/2) and height of 0.5 plate
dplyr::group_by(stud_id) %>%
dplyr::mutate(x_mid = median(x), y_mid = median(y),
stud = ((x-x_mid)^2 + (y-y_mid)^2)^(1/2) < ex_size/3) %>%
stud = ((x-x_mid)^2 + (y-y_mid)^2)^(1/2) <= (ex_size * (5/8 * (1/2))),
stud_color = dplyr::between(((x-x_mid)^2 + (y-y_mid)^2)^(1/2),
(ex_size * (5/8 * (1/2))) - 1,
(ex_size * (5/8 * (1/2)))
)) %>%
dplyr::ungroup() %>%
dplyr::mutate(elevation = ifelse(stud, elevation+0.5, elevation)) %>%
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego), list(~ifelse(stud, .-0.1, .))) %>%
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego), list(~ifelse(stud_color, .-0.1, .))) %>%
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego), list(~ifelse(. < 0, 0, .)))
#Elevation Matrix
@@ -70,10 +110,14 @@ layer_from_bricks <- function(brick_list, lev=1){
3))
lego_expand_color <- lego_expand2 %>%
dplyr::group_by(brick_id) %>%
dplyr::group_by(brick_name) %>%
#This darkens the edge of each brick, to look like they are separated
# The higher the resolution, the dark this should be
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego),
list(~ifelse((x == min(x) | y == min(y) | x == max(x) | y == max(y)), .*0.9, .))) %>%
list(~ifelse((x == min(x) | y == min(y) | x == max(x) | y == max(y)),
. - 0.1, .))) %>%
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego),
list(~ifelse(. < 0, 0, .))) %>%
dplyr::ungroup()
lego_hillshade_m[,,1] <- lego_expand_color %>%
@@ -97,6 +141,7 @@ layer_from_bricks <- function(brick_list, lev=1){
#Return
in_list[["threed_elevation"]] <- lego_elmat
in_list[["threed_hillshade"]] <- lego_hillshade_m
in_list[["brick_resolution"]] <- ex_size
return(in_list)
@@ -106,14 +151,18 @@ layer_from_bricks <- function(brick_list, lev=1){
#' Build 3D brick model with rayshader.
#'
#' @param brick_list List output from collect_bricks(). Contains an element \code{Img_lego}.
#' @param brick_type Type of brick to use. Default is 'brick'. Other option is 'plate', which is 1/3 the height of a brick.
#' @param view_levels Numeric array of Levels/z values to display. Leave as \code{NULL} to include all.
#' @param brick_res Resolution, expressed at number of pixels on one side of a 1x1 brick. Defaults to 'sd' (15px). Use 'hd' for 30px per brick, and 'uhd' for 60px.
#' Enter a value for a custom resolution. High resolutions take longer to render.
#' @param solidcolor Hex color of mosaic base. Only renders on bottom.
#' @param ... All other inputs from rayshader::plot_3d() EXCEPT \code{hillshade}, \code{soliddepth}, \code{zscale}, and \code{shadow}.
#' @return 3D brick model rendered in the 'rgl' package.
#' @family 3D Models
#' @export
#'
display_bricks <- function(brick_list, view_levels = NULL,
solidcolor = "#a3a2a4", ...){
build_bricks <- function(brick_list, brick_type = "brick", brick_res = "sd",
view_levels = NULL, solidcolor = "#a3a2a4", ...){
#Requires Rayshader
if (!requireNamespace("rayshader", quietly = TRUE)) {
stop("Package \"rayshader\" needed for this function to work. Please install it.",
@@ -129,13 +178,14 @@ display_bricks <- function(brick_list, view_levels = NULL,
if(is.null(view_levels)){
view_levels <- unique(img_lego$Level)
}
for(ii in view_levels){
brick_layer <- brick_list %>% layer_from_bricks(ii)
brick_layer <- brick_list %>% layer_from_bricks(ii, brick_type = brick_type, brick_res = brick_res)
brick_layer$`threed_hillshade`%>%
rayshader::plot_3d(brick_layer$`threed_elevation`, zscale=0.167, solid = FALSE,
rayshader::plot_3d(brick_layer$`threed_elevation`, zscale=0.167*(15/brick_layer$`brick_resolution`),
solid = FALSE,
solidcolor=solidcolor, shadow = FALSE, ...)
}
}
}
+76
View File
@@ -0,0 +1,76 @@
#' Create instruction manual for 2D image mosaics
#'
#' @param brickr_obj brickr mosaic or 3D model object.
#' @param num_steps Number of discrete steps in instruction manual, for mosaics only
#' @family Resources
#' @export
#'
build_instructions <- function(brickr_obj, num_steps=6) {
in_list <- brickr_obj
image <- in_list$Img_bricks
type <- in_list$brickr_object
#Mosaic instructions ----
if(type == "mosaic"){
num_steps <- min(abs(round(num_steps)), 40)
rows_per_step <- ceiling((max(image$ymax)-0.5) / (num_steps+1))
create_steps <- function(a, n_steps) {
if(a < n_steps){
image %>%
dplyr::group_by(brick_name) %>%
dplyr::filter(min(ymin) <= a*rows_per_step+(min(image$ymin)+0.5)) %>%
dplyr::ungroup() %>%
dplyr::mutate(Step = paste("Step", stringr::str_pad(a, 2, pad = "0")))
} else {
image %>%
dplyr::mutate(Step = paste("Step", stringr::str_pad(a, 2, pad = "0")))
}
}
steps_for_plot <- 1:num_steps %>%
purrr::map_df(create_steps, num_steps) %>%
dplyr::mutate(alpha = 1)
} #end mosaics
else if(type == "3dmodel"){
num_steps <- length(unique(image$Level))
create_steps <- function(a, n_steps) {
image %>%
dplyr::filter(between(Level, a-1, a)) %>%
dplyr::mutate(alpha = ifelse(Level == a, 1, 0.5)) %>%
dplyr::mutate(Step = paste("Step", stringr::str_pad(a, 2, pad = "0")))
}
steps_for_plot <- 1:num_steps %>%
purrr::map_df(create_steps, num_steps)
}
#Plot ----
coord_ratio <- 1
steps_for_plot %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
fill = Lego_color, alpha = alpha), color = "#333333") +
ggplot2::scale_fill_identity() +
ggplot2::scale_alpha_identity() +
ggplot2::coord_fixed(ratio = coord_ratio, expand = TRUE) +
ggplot2::facet_wrap(~Step) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
legend.position = "none")
}
+28
View File
@@ -0,0 +1,28 @@
#' Display 2D LEGO mosaic as a plot image
#'
#' @param brick_obj List output from image_to_bricks(). Contains an element \code{Img_lego}.
#' @param title Optional title to include above plotted mosaic.
#' @family Mosaics
#' @export
#'
build_mosaic <- function(brick_obj, title=NULL){
in_list <- brick_obj
image <- in_list$Img_bricks
type <- in_list$mosaic_type
coord_x <- c(min(image$xmin)+0.5, max(image$xmax)-0.5)
coord_y <- c(min(image$ymin)+0.5, max(image$ymax)-0.5)
img <- ggplot2::ggplot(in_list$Img_lego, ggplot2::aes(x=x, y=y)) +
geom_brick_rect(ggplot2::aes(fill = Lego_color), color = "#333333")+
ggplot2::scale_fill_identity() +
ggplot2::coord_fixed(expand = 0.5)
img <- img +
ggplot2::labs(title = title) +
ggplot2::theme_void()
return(img)
}
+118
View File
@@ -0,0 +1,118 @@
#' Consolidate 1x1 bricks into larger ones of the same color. Internal function.
#'
#' @param image_list List output from legoize(). Contains an element \code{Img_lego}.
#' @param use_bricks Array of brick sizes to use in mosaic. Defaults to \code{c('4x2', '2x2', '3x1', '2x1', '1x1')}`.
#' @return A list with element \code{Img_bricks} containing a data frame of the x- & y-coordinates, R, G, B channels, and brick ID. Other helper elements.
#' @keywords internal
collect_bricks <- function(image_list, use_bricks = NULL){
in_list <- image_list
#Allowed bricks ----
if(is.null(use_bricks)){
use_bricks <- c('4x2', '2x2', '4x1', '3x1', '2x1', '1x1')
} else {
#Must contain 1x1... duplicated gets dropped
use_bricks <- c(use_bricks, '1x1')
}
brick_sizes <- tibble::tibble(bricks = use_bricks) %>%
tidyr::separate(bricks, c("xx", "yy"), sep = "[^[\\d+]]+") %>%
dplyr::mutate_all(as.numeric)
brick_sizes2 <- dplyr::bind_rows(
brick_sizes,
brick_sizes %>% dplyr::rename(yy=1, xx=2)
) %>%
dplyr::distinct() %>%
dplyr::mutate(offset_x = purrr::map(xx, ~.x:1 -1)) %>%
tidyr::unnest() %>%
dplyr::mutate(offset_y = purrr::map(yy, ~.x:1 -1)) %>%
tidyr::unnest() %>%
dplyr::arrange(dplyr::desc(xx*yy), #Start with bricks with most area
xx+yy, #Then smaller perimeter... so 2x2 is before 1x4,
dplyr::desc(xx), #Then widest first, so offsets are collected
offset_x, offset_y) %>%
dplyr::mutate(brick_id_loc = dplyr::row_number())
# Brick looping ----
# Does any xx*yy space contain all the same color?
img <- (1:nrow(brick_sizes2)) %>%
purrr::map_dfr(function(aa){
xx <- brick_sizes2$xx[aa]
yy <- brick_sizes2$yy[aa]
offset_x <- brick_sizes2$offset_x[aa]
offset_y <- brick_sizes2$offset_y[aa]
in_list$Img_lego %>%
#Weird bug when resetting the level
dplyr::select(Level, x, y, Lego_name, Lego_color) %>%
# dplyr::mutate(Level = ifelse(!is.numeric(lll), as.numeric(as.factor(lll)), lll)) %>%
# dplyr::select(-lll) %>%
dplyr::group_by(Level,
xg = (x + offset_x -1 + Level -1) %/% xx,
yg = (y + offset_y -1 + Level -1) %/% yy) %>%
dplyr::mutate(brick_type = paste0("x", xx, "y", yy, "_offx", offset_x, "_offy", offset_y)) %>%
dplyr::mutate(brick_name = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == (xx*yy),
paste0("brick_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
dplyr::ungroup() %>%
dplyr::select(-xg, -yg) %>%
dplyr::filter(!is.na(Lego_name))
}
)
#Output of all brick types... size * layout
bricks <- unique(img$brick_type)
bricks_df <- img %>%
dplyr::filter(dplyr::row_number() < 1)
#Reduce to the biggest and first brick ----
#Iteratively go through each brick, in order from largest to smallest, removing them and then checking the remaining image for complete bricks.
for(bb in bricks){
dat <- img %>%
dplyr::filter(brick_type == bb) %>%
tidyr::drop_na(brick_name) %>%
dplyr::anti_join(bricks_df, by = c("Level", "x", "y")) %>%
#Necessary Area
dplyr::mutate(area_tar = as.numeric(substr(brick_type, 2,2)) * as.numeric(substr(brick_type, 4,4))) %>%
#Actual Area
dplyr::group_by(brick_name) %>%
dplyr::mutate(area_act = dplyr::n()) %>%
dplyr::ungroup() %>%
#Drop rows where the areas don't match
dplyr::filter(area_act == area_tar) %>%
dplyr::select(-dplyr::starts_with("area"))
bricks_df <- bricks_df %>%
dplyr::bind_rows(dat)
}
img2 <- bricks_df %>%
# min/max coord for geom_rect()
dplyr::group_by(Level, brick_type, brick_name, Lego_color, Lego_name) %>%
dplyr::summarise(xmin = min(x)-0.5, xmax = max(x)+0.5,
ymin = min(y)-0.5, ymax = max(y)+0.5) %>%
dplyr::ungroup()
# Pieces ----
# This is very brute-force. Probably a much cleaner way to do this
pcs <- img2 %>%
dplyr::select(Level, brick_type, brick_name, Lego_name, Lego_color) %>%
dplyr::distinct() %>%
dplyr::mutate(size1 = as.numeric(substr(brick_type, 2, 2)),
size2 = as.numeric(substr(brick_type, 4, 4))) %>%
dplyr::mutate(Brick_size = ifelse(size1>size2, paste(size1, "x", size2), paste(size2, "x" , size1))) %>%
dplyr::count(Brick_size, Lego_name, Lego_color)
in_list[["Img_bricks"]] <- img2
in_list[["ID_bricks"]] <- bricks_df
in_list[["pieces"]] <- pcs
return(in_list)
}
-272
View File
@@ -1,272 +0,0 @@
#' Collect legoize image from individual bricks into grouped bricks.
#'
#' @param image_list List output from legoize(). Contains an element \code{Img_lego}.
#' @param mosaic_type Default is 'flat' for a "studs-up" mosaic. Other option is 'stacked' for bricks placed on top of each other.
#' @return A list with element \code{Img_bricks} containing a data frame of the x- & y-coordinates, R, G, B channels, and brick ID. Other helper elements.
#' @export
#'
collect_bricks <- function(image_list, mosaic_type = "flat"){
in_list <- image_list
if(mosaic_type == "flat"){
img <- in_list$Img_lego %>%
dplyr::select(Level, x, y, Lego_name, Lego_color) %>%
#4x2 bricks - horizontal
dplyr::group_by(Level, xg = x %/% 4, yg = y %/% 2) %>%
dplyr::mutate(g_1_x4y2_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 1,0
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 4, yg = y %/% 2) %>%
dplyr::mutate(g_1_x4y2_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 2,0
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+2) %/% 4, yg = y %/% 2) %>%
dplyr::mutate(g_1_x4y2_2 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 3,0
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+3) %/% 4, yg = y %/% 2) %>%
dplyr::mutate(g_1_x4y2_3 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 0,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+0) %/% 4, yg = (y+1) %/% 2) %>%
dplyr::mutate(g_1_x4y2_4 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 1,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 4, yg = (y+1) %/% 2) %>%
dplyr::mutate(g_1_x4y2_5 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 2,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+2) %/% 4, yg = (y+1) %/% 2) %>%
dplyr::mutate(g_1_x4y2_6 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - horizontal- offset 3,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+3) %/% 4, yg = (y+1) %/% 2) %>%
dplyr::mutate(g_1_x4y2_7 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x4y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x %/% 2, yg = y %/% 4) %>%
dplyr::mutate(g_2_x2y4_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 0,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x) %/% 2, yg = (y+1) %/% 4) %>%
dplyr::mutate(g_2_x2y4_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 0,2
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+0) %/% 2, yg = (y+2) %/% 4) %>%
dplyr::mutate(g_2_x2y4_2 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 0,3
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+0) %/% 2, yg = (y+3) %/% 4) %>%
dplyr::mutate(g_2_x2y4_3 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 1, 0
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 2, yg = y %/% 4) %>%
dplyr::mutate(g_2_x2y4_4 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 1,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 2, yg = (y+1) %/% 4) %>%
dplyr::mutate(g_2_x2y4_5 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 1,2
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 2, yg = (y+2) %/% 4) %>%
dplyr::mutate(g_2_x2y4_6 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x2 bricks - vertical - offset 1,3
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 2, yg = (y+3) %/% 4) %>%
dplyr::mutate(g_2_x2y4_7 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 8,
paste0("x2y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x2 bricks
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x %/% 2, yg = y %/% 2) %>%
dplyr::mutate(g_5_x2y2_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x2y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x2 bricks - offset by 1,1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 2, yg = (y+1) %/% 2) %>%
dplyr::mutate(g_5_x2y2_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x2y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - horizontal
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x %/% 4, yg = y ) %>%
dplyr::mutate(g_7_x4y1_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x4y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - horizontal - offset 1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 4, yg = y ) %>%
dplyr::mutate(g_7_x4y1_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x4y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - horizontal - offset 2
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+2) %/% 4, yg = y ) %>%
dplyr::mutate(g_7_x4y1_2 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x4y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - horizontal - offset 3
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+3) %/% 4, yg = y ) %>%
dplyr::mutate(g_7_x4y1_3 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x4y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - vertical
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = y %/% 4) %>%
dplyr::mutate(g_8_x1y4_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x1y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - vertical - offset 1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = (y+1) %/% 4) %>%
dplyr::mutate(g_8_x1y4_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x1y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - vertical - offset 2
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = (y+2) %/% 4) %>%
dplyr::mutate(g_8_x1y4_2 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x1y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#4x1 bricks - vertical - offset 3
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = (y+3) %/% 4) %>%
dplyr::mutate(g_8_x1y4_3 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x1y4_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - horizontal
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x %/% 3, yg = y ) %>%
dplyr::mutate(g_7_x3y1_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x3y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - horizontal - offset 1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 3, yg = y ) %>%
dplyr::mutate(g_7_x3y1_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x3y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - horizontal - offset 2
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+2) %/% 3, yg = y ) %>%
dplyr::mutate(g_7_x3y1_2 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x3y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - vertical
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = y %/% 3) %>%
dplyr::mutate(g_8_x1y3_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x1y3_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - vertical - offset 1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = (y+1) %/% 3) %>%
dplyr::mutate(g_8_x1y3_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x1y3_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - vertical - offset 2
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = (y+2) %/% 3) %>%
dplyr::mutate(g_8_x1y3_2 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x1y3_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x1 bricks - horizontal
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x %/% 2, yg = y ) %>%
dplyr::mutate(g_9_x2y1_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 2,
paste0("x2y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x1 bricks - horizontal - offset 1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x+1) %/% 2, yg = y ) %>%
dplyr::mutate(g_9_x2y1_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 2,
paste0("x2y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x1 bricks - vertical
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = y %/% 2) %>%
dplyr::mutate(g_a_x1y2_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 2,
paste0("x1y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x1 bricks - vertical - offset 1
dplyr::ungroup() %>% dplyr::group_by(Level, xg = x, yg = (y+1) %/% 2) %>%
dplyr::mutate(g_a_x1y2_1 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 2,
paste0("x1y2_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
dplyr::ungroup() %>%
#1x1
dplyr::mutate(g_b_x1y1_0 = paste0("x1y1_", "x", x, "_y", y, "_", Level)) %>%
dplyr::select(-xg, -yg)
}
else if(mosaic_type == "stacked"){
img <- in_list$Img_lego %>%
dplyr::select(Level, x, y, Lego_name, Lego_color) %>%
#4x1 bricks - horizontal
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x + y %% 4) %/% 4, yg = y ) %>%
dplyr::mutate(g_7_x4y1_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 4,
paste0("x4y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#3x1 bricks - horizontal
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x + y %% 3) %/% 3, yg = y ) %>%
dplyr::mutate(g_7_x3y1_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 3,
paste0("x3y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
#2x1 bricks - horizontal
dplyr::ungroup() %>% dplyr::group_by(Level, xg = (x + y %% 2) %/% 2, yg = y ) %>%
dplyr::mutate(g_9_x2y1_0 = ifelse(length(unique(Lego_name)) == 1 & dplyr::n() == 2,
paste0("x2y1_", "x", min(x), "_y", min(y), "_", Level), NA)) %>%
dplyr::ungroup() %>%
#1x1
dplyr::mutate(g_b_x1y1_0 = paste0("x1y1_", "x", x, "_y", y, "_", Level)) %>%
dplyr::select(-xg, -yg)
}
else(stop("Use mosaic_type = 'flat' or 'stacked'"))
# New calculation for piece placement, March 1, 2019.
# https://github.com/ryantimpe/LEGOMosaics/issues/2
img2a <- img %>%
tidyr::gather(Brick, brick_id, dplyr::starts_with("g_"))
bricks <- unique(img2a$Brick)
bricks_df <- img2a %>%
dplyr::filter(dplyr::row_number() <1)
#Iteratively go through each brick, in order from largest to smallest, removing them and then checking the remaining image for complete bricks.
for(bb in bricks){
dat <- img2a %>%
dplyr::filter(Brick == bb) %>%
tidyr::drop_na(brick_id) %>%
dplyr::anti_join(bricks_df, by = c("Level", "x", "y")) %>%
#Necessary Area
dplyr::mutate(area_tar = as.numeric(substr(brick_id, 2,2)) * as.numeric(substr(brick_id, 4,4))) %>%
#Actual Area
dplyr::group_by(brick_id) %>%
dplyr::mutate(area_act = dplyr::n()) %>%
dplyr::ungroup() %>%
#Drop rows where the areas don't match
dplyr::filter(area_act == area_tar) %>%
dplyr::select(-dplyr::starts_with("area"))
bricks_df <- bricks_df %>%
dplyr::bind_rows(dat)
}
img2 <- bricks_df %>%
# min/max coord for geom_rect()
dplyr::group_by(Level, Brick, brick_id, Lego_color, Lego_name) %>%
dplyr::summarise(xmin = min(x)-0.5, xmax = max(x)+0.5,
ymin = min(y)-0.5, ymax = max(y)+0.5) %>%
dplyr::ungroup()
# This is very brute-force. Probably a much cleaner way to do this
pcs <- img2 %>%
dplyr::select(Level, Brick, brick_id, Lego_name, Lego_color) %>%
dplyr::distinct() %>%
tidyr::separate(Brick, c("g", "gn", "size", "gi")) %>%
dplyr::select(-dplyr::starts_with("g")) %>%
dplyr::mutate(size1 = as.numeric(substr(size, 2, 2)),
size2 = as.numeric(substr(size, 4, 4))) %>%
dplyr::mutate(Brick_size = ifelse(size1>size2, paste(size1, "x", size2), paste(size2, "x" , size1))) %>%
dplyr::count(Brick_size, Lego_name, Lego_color)
#Replace "x 1" bricks with "x 2". More likely to be used for a stacked mosaic
if(mosaic_type == "stacked"){
pcs <- pcs %>%
dplyr::mutate(Brick_size = gsub("x 1", "x 2", Brick_size, fixed = TRUE))
}
in_list[["Img_bricks"]] <- img2
in_list[["ID_bricks"]] <- bricks_df
in_list[["mosaic_type"]] <- mosaic_type
in_list[["pieces"]] <- pcs
return(in_list)
}
#' Convert image raster array to a LEGO-esque mosaic. Wrapper function.
#'
#' @param image_list List output from scale_image(). Contains an element \code{Img_scaled}.
#' @param img_size Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. \code{48}) for a square image with 48 pixels on each side.
#' Use an array of two values for a rectangular image \code{c(width, height)}.
#' @param color_table Defaults to \code{lego_colors}. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels. See attached data \code{lego_colors} as examples.
#' @param mosaic_type Default is 'flat' for a "studs-up" mosaic. Other option is 'stacked' for bricks placed on top of each other.
#' @param brightness A value >1 will increase the brightness of the image while a positive value <1 will decrease the brightness.
#' @param warhol Array of values \code{c(1, 2, 3)} associated with R, G, B color channels. Swap values in array to swap color channels for a fun visual effect.
#' @param brick_theme Theme of brick colors to use. Set to \code{"bw"} for grayscale mosaics.
#' @param contrast For \code{theme = "bw"}. A value >1 will increase the contrast of the image while a positive value <1 will decrease the contrast.
#' @return A list with element \code{Img_lego} containing a data frame of the x- & y-coordinates, R, G, B channels, and mapped color of each brick (pixel).
#' @export
#'
image_to_bricks <- function(img, img_size = 48, color_table = lego_colors, mosaic_type = "flat",
brightness = 1, warhol = 1:3, brick_theme = "default", contrast = 1){
in_list <- img %>%
scale_image(img_size = img_size, brightness = brightness, warhol = warhol) %>%
legoize(color_table = color_table, theme = brick_theme, contrast = contrast) %>%
collect_bricks(mosaic_type = mosaic_type)
return(in_list)
}
+92
View File
@@ -0,0 +1,92 @@
#' Display available brick colors
#'
#' Generates a plot of available brick colors. Use .names_only = TRUE to get a list of color names.
#'
#' @param .names_only Return an array of the 41 brick color names. Does not plot.
#' @return A table and ggplot of brick colors & ID numbers.
#' @examples
#' #Generate plot of colors
#' build_colors()
#'
#' #Print list of colors
#' build_colors(TRUE)
#' @family Resources
#' @export
build_colors <- function(.names_only = FALSE){
if(.names_only){
return(lego_colors$Color)
}
message("Use View(lego_colors) to see these in a table format.")
tidyr::crossing(x=1:2, y=1:2, color = lego_colors$Color) %>%
dplyr::left_join(lego_colors %>% dplyr::select(color = Color, color_hex = hex), by = "color") %>%
dplyr::mutate(color = factor(gsub(" ", "\n", color),
levels = gsub(" ", "\n", lego_colors$Color))) %>%
ggplot2::ggplot(aes(x=x, y=y, group=color)) +
ggplot2::labs(title = "Brick colors available in {brickr}") +
geom_brick_rect(aes(fill = color_hex), label_scale = 0.1,
#Including the use_bricks inputs greatly increases the speed of this.
use_bricks = c("2x2")) +
ggplot2::coord_fixed(x=c(0.5, 2.5), y=c(0.5, 2.5)) +
ggplot2::scale_fill_identity() +
ggplot2::facet_wrap(~color, ncol = 9) +
ggplot2::theme_void()
}
#' Display available brick themes for ggplot feature scale_fill_brick()
#'
#' Generates a plot of available brick themes.
#' @param show_theme Defaults to "all". Pass an array of theme names to only plot a subset.
#' @param .names_only Logical. Return an array of the theme names. Does not plot.
#' @return A table and ggplot of brick colors & ID numbers.
#' @examples
#' #Generate plot of themes
#' build_themes()
#' build_themes(c("ducks", "ocean", "space"))
#'
#' #Print list of themes
#' build_themes(.names_only = TRUE)
#' @family Resources
#' @export
build_themes <- function(show_themes = "all", .names_only = FALSE){
if(.names_only){
return(unique(brickr_themes$theme))
}
if("all" %in% show_themes | !any(show_themes %in% brickr_themes$theme)){
thms <- brickr_themes$theme
} else {
thms <- show_themes
}
dat <- brickr_themes %>%
dplyr::filter(TYPE == "color") %>%
dplyr::filter(theme %in% thms) %>%
dplyr::group_by(theme) %>%
dplyr::mutate(y = (dplyr::row_number()-1) %/% 4,
x = (dplyr::row_number()-1) %% 4,
x = x * 1.1, y = y * 1.1) %>%
dplyr::ungroup() %>%
dplyr::mutate(theme = factor(theme, levels = unique(brickr_themes$theme)))
dat$y = max(dat$y) - dat$y + 1
brickr_themes %>%
dplyr::filter(TYPE == "plot") %>%
dplyr::filter(theme %in% thms) %>%
dplyr::mutate(xmin = -0.7, xmax = 4, ymin = 0.2, ymax = max(dat$y)+0.7, x=0, y=0,
theme = factor(theme, levels = unique(dat$theme))) %>%
ggplot2::ggplot(ggplot2::aes(x=x, y=y)) +
ggplot2::geom_rect(ggplot2::aes(fill = hex, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)) +
geom_brick_rect(data = dat, ggplot2::aes(fill = hex), use_bricks = "1x1",
label_scale = 0.2 * (20 / length(thms))^(1/6), label = "") +
ggplot2::labs(title = "Brick themes available in {brickr}") +
ggplot2::scale_fill_identity() +
ggplot2::coord_fixed(expand = FALSE) +
ggplot2::facet_wrap(~theme, ncol = 7) +
ggplot2::theme_void() +
NULL
}
+100
View File
@@ -0,0 +1,100 @@
#' Cartesian coordinates for bricks - ggplot2 extension
#'
#' A fixed scale coordinate system that ensures correct brick proportions are maintained regardless of device size.
#' Use \code{coord_brick_flip()} for horizontal bars.
#'
#' @inheritParams ggplot2::coord_fixed
#' @examples
#' #geom_brick_col should be used in conjunction with other brickr charting functions, especially coord_brick.
#' df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
#' ggplot(df, aes(trt, outcome)) +
#' geom_brick_col(aes(fill = trt)) +
#' coord_brick()
#'
#' #horizontal bars
#' ggplot(df, aes(trt, outcome)) +
#' geom_brick_col(aes(fill = trt)) +
#' coord_brick_flip()
#' @family Graphs
#' @export
#' @rdname coord-brick
coord_brick <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
ggproto(NULL, CoordBrick,
limits = list(x = xlim, y = ylim),
expand = expand,
clip = clip
)
}
#' @export
#' @rdname coord-brick
coord_brick_flip <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
ggproto(NULL, CoordBrickFlip,
limits = list(x = xlim, y = ylim),
expand = expand,
clip = clip
)
}
#' @rdname brickr-ggproto
#' @format NULL
#' @usage NULL
CoordBrick <- ggproto("CoordBrick", CoordCartesian,
is_free = function() FALSE,
is_flipped = function() FALSE,
aspect = function(self, ranges) {
1
}
)
#' @rdname brickr-ggproto
#' @format NULL
#' @usage NULL
CoordBrickFlip <- ggproto("CoordBrickFlip", CoordCartesian,
is_flipped = function() TRUE,
transform = function(data, panel_params) {
data <- ggplot2:::flip_labels(data)
CoordCartesian$transform(data, panel_params)
},
backtransform_range = function(self, panel_params) {
self$range(panel_params)
},
range = function(self, panel_params) {
# summarise_layout() expects the original x and y ranges here,
# not the ones we would get after flipping the axes
un_flipped_range <- ggproto_parent(CoordCartesian, self)$range(panel_params)
list(x = un_flipped_range$y, y = un_flipped_range$x)
},
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
parent <- ggproto_parent(CoordCartesian, self)
panel_params <- parent$setup_panel_params(scale_x, scale_y, params)
ggplot2:::flip_labels(panel_params)
},
labels = function(panel_params) {
ggplot2:::flip_labels(CoordCartesian$labels(panel_params))
},
setup_layout = function(layout, params) {
# Switch the scales
layout[c("SCALE_X", "SCALE_Y")] <- layout[c("SCALE_Y", "SCALE_X")]
layout
},
modify_scales = function(scales_x, scales_y) {
lapply(scales_x, ggplot2:::scale_flip_position)
lapply(scales_y, ggplot2:::scale_flip_position)
},
is_free = function() FALSE,
aspect = function(self, ranges) {
1
}
)
+35
View File
@@ -0,0 +1,35 @@
#' @rdname brickr-ggproto
#' @keywords internal
draw_key_brick <- function(data, params, size) {
#Outline and text for dark colors
color_lum <- as.data.frame(t(col2rgb(data$fill)/255))
data$color_intensity <- 0.299*color_lum$red + 0.587*color_lum$green + 0.114*color_lum$blue
data$text_alpha <- ifelse(data$color_intensity <= thres_brick_lum(), 0.3, 0.3)
data$text_col <- ifelse(data$color_intensity <= thres_brick_lum(), "#CCCCCC", "#333333")
grid::grobTree(
grid::rectGrob(gp = grid::gpar(col = alpha(data$colour %||% "#333333", 0.3),
fill = alpha(data$fill %||%
data$colour %||% "#333333", data$alpha))),
grid::circleGrob(0.6, 0.4, r = 5/8*(1/2),
gp = grid::gpar(col = NA,
fill = alpha("#333333", 0.3))),
grid::circleGrob(0.5, 0.5, r = 5/8*(1/2),
gp = grid::gpar(col = alpha(data$text_col, data$text_alpha),
fill = alpha(data$fill, data$alpha))),
grid::textGrob(
data$label,
0.5, 0.5,
hjust = 0.5, vjust=0.5,
default.units = "native",
gp = grid::gpar(
col = alpha(data$text_col, data$text_alpha),
# fontsize = fs,
cex = (3/8)*0.65,
fontface = "bold"
)
)
)
}
+346
View File
@@ -0,0 +1,346 @@
#' Bar charts with bricks - ggplot2 extension
#'
#' `geom_brick_col()` is the \code{brickr} version of `ggplot2::geom_col()`.
#' Bar height is determined by values in the data using the \code{y} aesthetic. With the exception of \code{fill}, aesthetics available in `ggplot2::geom_col()` are generally not enabled here.
#
#' @inheritParams ggplot2::geom_col
#' @param label Character string to include as embossed text inside brick knobs. Maximum 6 characters.
#' @param label_scale Scale text size of label as a percentage.
#' Sizing for the embossed text can be off. A best attempt at the text size is calculated from the device size. Zooming a plot in the RStudio window will not update the text size.
#' If the automated size doesn't look correct after rendering the chart, use this scale.
#' @param two_knob Logical. Each bar is two knobs / studs wide. When rendering many \code{x} values, set to \code{FALSE}.
#' @param split_bricks Logical. For simpler bars, do not split into individual bricks. Knobs still render.
#' @param min_radius_for_text Knob radius as a percentage of view port. If the calculated radius is lower than this value, embossed label will not appear in knobs.
#' @param position It it not recommended to use \code{position = "stack"}.
#' @examples
#' #geom_brick_col should be used in conjunction with other brickr charting functions, especially coord_brick.
#' df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
#' ggplot(df, aes(trt, outcome)) +
#' geom_brick_col() +
#' coord_brick()
#'
#' #For official LEGO colors, use with scale_fill_brick and theme_brick.
#' ggplot(df, aes(trt, outcome)) +
#' geom_brick_col(aes(fill = trt)) +
#' scale_fill_brick() +
#' coord_brick() +
#' theme_brick()
#' @family Graphs
#' @export
geom_brick_col <- function(mapping = NULL, data = NULL,
position = "dodge", two_knob = TRUE, split_bricks = TRUE,
min_radius_for_text = 0.02, label = "brickr", label_scale = 1,
...,
width = NULL,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = "identity",
geom = GeomBrickCol,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
width = width,
label = label,
two_knob = two_knob,
split_bricks = split_bricks,
min_radius_for_text = min_radius_for_text,
label_scale = label_scale,
na.rm = na.rm,
...
)
)
}
#' @rdname brickr-ggproto
#' @format NULL
#' @usage NULL
GeomBrickCol <- ggproto("GeomBrickCol", GeomRect,
default_aes = aes(colour = "#333333", fill = "#B40000", size = 0.25, linetype = 1,
alpha = NA, label = "brickr",
angle = 0, family = "", fontface = 1, lineheight = 1.2),
required_aes = c("x", "y"),
# These aes columns are created by setup_data(). They need to be listed here so
# that GeomRect$handle_na() properly removes any bars that fall outside the defined
# limits, not just those for which x and y are outside the limits
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),
setup_data = function(data, params) {
data$width <- data$width %||%
params$width %||% (resolution(data$x, FALSE) * 0.9)
data$sign = sign(data$y)
transform(data,
ymin = pmin(y, 0), ymax = pmax(y, 0),
xmin = x - width / 2, xmax = x + width / 2, width = NULL
)
},
draw_panel = function(self, data, panel_params, coord, linejoin = "mitre",
min_radius_for_text = 0.02, width=NULL, label = "brickr",
two_knob = TRUE, split_bricks = TRUE, label_scale =1) {
#This happens to EACH panel
#Parameters ----
if(two_knob) n_knob <- 2 else n_knob <- 1
#Brick border ----
coords_rect <- coord$transform(data, panel_params) %>%
dplyr::mutate(size = data$size[1], linetype = data$linetype[1],
colour = data$colour[1], alpha = data$alpha[1])
#Reverse calc for flipped
if(!is.null(coord$is_flipped) && coord$is_flipped()){
coords_rect <- flip_coords(coords_rect)
}
# test_coords_rect <<- coords_rect
# Split the bricks into 4-knob long bricks. This can be turned on and off
if(split_bricks){
brick_dims <- coords_rect %>%
dplyr::mutate( brick_width = abs(xmax - xmin) / n_knob,
num_of_1xs = abs(ymax - ymin + 0.001) %/% brick_width,
num_of_plates = abs(ymax - ymin + 0.001) %/% (brick_width*4) + 1) %>% #Always at least 1 plate
#For negative bars, temporarily make them positive
dplyr::mutate(y_swap = ymin,
ymin = ifelse(sign == -1, ymax, ymin),
ymax = ifelse(sign == -1, ymax + (ymax - y_swap), ymax)) %>%
dplyr::select(-y_swap)
coords_rect_complete_bricks <- 1:max(brick_dims$num_of_plates) %>%
purrr::map_dfr(function(kk){
brick_dims %>%
dplyr::filter(num_of_plates >= kk) %>%
dplyr::mutate(ymin_orig = ymin, ymax_orig = ymax) %>%
dplyr::rowwise() %>%
dplyr::mutate(ystart_ideal = ymin_orig + (kk-1)*4*brick_width,
yend_ideal = min(ymax_orig, ystart_ideal + 4*brick_width),
num_of_knobs_in_this_brick = (abs(ystart_ideal - yend_ideal) + 0.001) %/% brick_width,
ymin = ymin_orig + (kk-1)*4*brick_width,
ymax = min(ymax_orig, ymin + num_of_knobs_in_this_brick*brick_width)) %>%
dplyr::ungroup()
})
# test_coords_rect2 <<- coords_rect_complete_bricks
coords_rect_unflipped <- dplyr::bind_rows(
#Knobbed-bricks
coords_rect_complete_bricks %>%
dplyr::filter(num_of_knobs_in_this_brick > 0),
#Unknobbed caps
coords_rect_complete_bricks %>%
dplyr::group_by(PANEL, group) %>%
dplyr::filter((dplyr::n() > 1 && num_of_knobs_in_this_brick > 0) |
dplyr::n() == 1) %>%
dplyr::filter(ymax == max(ymax)) %>%
dplyr::ungroup() %>%
dplyr::mutate(ymin = ymax,
ymax = ymax_orig)
)
coords_rect <- coords_rect_unflipped %>%
#Now need to unswap negative bars
dplyr::mutate(
y_swap = ymax,
ymax = ifelse(sign == 1, ymax,
ymin_orig - (ymin - ymin_orig)),
ymin = ifelse(sign == 1, ymin,
ymin_orig - (y_swap - ymin_orig))
) %>%
dplyr::select(-y_swap)
} #End split_bricks
# test_coords_rect3 <<- coords_rect_unflipped
# test_coords_rect4 <<- coords_rect
#Brighter colors for darker bricks
#Calculate brightness of color
# https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
color_lum <- as.data.frame(t(col2rgb(coords_rect$fill)/255))
coords_rect$color_intensity <- 0.299*color_lum$red + 0.587*color_lum$green + 0.114*color_lum$blue
coords_rect$outline_col <- ifelse(coords_rect$color_intensity <= thres_brick_lum(), "#CCCCCC", "#333333")
#Un-Reverse calc for flipped coords
if(!is.null(coord$is_flipped) && coord$is_flipped()){
coords_rect <- flip_coords(coords_rect)
}
gm_brick <- grid::rectGrob(
coords_rect$xmin, coords_rect$ymax,
width = coords_rect$xmax - coords_rect$xmin,
height = coords_rect$ymax - coords_rect$ymin,
default.units = "native",
just = c("left", "top"),
gp = grid::gpar(
col = alpha(coords_rect$outline_col, 0.3),
fill = alpha(coords_rect$fill, coords_rect$alpha),
lwd = coords_rect$size * .pt,
lty = coords_rect$linetype,
linejoin = linejoin,
lineend = if (identical(linejoin, "round")) "round" else "square"
)
)
# Knobs ----
coords <- coord$transform(data, panel_params)
# coords_knobs0 <<- coords
#Reverse calc for flipped
if(!is.null(coord$is_flipped) && coord$is_flipped()){
coords <- flip_coords(coords)
}
knobs_dims <- coords %>%
dplyr::mutate(brick_width = abs(xmax - xmin)/n_knob,
num_of_1x1s = (ymax-ymin) %/% brick_width,
knob_radius = brick_width * (5/8) * (1/2) )
# coords_knobs0a <<- knobs_dims
coords_knobs <- 1:max(knobs_dims$num_of_1x1s) %>%
purrr::map_dfr(function(kk){
dat <- knobs_dims %>%
dplyr::filter(num_of_1x1s >= kk) %>%
dplyr::mutate(y = ifelse(sign == 1,
ymin + (kk * brick_width) - brick_width/2,
ymax - (kk * brick_width) + brick_width/2))
if(two_knob){
dplyr::bind_rows(
dat %>% dplyr::mutate(x = xmin + brick_width/2),
dat %>% dplyr::mutate(x = xmax - brick_width/2)
)
} else {
dat %>% dplyr::mutate(x = xmin + brick_width/2)
}
})
# coords_knobs1 <<- coords_knobs
#Outline and text for dark colors
color_lum <- as.data.frame(t(col2rgb(coords_knobs$fill)/255))
coords_knobs$color_intensity <- 0.299*color_lum$red + 0.587*color_lum$green + 0.114*color_lum$blue
coords_knobs$text_alpha <- ifelse(coords_knobs$color_intensity <= thres_brick_lum(), 0.3, 0.3)
coords_knobs$text_col <- ifelse(coords_knobs$color_intensity <= thres_brick_lum(), "#CCCCCC", "#333333")
#Un-Reverse calc for flipped
if(!is.null(coord$is_flipped) && coord$is_flipped()){
coords_knobs <- flip_coords_xy(coords_knobs)
}
gm_knob_shadow <- grid::circleGrob(
coords_knobs$x + (1/4)*coords_knobs$knob_radius,
coords_knobs$y - (1/4)*coords_knobs$knob_radius,
r= coords_knobs$knob_radius,
default.units = "native",
gp = grid::gpar(
col = NA,
fill = alpha("#333333", 0.3),
size = coords_knobs$size * .pt,
lty = coords_knobs$linetype
)
)
gm_knob_base <- grid::circleGrob(
coords_knobs$x, coords_knobs$y,
r= coords_knobs$knob_radius,
default.units = "native",
gp = grid::gpar(
col = alpha(coords_knobs$text_col, coords_knobs$text_alpha),
fill = alpha(coords_knobs$fill, coords_knobs$alpha),
size = coords_knobs$size * .pt,
lty = coords_knobs$linetype
)
)
#Text ----
#Don't draw if there are more knobs than threshold size
n <- nrow(coords_knobs)
if (coords_knobs$knob_radius[1] < min_radius_for_text ) {
gm_knob_text <- grid::nullGrob()
} else {
lab <- data$label
if(any(nchar(lab) > 6)){
warning("aes `label` is too long and will be truncated. Please limit to 6 characters or less.")
lab <- substr(lab, 1, 6)
}
label_num <- nchar(lab)[1]
#Get view port size for initial text drawing...
vp_width = grid::convertWidth(unit(1, "snpc"), "mm", valueOnly=TRUE)
fs <- scales::rescale(vp_width, to=c(20, 7), from=c(120, 20))
gm_knob_text <- grid::textGrob(
lab,
coords_knobs$x, coords_knobs$y,
default.units = "native",
# hjust = data$hjust, vjust = data$vjust,
# rot = data$angle,
gp = grid::gpar(
col = alpha(coords_knobs$text_col, coords_knobs$text_alpha),
fontsize = fs,
cex = (3/8) * 0.75 * ((coords_knobs$knob_radius / 0.03)^(1/2)) * label_scale,
# fontfamily = data$family,
fontface = "bold"#,
# lineheight = data$lineheight
)
)
}
# Combine ----
ggplot2:::ggname("geom_brick_rect",
grid::grobTree(gm_brick,
gm_knob_shadow,
gm_knob_base,
gm_knob_text
))
},
draw_key = draw_key_brick
)
flip_coords <- function(dat){
dat$zmin <- dat$xmin
dat$zmax <- dat$xmax
dat$xmin <- dat$ymin
dat$xmax <- dat$ymax
dat$ymin <- dat$zmin
dat$ymax <- dat$zmax
dat$zmin <- NULL
dat$zmax <- NULL
return(dat)
}
flip_coords_xy <- function(dat){
dat$z <- dat$x
dat$x <- dat$y
dat$y <- dat$z
dat$z <- NULL
return(dat)
}
thres_brick_lum <- function(){
return(0.4)
}
+213
View File
@@ -0,0 +1,213 @@
#' Tile charts as Bricks - ggplot2 extension
#'
#' `geom_rect`, except bars look like LEGO(R) bricks.
#' @inheritParams ggplot2::geom_rect
#' @param label Character string to include as embossed text inside brick knobs. Maximum 6 characters.
#' @param label_scale Scale text size of label as a percentage.
#' @param simplified_threshold Maximum number of knobs on the plot before embossed label is suppressed.
#' @param use_bricks Array of brick sizes to use in mosaic. Defaults to \code{c('4x2', '2x2', '3x1', '2x1', '1x1')}`.
#' @family Graphs
#' @export
geom_brick_rect <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
label = "brickr", simplified_threshold = 24*24, label_scale = 1,
use_bricks = NULL,
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
layer_brick <- layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomBrick,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
linejoin = linejoin,
label = label,
label_scale = label_scale,
use_bricks = use_bricks,
na.rm = na.rm,
simplified_threshold = simplified_threshold,
...
)
)
return(layer_brick)
}
#' GeomBrick
#'
#' ggproto for brickr geoms
#'
#' @rdname brickr-ggproto
#' @format NULL
#' @usage NULL
GeomBrick <- ggproto("GeomBrick", Geom,
default_aes = aes(colour = "#333333", fill = "#B40000", size = 0.5, linetype = 1,
alpha = NA, label = "brickr", label_scale = 1,
angle = 0, family = "", fontface = 1, lineheight = 1.2),
required_aes = c("x", "y"),
setup_data = function(data, params) {
#This data manipulation happens BEFORE splitting the data into the PANEL
return(data)
},
draw_panel = function(self, data, panel_params, coord, linejoin = "mitre",
simplified_threshold = 24*24, label_scale = 1,
use_bricks = use_bricks) {
#This happens to EACH panel
if (!coord$is_linear()) {
stop("geom_brick_rect must be used with linear coordinates")
} else {
#Brick border ----
points_to_rects <- function(data){
#Probably super frowned upon to use dplyr inside of a ggproto, but this simplifies the data that can be fed into geom
data$Level <- as.numeric(data$PANEL)
if(is.null(data$fill)){
data$Lego_name <- "#B40000"
data$Lego_color <- "#B40000"
}else{
data$Lego_name <- data$fill
data$Lego_color <- data$fill
}
dat <- collect_bricks(list(Img_lego = data),
use_bricks = use_bricks)$Img_bricks
dat <- transform(dat,
PANEL = Level, Level = NULL,
fill = Lego_color)
# print(dat)
return(dat)
}
coords_rect <- coord$transform(data %>% points_to_rects, panel_params) %>%
dplyr::mutate(size = data$size[1], linetype = data$linetype[1],
colour = data$colour[1], alpha = data$alpha[1])
gm_brick <- grid::rectGrob(
coords_rect$xmin, coords_rect$ymax,
width = coords_rect$xmax - coords_rect$xmin,
height = coords_rect$ymax - coords_rect$ymin,
default.units = "native",
just = c("left", "top"),
gp = grid::gpar(
col = alpha(coords_rect$colour, 0.2),
fill = alpha(coords_rect$fill, coords_rect$alpha),
lwd = coords_rect$size * .pt,
lty = coords_rect$linetype,
linejoin = linejoin,
# `lineend` is a workaround for Windows and intentionally kept unexposed
# as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667)
lineend = if (identical(linejoin, "round")) "round" else "square"
)
)
# Knob ----
coords <- coord$transform(data, panel_params)
# test_coord <<- coords
x_size <- median(abs(diff(coords$x))[abs(diff(coords$x))>0], na.rm=TRUE)
y_size <- median(abs(diff(coords$y))[abs(diff(coords$y))>0], na.rm=TRUE)
diameter <- max(x_size, y_size, na.rm=TRUE)
#Nudge the shadow down and right by a 1/4 knob radius
coords_nudge <- ggplot2::transform_position(coords,
function(x) x + x_size*(5/8)*(1/2)*(1/4),
function(y) y - y_size*(5/8)*(1/2)*(1/4))
#Outline and text for dark colors
color_lum <- as.data.frame(t(col2rgb(coords$fill)/255))
coords$color_intensity <- 0.299*color_lum$red + 0.587*color_lum$green + 0.114*color_lum$blue
coords$text_alpha <- ifelse(coords$color_intensity <= thres_brick_lum(), 0.3, 0.3)
coords$text_col <- ifelse(coords$color_intensity <= thres_brick_lum(), "#CCCCCC", "#333333")
gm_knob_shadow <- grid::circleGrob(
coords_nudge$x,
coords_nudge$y,
r= diameter*(5/8)*(1/2),
default.units = "native",
gp = grid::gpar(
col = NA,
fill = alpha("#333333", 0.2),
size = coords$size * .pt,
lty = coords$linetype
)
)
gm_knob_base <- grid::circleGrob(
coords$x, coords$y,
r= diameter*(5/8)*(1/2),
default.units = "native",
gp = grid::gpar(
# col = alpha("#333333", 0.2),
col = alpha(coords$text_col, coords$text_alpha),
fill = alpha(coords$fill, coords$alpha),
size = coords$size * .pt,
lty = coords$linetype
)
)
#Text ----
#Don't draw if mosaic is larger than threshold size
n <- nrow(data)
if (n > simplified_threshold | data$label[1] == "") {
gm_knob_text <- grid::nullGrob()
} else {
lab <- data$label
if(any(nchar(lab) > 6)){
warning("aes `label` is too long and will be truncated. Please limit to 6 characters or less.")
lab <- substr(lab, 1, 6)
}
label_num <- nchar(lab)[1]
#Get view port size for initial text drawing...
vp_width = grid::convertWidth(unit(1, "snpc"), "mm", valueOnly=TRUE)
fs <- scales::rescale(vp_width, to=c(20, 7), from=c(120, 20))
gm_knob_text <- grid::textGrob(
lab,
coords$x, coords$y,
default.units = "native",
hjust = data$hjust, vjust = data$vjust,
rot = data$angle,
gp = grid::gpar(
col = alpha(coords$text_col, coords$text_alpha),
fontsize = fs,
cex = label_scale * (3/8) * 0.5 * (1.5) * ((100/n)^(1/2)), #100 bricks is optimal size for labels by default?
fontfamily = data$family,
fontface = "bold",
lineheight = data$lineheight
)
)
}
# Combine ----
ggplot2:::ggname("geom_brick_rect",
grid::grobTree(gm_brick,
gm_knob_shadow, gm_knob_base,
gm_knob_text
))
}
},
draw_key = draw_key_brick
)
+37
View File
@@ -0,0 +1,37 @@
#' Create a 2D LEGO mosaic from an image array
#'
#' @param img Image to convert into mosaic. Usually from \code{jpeg::readJPEG()} or \code{png::readPNG()}.
#' @param img_size Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. \code{48}) for a square image with 48 pixels on each side.
#' Use an array of two values for a rectangular image \code{c(width, height)}.
#' @param method The method to use for comparison. Either 'brickr_classic', 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'.
#' 'brickr_classic' is an explicit euclidean distance formula, but yield different results than 'euclidean' in {farver}.
#' See \code{farver::compare_colour}.
#' @param color_table Defaults to \code{lego_colors}. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels.
#' See attached data \code{lego_colors} as examples.
#' @param color_palette Brick color rarity to use. Defaults to all colors: 'universal' (most common), 'generic', and 'special' (least common). This is useful when trying to build the mosaic out of real bricks.
#' Use "bw" for only grayscale bricks. Ignored if a \code{color_table} is supplied.
#' @param use_bricks Array of brick sizes to use in mosaic. Defaults to \code{c('4x2', '2x2', '3x1', '2x1', '1x1')}`.
#' @param dithering Improves color of large, photo-realistic mosaics.
#' @param brightness A value >1 will increase the brightness of the image while a positive value <1 will decrease the brightness.
#' @param warhol Array of values \code{c(1, 2, 3)} associated with R, G, B color channels. Swap values in array to swap color channels for a fun visual effect.
#' @param contrast For \code{theme = "bw"}. A value >1 will increase the contrast of the image while a positive value <1 will decrease the contrast.
#' @return A list with element \code{Img_lego} containing a data frame of the x- & y-coordinates, R, G, B channels, and mapped color of each brick (pixel).
#' @family Mosaics
#' @export
#'
image_to_mosaic <- function(img, img_size = 48, color_table = NULL,
method = "cie94",
color_palette = c("universal", "generic", "special"),
dithering = FALSE, contrast = 1,
use_bricks = NULL,
brightness = 1, warhol = 1:3){
in_list <- img %>%
image_to_scaled(img_size = img_size, brightness = brightness, warhol = warhol) %>%
scaled_to_colors(method = method,
color_table = color_table, color_palette = color_palette,
dithering = dithering, contrast = contrast) %>%
collect_bricks(use_bricks = use_bricks)
return(in_list)
}
+299
View File
@@ -0,0 +1,299 @@
#' Scale an image raster array to a small number of pixels. Process into a data frame. Internal function.
#'
#' @param image A raster array from an image.
#' @param img_size Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. \code{48}) for a square image with 48 pixels on each side.
#' Use an array of two values for a rectangular image \code{c(width, height)}.
#' @param brightness A value >1 will increase the brightness of the image while a positive value <1 will decrease the brightness.
#' @param warhol Array of values \code{c(1, 2, 3)} associated with R, G, B color channels. Swap values in array to swap color channels for a fun visual effect.
#' @format NULL
#' @usage NULL
#' @return A list with element \code{Img_scaled} containing a data frame of the x- & y-coordinates, R, G, B channels, and hex color of each brick (pixel).
#' @keywords internal
image_to_scaled <- function(image, img_size = 48, brightness = 1, warhol = 1:3){
#Adjust brightness. Max channel value is 1
if(brightness < 0 ){stop("brightness should be a positive value. Use 1 for no change, >1 for lighter, <1 for darker.")}
image_b <- image*brightness
image_b[image_b>1] <- 1
#Only whole values for image size
img_size <- round(img_size, 0)
#RGB channel order as specified with the `warhol` input
col_chan <- order(warhol[1:3])
#Convert image to a data frame with RGB values
img <- dplyr::bind_rows(
list(
(as.data.frame(image_b[, , col_chan[1]]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "R")),
(as.data.frame(image_b[, , col_chan[2]]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "G")),
(as.data.frame(image_b[, , col_chan[3]]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "B"))
)
) %>%
tidyr::gather(x, value, -y, -channel) %>%
dplyr::mutate(x = as.numeric(gsub("V", "", x))) %>%
tidyr::spread(channel, value)
#If png, drop the transparent bricks
if(dim(image_b)[3] == 4){
transparent <- as.data.frame(image_b[, , 4]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "Tr") %>%
tidyr::gather(x, value, -y, -channel) %>%
dplyr::mutate(x = as.numeric(gsub("V", "", x))) %>%
tidyr::spread(channel, value) %>%
dplyr::filter(Tr < 1)
img <- img %>%
dplyr::anti_join(transparent, by = c("y", "x"))
}
#Wide or tall image? Shortest side should be `img_size` pixels
if(max(img$x) > max(img$y)){
img_scale_x <- max(img$x) / max(img$y)
img_scale_y <- 1
} else {
img_scale_x <- 1
img_scale_y <- max(img$y) / max(img$x)
}
#If only 1 img_size value, create a square image
if(length(img_size) == 1){
img_size2 <- c(img_size, img_size)
} else {
img_size2 <- img_size[1:2]
img_scale_x <- 1
img_scale_y <- 1
}
#Rescale the image
img2 <- img %>%
dplyr::mutate(y_scaled = (y - min(y))/(max(y)-min(y))*img_size2[2]*img_scale_y + 1,
x_scaled = (x - min(x))/(max(x)-min(x))*img_size2[1]*img_scale_x + 1) %>%
dplyr::select(-x, -y) %>%
dplyr::group_by(y = ceiling(y_scaled), x = ceiling(x_scaled)) %>%
#Get average R, G, B and convert it to hexcolor
dplyr::summarize_at(dplyr::vars(R, G, B), mean) %>%
dplyr::rowwise() %>%
dplyr::mutate(color = rgb(R, G, B)) %>%
dplyr::ungroup() %>%
#Center the image
dplyr::filter(x <= median(x) + img_size2[1]/2, x > median(x) - img_size2[1]/2,
y <= median(y) + img_size2[2]/2, y > median(y) - img_size2[2]/2) %>%
#Flip y
dplyr::mutate(y = (max(y) - y) + 1)
out_list <- list()
out_list[["Img_scaled"]] <- img2
return(out_list)
}
#' Convert image output from scale_image() to bricks
#'
#' @param image_list List output from scale_image(). Contains an element \code{Img_scaled}.
#' @param method The method to use for comparison. Either 'brickr_classic', 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'.
#' 'brickr_classic' is an explicit euclidean distance formula, but yield different results than 'euclidean' in {farver}.
#' See \code{farver::compare_colour}.
#' @param color_table Defaults to \code{lego_colors}. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels.
#' See attached data \code{lego_colors} as examples.
#' @param color_palette Brick color rarity to use. Defaults to all colors: 'universal' (most common), 'generic', and 'special' (least common). This is useful when trying to build the mosaic out of real bricks.
#' Use "bw" for only grayscale bricks. Ignored if a \code{color_table} is supplied.
#' @param dithering Improves color of large, photo-realistic mosaics.
#' @param contrast For \code{color_palette = "bw"}. A value >1 will increase the contrast of the image while a positive value <1 will decrease the contrast.
#' @format NULL
#' @usage NULL
#' @keywords internal
#' @return A list with element \code{Img_lego} containing a data frame of the x- & y-coordinates, R, G, B channels, and mapped color of each brick (pixel).
scaled_to_colors <- function(image_list, method = "cie94",
color_table = NULL,
color_palette = c("universal", "generic", "special"),
dithering = FALSE,
contrast = 1){
in_list <- image_list
#Brick colors to use ----
if(is.null(color_table)) {
brick_table <- lego_colors
} else{
brick_table <- color_table
}
#Set up color palette... used standard way or with Dithering
if(any(c("universal", "generic", "special") %in% color_palette)){
brick_table <- brick_table %>%
dplyr::filter(tolower(Palette) %in% color_palette)
} else {
#Black and white is simpler... cut the colors into 4 groups, then assign lightest = white, darkest = black
brick_table <- lego_colors %>%
dplyr::filter(Color %in% c("White", "Black", "Medium stone grey", "Dark stone grey")) %>%
dplyr::arrange((R_lego + G_lego + B_lego)) %>%
dplyr::mutate(Lego_color = grDevices::rgb(R_lego, G_lego, B_lego))
}
#Standard or dithering
if(!dithering){
img <- convert_color_to_brick_standard(in_list$Img_scaled, color_table, brick_table,
color_palette, method, contrast)
} else {
img <- convert_color_to_brick_dithering(in_list$Img_scaled, color_table, brick_table,
color_palette, method)
}
#Return output....
in_list[["Img_lego"]] <- img %>%
dplyr::mutate(Level = 1)
in_list[["brickr_object"]] <- "mosaic"
return(in_list)
}
convert_color_to_brick_standard <- function(img_object, color_table, brick_table, color_palette, method, contrast){
#Standard bricks ----
# Two condition... not-supplied color_table & standard palette - or - a supplied color_table
if((is.null(color_table) & any(c("universal", "generic", "special") %in% color_palette)) |
!is.null(color_table)){
#Speed up calc by round pixel to nearest 1/20 & only calculating unique
mosaic_base <- img_object %>%
dplyr::mutate_at(dplyr::vars(R, G, B), list(~round(.*20)/20)) %>%
dplyr::select(R, G, B) %>%
dplyr::distinct()
#Match colors either the old way or with Farver ----
if(method == "brickr_classic"){
mosaic_colors <- mosaic_base %>%
dplyr::mutate(lego = purrr::pmap(list(R, G, B), convert_to_match_color, brick_table)) %>%
tidyr::unnest(lego)
} else { #Farver ----
mosaic_colors <- mosaic_base %>%
dplyr::mutate(rgb = purrr::pmap(list(R, G, B), function(R, G, B){
cc <- matrix(c(R, G, B), ncol = 3)
dstncs <- farver::compare_colour(from=cc, to=brick_table[, c('R_lego', 'G_lego', 'B_lego')],
from_space='rgb', to_space = 'rgb', method=method)
sel_color <- as.character(brick_table[which.min(dstncs), "Color"])[1]
brick_table %>%
dplyr::filter(Color == sel_color) %>%
dplyr::mutate(Lego_color = grDevices::rgb(R_lego, G_lego, B_lego)) %>%
dplyr::select(Lego_name = Color, Lego_color)
})) %>%
tidyr::unnest(rgb)
}
img <- img_object %>%
dplyr::mutate_at(dplyr::vars(R, G, B), list(~round(.*20)/20)) %>%
dplyr::left_join(mosaic_colors, by = c("R", "G", "B"))
return(img)
} else if ("bw" %in% color_palette){
img <- img_object %>%
dplyr::mutate(shade = (0.299*R+0.587*G+0.114*B)/3,
shade = shade ^ contrast) %>%
dplyr::mutate(shade_bw = as.numeric(as.factor(cut(shade, 4)))) %>%
dplyr::mutate(Lego_name = brick_table$Color[shade_bw],
Lego_color = brick_table$Lego_color[shade_bw]) %>%
dplyr::select(-dplyr::starts_with("shade"))
return(img)
} else {
stop("Either you must supply a color_table or use an accepted color_palette:
a combination of ('universal', 'generic', and/or 'special') - or- 'bw'")
}
}
convert_color_to_brick_dithering <- function(img_object, color_table, brick_table, color_palette, method){
#Standard bricks ----
# Two condition... not-supplied color_table & standard palette - or - a supplied color_table
if((is.null(color_table) & any(c("universal", "generic", "special", "bw") %in% color_palette)) |
!is.null(color_table)){
#Speed up calc by round pixel to nearest 1/20 & only calculating unique
mosaic_base <- img_object
#Ignore brickr_classic for now
if(method == "brickr_classic") {
method <- "cie94"
}
mosaic_base$Lego_color <- NA
mosaic_base$Lego_name <- NA
for(yy in unique(mosaic_base$y)){
for(xx in unique(mosaic_base$x)){
dstncs <- mosaic_base[mosaic_base$x == xx & mosaic_base$y == yy, c("R", "G", "B")] %>%
as.matrix(ncol = 3) %>%
farver::compare_colour(to=brick_table[, c('R_lego', 'G_lego', 'B_lego')],
from_space='rgb', to_space = 'rgb', method=method)
#Assign LEGO color for this cell
mosaic_base[mosaic_base$x == xx & mosaic_base$y == yy, c("Lego_name", "Lego_color")] <-
brick_table[which.min(dstncs), c("Color", "hex")]
#Difference in color
dith_diff <- mosaic_base[mosaic_base$x == xx & mosaic_base$y == yy, c("R", "G", "B")] -
brick_table[which.min(dstncs), c("R_lego", "G_lego", "B_lego")]
# dith_diff <- dith_diff*c(0.299, 0.587, 0.114)
#Update color of surrounding pixels.. if pixel exists
if(xx < max(mosaic_base$x)){
xs <- 1; ys <- 0;
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] <-
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] + (7/16)*dith_diff
}
if(yy > min(mosaic_base$y)){
xs <- 0; ys <- -1;
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] <-
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] + (5/16)*dith_diff
}
if(xx > min(mosaic_base$x) & yy > min(mosaic_base$y)){
xs <- -1; ys <- -1;
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] <-
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] + (3/16)*dith_diff
}
if(xx < max(mosaic_base$x) & yy > min(mosaic_base$y)){
xs <- 1; ys <- -1;
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] <-
mosaic_base[(mosaic_base$x == (xx+xs)) & (mosaic_base$y == (yy+ys)), c("R", "G", "B")] + (1/16)*dith_diff
}
#Ensure RGBs [0,1]
mosaic_base[mosaic_base$R > 1, "R"] <- 1
mosaic_base[mosaic_base$G > 1, "G"] <- 1
mosaic_base[mosaic_base$B > 1, "B"] <- 1
mosaic_base[mosaic_base$R < 0, "R"] <- 0
mosaic_base[mosaic_base$G < 0, "R"] <- 0
mosaic_base[mosaic_base$B < 0, "R"] <- 0
}
}
return(mosaic_base)
} else {
stop("Either you must supply a color_table or use an accepted color_palette:
a combination of ('universal', 'generic', and/or 'special') - or- 'bw'")
}
}
convert_to_match_color <- function(R, G, B, dat_color){
dat_color %>%
dplyr::mutate(dist = ((R_lego - R)^2 + (G_lego - G)^2 + (B_lego - B)^2)^(1/2)) %>%
dplyr::top_n(-1, dist) %>%
dplyr::mutate(Lego_color = grDevices::rgb(R_lego, G_lego, B_lego)) %>%
dplyr::select(Lego_name = Color, Lego_color)
}
-131
View File
@@ -1,131 +0,0 @@
#' Convert image output from scale_image() to bricks
#'
#' @param image_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @param mosaic_height Maximum height of 3D mosiacs in LEGO plates. 3 plates = 1 brick. This is also the maximum # of distinct elevations.
#' @param highest_el Brick height is determined by brightness of color. Use \code{highest_el = 'dark'} for darkest bricks to have \code{mosaic_height}.
#' @return A list with elements \code{threed_elevation} and \code{threed_hillshade} to created 3D mosiacs with the \code{rayshader} package.
#' @export
#'
collect_3d <- function(image_list, mosaic_height = 6, highest_el = "light"){
#Get previous data
in_list <- image_list
if(in_list$mosaic_type != "flat")stop("3D mosaics can only be generated with 'flat' mosaics. Set this input in the 'collect_bricks' function.")
BrickIDs <- in_list$ID_bricks
img_lego <- in_list$Img_lego
#Number of 'pixels' on a side of a single-stud brick. I think this should be fixed for now
ex_size <- 15
lego_expand <- img_lego %>%
dplyr::select(x, y, Lego_name, Lego_color) %>%
dplyr::mutate(stud_id = dplyr::row_number())
lego_expand2 <- expand.grid(x = (min(lego_expand$x)*ex_size):(max(lego_expand$x+1)*ex_size),
y = (min(lego_expand$y)*ex_size):(max(lego_expand$y+1)*ex_size)) %>%
dplyr::mutate(x_comp = x %/% ex_size,
y_comp = y %/% ex_size) %>%
dplyr::left_join(lego_expand %>% dplyr::rename(x_comp = x, y_comp = y),
by = c("x_comp", "y_comp")) %>%
dplyr::left_join(BrickIDs %>% dplyr::select(brick_id, x_comp = x, y_comp = y),
by = c("x_comp", "y_comp")) %>%
dplyr::select(-x_comp, -y_comp) %>%
dplyr::left_join(lego_colors %>% dplyr::select(Lego_name = Color, R_lego, G_lego, B_lego),
by = "Lego_name") %>%
dplyr::do(
if(highest_el == "dark"){
dplyr::mutate(., elevation = (1-((R_lego + G_lego + B_lego )/3)) * 1000)
} else {
dplyr::mutate(., elevation = ( ((R_lego + G_lego + B_lego )/3)) * 1000)
}
) %>%
#Round elevation to nearest 1/height
dplyr::mutate(elevation = as.numeric(as.factor(cut(elevation, mosaic_height)))) %>%
dplyr::mutate(y = max(y)-y) %>%
dplyr::filter(!is.na(elevation)) %>%
#Calculate stud placement... radius of 1/3 and height of 0.5 plate
dplyr::group_by(stud_id) %>%
dplyr::mutate(x_mid = median(x), y_mid = median(y),
stud = ((x-x_mid)^2 + (y-y_mid)^2)^(1/2) < ex_size/3) %>%
dplyr::ungroup() %>%
dplyr::mutate(elevation = ifelse(stud, elevation+0.5, elevation)) %>%
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego), dplyr::funs(ifelse(stud, .-0.1, .))) %>%
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego), dplyr::funs(ifelse(. < 0, 0, .)))
edges <- dplyr::bind_rows(list(
lego_expand2 %>% dplyr::filter(x == min(x)) %>% dplyr::mutate(x = x-1),
lego_expand2 %>% dplyr::filter(x == max(x)) %>% dplyr::mutate(x = x+1),
lego_expand2 %>% dplyr::filter(y == min(y)) %>% dplyr::mutate(y = y-1),
lego_expand2 %>% dplyr::filter(y == max(y)) %>% dplyr::mutate(y = y+1)
)) %>%
dplyr:: mutate(R_lego = 1, G_lego = 1, B_lego = 1,
elevation = 0,
brick_id = NA)
#Elevation Matrix
lego_elmat <- lego_expand2 %>%
dplyr::bind_rows(edges) %>%
dplyr::select(x, y, elevation) %>%
tidyr::spread(y, elevation) %>%
dplyr::select(-x) %>%
as.matrix()
#Hillshade matrix
lego_hillshade_m <- array(dim = c(length(unique(lego_expand2$y)),
length(unique(lego_expand2$x)),
3))
lego_expand_color <- lego_expand2 %>%
dplyr::group_by(brick_id) %>%
#This darkens the edge of each brick, to look like they are separated
dplyr::mutate_at(dplyr::vars(R_lego, G_lego, B_lego),
dplyr::funs(ifelse((x == min(x) | y == min(y) | x == max(x) | y == max(y)), .*0.75, .))) %>%
dplyr::ungroup()
lego_hillshade_m[,,1] <- lego_expand_color %>%
dplyr::select(x, y, R_lego) %>%
tidyr::spread(x, R_lego) %>%
dplyr::select(-y) %>%
as.matrix()
lego_hillshade_m[,,2] <- lego_expand_color %>%
dplyr::select(x, y, G_lego) %>%
tidyr::spread(x, G_lego) %>%
dplyr::select(-y) %>%
as.matrix()
lego_hillshade_m[,,3] <- lego_expand_color %>%
dplyr::select(x, y, B_lego) %>%
tidyr::spread(x, B_lego) %>%
dplyr::select(-y) %>%
as.matrix()
#Return
in_list[["threed_elevation"]] <- lego_elmat
in_list[["threed_hillshade"]] <- lego_hillshade_m
return(in_list)
}
#' brickr wrapper for rayshader::plot_3d() to display 3D mosaics. Requires rayshader.
#'
#' @param image_list List output from collect_3d(). Contains element \code{threed_elevation} and \code{threed_hillshade}.
#' @param solidcolor Hex color of mosaic base. Only renders on bottom.
#' @param ... All other inputs from rayshader::plot_3d() EXCEPT \code{hillshade}, \code{soliddepth}, and \code{zscale}.
#' @return 3D mosaic rendered in the 'rgl' package.
#' @export
display_3d <- function(image_list, solidcolor = "#a3a2a4", ...){
#Requires Rayshader
if (!requireNamespace("rayshader", quietly = TRUE)) {
stop("Package \"rayshader\" needed for this function to work. Please install it.",
call. = FALSE)
}
image_list$`threed_hillshade`%>%
rayshader::plot_3d(image_list$`threed_elevation`, zscale=0.125,
solidcolor=solidcolor, ...)
}
-91
View File
@@ -1,91 +0,0 @@
#' Helper function to match an RGB color to a subset of allowed colors
#'
#' @param R,G,B R, G, and B color values between 0 and 1.
#' @param dat_color Data frame of allowed color. Use the attached data \code{lego_colors.rda}.
#' @return A data frame of a matched color with closest Euclidean distance to the input R, G, & B.
#' @export
#'
convert_to_match_color <- function(R, G, B, dat_color){
dat_color %>%
dplyr::mutate(dist = ((R_lego - R)^2 + (G_lego - G)^2 + (B_lego - B)^2)^(1/2)) %>%
dplyr::top_n(-1, dist) %>%
dplyr::mutate(Lego_color = grDevices::rgb(R_lego, G_lego, B_lego)) %>%
dplyr::select(Lego_name = Color, Lego_color)
}
#' Convert image output from scale_image() to bricks
#'
#' @param image_list List output from scale_image(). Contains an element \code{Img_scaled}.
#' @param color_table Defaults to \code{lego_colors}. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels. See attached data \code{lego_colors} as examples.
#' @param theme Theme of brick colors to use. Set to \code{"bw"} for grayscale mosaics.
#' @param contrast For \code{theme = "bw"}. A value >1 will increase the contrast of the image while a positive value <1 will decrease the contrast.
#' @return A list with element \code{Img_lego} containing a data frame of the x- & y-coordinates, R, G, B channels, and mapped color of each brick (pixel).
#' @export
#'
legoize <- function(image_list, color_table = lego_colors, theme = "default", contrast = 1){
in_list <- image_list
if(theme == "default"){
#Speed up calc by round pixel to nearest 1/20 & only calculating unique
mosaic_colors <- in_list$Img_scaled %>%
dplyr::mutate_at(dplyr::vars(R, G, B), dplyr::funs(round(.*20)/20)) %>%
dplyr::select(R, G, B) %>%
dplyr::distinct() %>%
dplyr::mutate(lego = purrr::pmap(list(R, G, B), convert_to_match_color, color_table)) %>%
tidyr::unnest(lego)
img <- in_list$Img_scaled %>%
dplyr::mutate_at(dplyr::vars(R, G, B), dplyr::funs(round(.*20)/20)) %>%
dplyr::left_join(mosaic_colors, by = c("R", "G", "B"))
} else if (theme == "bw"){
#Black and white is simpler... cut the colors into 4 groups, then assign lightest = white, darkest = black
bw_colors <- color_table %>%
dplyr::filter(t_BW) %>%
dplyr::arrange((R_lego + G_lego + B_lego)) %>%
dplyr::mutate(Lego_color = grDevices::rgb(R_lego, G_lego, B_lego))
img <- in_list$Img_scaled %>%
dplyr::mutate(shade = (R+G+B)/3,
shade = shade ^ contrast) %>%
dplyr::mutate(shade_bw = as.numeric(as.factor(cut(shade, 4)))) %>%
dplyr::mutate(Lego_name = bw_colors$Color[shade_bw],
Lego_color = bw_colors$Lego_color[shade_bw]) %>%
dplyr::select(-dplyr::starts_with("shade"))
}
in_list[["Img_lego"]] <- img %>%
dplyr::mutate(Level = 1)
return(in_list)
}
#' Display a table and plot of possible brick colors & their ID numbers
#' @param .names_only Return an array of the 39 brick color names. Does not plot.
#' @return A table and ggplot of brick colors & ID numbers.
#' @export
#'
display_colors <- function(.names_only = FALSE){
if(.names_only){
return(lego_colors$Color)
}
message("Use View(lego_colors) to see these in a table format.")
lego_colors %>%
dplyr::mutate(Label = paste0(brickrID, "\n", Color)) %>%
ggplot2::ggplot(ggplot2::aes(x = brickrID %% 6, y = (6 - (brickrID %/% 6)))) +
ggplot2::geom_tile(ggplot2::aes(fill = hex),color = "white", size = 2) +
ggplot2::scale_fill_identity() +
ggplot2::geom_label(ggplot2::aes(label = Label)) +
ggplot2::labs(title = "Brick Colors by {brickr} ID# and LEGO Name",
subtilte = "See included data frame 'lego_colors'") +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank())
}
+80
View File
@@ -0,0 +1,80 @@
#' Generate required bricks as a data frame.
#'
#' @param brick_obj brickr mosaic or 3D model object.
#' @return Data frame of piece counts by LEGO color name and size.
#' @family Resources
#' @export
build_pieces_table <- function(brick_obj){
pcs <- brick_obj$pieces
pcs %>%
dplyr::select(-Lego_color) %>%
tidyr::spread(Brick_size, n, fill = 0) %>%
dplyr::rename(`LEGO Brick Color` = Lego_name)
}
#' Display bricks required to build model or mosaic.
#'
#' @param brick_obj brickr mosaic or 3D model object.
#' @return Plot object of required bricks by color and size.
#' @family Resources
#' @export
#'
build_pieces <- function(brick_obj){
in_list <- brick_obj
pcs <- in_list$pieces
pcs_coords <- dplyr::tibble(
Brick_size = c("1 x 1", "2 x 1", "3 x 1", "4 x 1", "2 x 2", "4 x 2"),
xmin = c(0, 0, 0, 0, 6, 6),
xmax = c(1, 2, 3, 4, 8, 8),
ymin = c(0, 2, 4, 6, 0, 3),
ymax = c(1, 3, 5, 7, 2, 7)
)
#This function creates nodes in each brick for stud placement
pcs_coords <- pcs_coords %>%
dplyr::mutate(studs = purrr::pmap(list(xmin, xmax, ymin, ymax), function(a, b, c, d){
expand.grid(x=seq(a+0.5, b-0.5, by=1),
y=seq(c+0.5, d-0.5, by=1))
}))
pcs2 <- pcs %>%
dplyr::arrange(Lego_color) %>%
dplyr::mutate(Lego_name = factor(Lego_name,
levels = c("Black",
unique(Lego_name)[!(unique(Lego_name) %in% c("Black", "White"))],
"White"))) %>%
dplyr::left_join(pcs_coords, by = "Brick_size")
coord_xlim <- c(-0.5, 10)
facet_cols <- 5
pcs2 %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=-ymin, ymax=-ymax,
fill = Lego_color), color = "#333333")+
ggplot2::scale_fill_identity() +
ggplot2::geom_point(data = pcs2 %>% tidyr::unnest(studs),
ggplot2::aes(x=x, y=-y),
color = "#cccccc", alpha = 0.25,
shape = 1, size = 2) +
ggplot2::geom_text(
ggplot2::aes(x = xmax + 0.25, y = -(ymin+ymax)/2, label = paste0("x", n)),
hjust = 0, vjust = 0.5, size = 3.5) +
ggplot2::coord_fixed(xlim = coord_xlim) +
ggplot2::labs(title = "Suggested LEGO Bricks") +
ggplot2::facet_wrap(~Lego_name, ncol=facet_cols) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
panel.grid = ggplot2::element_blank())
}
-98
View File
@@ -1,98 +0,0 @@
#' Generate required bricks as a data frame.
#'
#' @param image_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @return Data frame of piece counts by LEGO color name and size.
#' @export
#'
table_pieces <- function(image_list){
pcs <- image_list$pieces
pcs %>%
dplyr::select(-Lego_color) %>%
tidyr::spread(Brick_size, n, fill = 0) %>%
dplyr::rename(`LEGO Brick Color` = Lego_name)
}
#' Graphically display required bricks.
#'
#' @param image_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @return Plot object of required bricks by color and size.
#' @export
#'
display_pieces <- function(image_list){
in_list <- image_list
pcs <- in_list$pieces
if(in_list$mosaic_type == "flat"){
pcs_coords <- dplyr::tibble(
Brick_size = c("1 x 1", "2 x 1", "3 x 1", "4 x 1", "2 x 2", "4 x 2"),
xmin = c(0, 0, 0, 0, 6, 6),
xmax = c(1, 2, 3, 4, 8, 8),
ymin = c(0, 2, 4, 6, 0, 3),
ymax = c(1, 3, 5, 7, 2, 7)
)
} else {
pcs_coords <- dplyr::tibble(
Brick_size = c("1 x 2", "2 x 2", "3 x 2", "4 x 2"),
xmin = c(0, 5, 5, 0),
xmax = c(2, 7, 7, 2),
ymin = c(0, 0, 3, 2),
ymax = c(1, 2, 6, 6)
)
}
#This function creates nodes in each brick for stud placement
pcs_coords <- pcs_coords %>%
dplyr::mutate(studs = purrr::pmap(list(xmin, xmax, ymin, ymax), function(a, b, c, d){
expand.grid(x=seq(a+0.5, b-0.5, by=1),
y=seq(c+0.5, d-0.5, by=1))
}))
pcs2 <- pcs %>%
dplyr::arrange(Lego_color) %>%
dplyr::mutate(Lego_name = factor(Lego_name,
levels = c("Black",
unique(Lego_name)[!(unique(Lego_name) %in% c("Black", "White"))],
"White"))) %>%
dplyr::left_join(pcs_coords, by = "Brick_size")
if(in_list$mosaic_type == "flat"){
coord_xlim <- c(-0.5, 10)
facet_cols <- 5
} else {
coord_xlim <- c(-0.5, 9)
facet_cols <- 6
}
pcs2 %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=-ymin, ymax=-ymax,
fill = Lego_color), color = "#333333")+
ggplot2::scale_fill_identity() +
ggplot2::geom_point(data = pcs2 %>% tidyr::unnest(studs),
ggplot2::aes(x=x, y=-y),
color = "#cccccc", alpha = 0.25,
shape = 1, size = 2) +
ggplot2::geom_text(
ggplot2::aes(x = xmax + 0.25, y = -(ymin+ymax)/2, label = paste0("x", n)),
hjust = 0, vjust = 0.5, size = 3.5) +
ggplot2::coord_fixed(xlim = coord_xlim) +
ggplot2::labs(title = (if(in_list$mosaic_type == "stacked"){
"Suggested LEGO Bricks"
}else{"Suggested LEGO Plates"}),
caption = (if(in_list$mosaic_type == "stacked"){
"Mosaic is 2-bricks deep. Can substitute 2-stud bricks for 1-stud alternatives for a thinner mosaic."}else{""})
) +
ggplot2::facet_wrap(~Lego_name, ncol=facet_cols) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
panel.grid = ggplot2::element_blank())
}
+39
View File
@@ -0,0 +1,39 @@
#' Color scales for bricks - ggplot2 extension
#'
#' brickr counterpart to \code{ggplot2::scale_fill_discrete()} to map bar colors to the palette of LEGO mold colors.
#'
#' @inheritParams ggplot2::scale_fill_manual
#' @param brick_theme Color palette for bricks. Same as \code{brickr::theme_brick()}. Options include:
#' \code{ c("classic", "hp", "sw_light", "sw_dark", "friends", "elves",
#' "ninja", "classy", "city", "ocean", "movie", "space",
#' "jurassic", "duplo", "superhero", "80s",
#' "rainbow7", "rainbow13", "doublerainbow", "blue")}.
#' @examples
#' df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
#' p <- ggplot(df, aes(trt, outcome)) +
#' geom_brick_col(aes(fill = trt)) +
#' coord_brick()
#'
#' p + scale_fill_brick()
#'
#' #Select a brick_theme and use with theme_brick()
#' tm <- "hp"
#' p +
#' scale_fill_brick(tm) +
#' theme_brick(tm)
#' @family Graphs
#' @export
scale_fill_brick <- function(brick_theme = "classic", ...) {
if(!(brick_theme %in% brickr_themes$theme)){
warning(paste0("Defaulting scale_brick() to 'classic'. Use a brick_theme included in brickr:\n",
paste(unique(brickr_themes$theme), collapse = ", ")))
brick_theme <- "classic"
}
values <- brickr_themes[brickr_themes$theme == brick_theme &
brickr_themes$index >= 1, ]
ggplot2:::manual_scale("fill", values = values$hex, ...)
}
-79
View File
@@ -1,79 +0,0 @@
#' Scale an image raster array to a small number of pixels. Process into a data frame.
#'
#' @param image A raster array from an image.
#' @param img_size Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. \code{48}) for a square image with 48 pixels on each side.
#' Use an array of two values for a rectangular image \code{c(width, height)}.
#' @param brightness A value >1 will increase the brightness of the image while a positive value <1 will decrease the brightness.
#' @param warhol Array of values \code{c(1, 2, 3)} associated with R, G, B color channels. Swap values in array to swap color channels for a fun visual effect.
#' @return A list with element \code{Img_scaled} containing a data frame of the x- & y-coordinates, R, G, B channels, and hex color of each brick (pixel).
#' @export
#'
scale_image <- function(image, img_size = 48, brightness = 1, warhol = 1:3){
#Adjust brightness. Max channel value is 1
if(brightness < 0 ){stop("brightness should be a positive value. Use 1 for no change, >1 for lighter, <1 for darker.")}
image_b <- image*brightness
image_b[image_b>1] <- 1
#Only whole values for image size
img_size <- round(img_size, 0)
#RGB channel order as specified with the `warhol` input
col_chan <- order(warhol[1:3])
#Convert image to a data frame with RGB values
img <- dplyr::bind_rows(
list(
(as.data.frame(image_b[, , col_chan[1]]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "R")),
(as.data.frame(image_b[, , col_chan[2]]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "G")),
(as.data.frame(image_b[, , col_chan[3]]) %>%
dplyr::mutate(y=dplyr::row_number(), channel = "B"))
)
) %>%
tidyr::gather(x, value, -y, -channel) %>%
dplyr::mutate(x = as.numeric(gsub("V", "", x))) %>%
tidyr::spread(channel, value)
#Wide or tall image? Shortest side should be `img_size` pixels
if(max(img$x) > max(img$y)){
img_scale_x <- max(img$x) / max(img$y)
img_scale_y <- 1
} else {
img_scale_x <- 1
img_scale_y <- max(img$y) / max(img$x)
}
#If only 1 img_size value, create a square image
if(length(img_size) == 1){
img_size2 <- c(img_size, img_size)
} else {
img_size2 <- img_size[1:2]
img_scale_x <- 1
img_scale_y <- 1
}
#Rescale the image
img2 <- img %>%
dplyr::mutate(y_scaled = (y - min(y))/(max(y)-min(y))*img_size2[2]*img_scale_y + 1,
x_scaled = (x - min(x))/(max(x)-min(x))*img_size2[1]*img_scale_x + 1) %>%
dplyr::select(-x, -y) %>%
dplyr::group_by(y = ceiling(y_scaled), x = ceiling(x_scaled)) %>%
#Get average R, G, B and convert it to hexcolor
dplyr::summarize_at(dplyr::vars(R, G, B), dplyr::funs(mean(.))) %>%
dplyr::rowwise() %>%
dplyr::mutate(color = rgb(R, G, B)) %>%
dplyr::ungroup() %>%
#Center the image
dplyr::filter(x <= median(x) + img_size2[1]/2, x > median(x) - img_size2[1]/2,
y <= median(y) + img_size2[2]/2, y > median(y) - img_size2[2]/2) %>%
#Flip y
dplyr::mutate(y = (max(y) - y) + 1)
out_list <- list()
out_list[["Img_scaled"]] <- img2
return(out_list)
}
+36
View File
@@ -0,0 +1,36 @@
#' Brick color themes - ggplot2 extension
#'
#' @param brick_theme Color palette for bricks. Same as \code{brickr::theme_brick()}. Options include:
#' \code{ c("classic", "hp", "sw_light", "sw_dark", "friends", "elves",
#' "ninja", "classy", "city", "ocean", "movie", "space",
#' "jurassic", "duplo", "superhero", "80s",
#' "rainbow7", "rainbow13", "doublerainbow", "blue")}.
#' @family Graphs
#' @export
theme_brick <- function(brick_theme = "classic"){
if(!(brick_theme %in% brickr_themes$theme)){
warning(paste0("Defaulting theme_brick() to 'classic'. Use a brick_theme included in brickr:\n",
paste(unique(brickr_themes$theme), collapse = ", ")))
brick_theme <- "classic"
}
values <- brickr_themes[brickr_themes$theme == brick_theme &
brickr_themes$index <= 0, ]
theme_base <- if(brick_theme %in% c("sw_dark", "space", "ninja", "jurassic", "superhero")){
ggplot2::theme_dark()
} else {
ggplot2::theme_minimal()
}
theme_base +
ggplot2::theme(
# plot.background = element_rect(fill = values$hex[1]),
panel.background = element_rect(fill = values$hex[1]),
panel.grid = element_blank(),
text = element_text(color = values$hex[2]),
legend.text = element_text(color = values$hex[2], size = 8)
)
}
+5 -1
View File
@@ -1,6 +1,6 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr]{\%>\%}} for details.
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
@@ -9,3 +9,7 @@
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL
"%||%" <- function(a, b) {
if (!is.null(a)) a else b
}
-103
View File
@@ -1,103 +0,0 @@
#' Display 2D mosaic output as a plot image
#'
#' @param image_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @param title Optional title to include above plotted mosaic.
#' @export
#'
display_set <- function(image_list, title=NULL){
in_list <- image_list
image <- in_list$Img_bricks
type <- in_list$mosaic_type
coord_x <- c(min(image$xmin)+0.5, max(image$xmax)-0.5)
coord_y <- c(min(image$ymin)+0.5, max(image$ymax)-0.5)
img <- ggplot2::ggplot(image) +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
fill = Lego_color), color = "#333333")+
ggplot2::scale_fill_identity()
if(type == "flat"){
img <- img +
ggplot2::geom_point(data = expand.grid(x=coord_x[1]:coord_x[2],
y=coord_y[1]:coord_y[2]),
ggplot2::aes(x=x, y=y),
color = "#333333", alpha = 0.2, shape = 1, size = 2) +
ggplot2::coord_fixed(expand = FALSE)
} else {
img <- img +
ggplot2::coord_fixed(ratio = 6/5, expand = FALSE)
}
img <- img +
ggplot2::labs(title = title) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank())
return(img)
}
#' Create instruction manual for 2D image mosaics
#'
#' @param image_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @param num_steps Number of discrete steps in instruction manual
#' @export
#'
generate_instructions <- function(image_list, num_steps=6) {
in_list <- image_list
image <- in_list$Img_bricks
type <- in_list$mosaic_type
num_steps <- min(abs(round(num_steps)), 40)
rows_per_step <- ceiling((max(image$ymax)-0.5) / (num_steps+1))
create_steps <- function(a, n_steps) {
if(a < n_steps){
image %>%
dplyr::group_by(brick_id) %>%
dplyr::filter(min(ymin) <= a*rows_per_step+(min(image$ymin)+0.5)) %>%
dplyr::ungroup() %>%
dplyr::mutate(Step = paste("Step", (if(a<10){paste0('0', a)}else{a})))
} else {
image %>%
dplyr::mutate(Step = paste("Step", (if(a<10){paste0('0', a)}else{a})))
}
}
#Ratio of the "pixels" is different for flat or stacked bricks
if(type == "flat"){
coord_ratio <- 1
} else {
coord_ratio <- 6/5
}
1:num_steps %>%
purrr::map(create_steps, num_steps) %>%
dplyr::bind_rows() %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
fill = Lego_color), color = "#333333") +
ggplot2::scale_fill_identity() +
ggplot2::coord_fixed(ratio = coord_ratio, expand = FALSE) +
ggplot2::facet_wrap(~Step) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank())
}
+92 -151
View File
@@ -1,5 +1,5 @@
---
title: "LEGO Mosaics in R"
title: "The LEGO&reg; System in R"
output:
github_document:
fig_width: 7.5
@@ -17,17 +17,30 @@ library(tidyverse)
```
# brickr <img src='man/figures/logo.png' align="right" height="138" />
<!-- <!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- <!-- badges: end -->
<!-- <!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- <!-- badges: end -->
## Overview
**brickr** is a package for creating LEGO-esque 2D and 3D models using the R [tidyverse](https://www.tidyverse.org/) and [Tyler Morgan-Wall](https://twitter.com/tylermorganwall)'s [rayshader](https://github.com/tylermorganwall/rayshader) package.
**brickr** is a package for bringing the LEGO&reg; experience into the R and [tidyverse](https://www.tidyverse.org/) ecosystem.
The package has two key uses:
The package is divided into 3 separate systems:
- Converting image files in to 2D and 3D LEGO mosaics
- Building 3D LEGO models from simple data frames
- [**Mosaics**](#mosaics): Convert image files into mosaics that could be built using LEGO&reg; bricks.
- [**3D Models**](#3d-models): Build 3D LEGO&reg; models from simple data formats & [rayshader](https://www.rayshader.com/).
- [**Charts**](#charts): A [ggplot2](https://ggplot2.tidyverse.org/) extension to generate plots that resemble LEGO&reg; bricks.
brickr also includes tools help users create the Mosaics and 3D model output using real LEGO&reg; elements.
### What's the point?
The goal of {brickr} is to provide a series of tools to integrate the LEGO&reg; system with R by:
- Enhancing a real world building experience with mosaics, generated instructions, and piece counts.
- Generating interest in R and coding for new audiences with easy-to-create 3D models.
- or just embracing pure novelty.
*brickr is developed using publicly available information about LEGO&reg; products and is not officially affiliated with The LEGO Group*
## Installation
``` r
@@ -38,19 +51,42 @@ devtools::install_github("ryantimpe/brickr")
#For 3D features, rayshader is also required.
install.packages("rayshader")
```
## Mosaics
The mosaic functions renders an imported JPG or PNG file using LEGO colors and bricks.
```{r m1_set, fig.width = 3, fig.height=3, echo = TRUE, message = FALSE, warning = FALSE}
mosaic1 <- png::readPNG("Images/mf_unicorn.PNG") %>%
image_to_mosaic(img_size = 36) #Length of each side of mosaic in "bricks"
#Plot 2D mosaic
mosaic1 %>% build_mosaic()
```
In general, any {brickr} function that begins with `build_` generates a graphical output from a {brickr} list object from other functions.
### Customization
`image_to_mosaic()` can take a few important arguments. See `?image_to_mosaic()` for full detail.
- `img_size` Providing a single value, such as `48`, crops the image to a square. Inputting a 2-element array, `c(56, 48)`, will output a rectangular image of `c(width, height)`.
- `color_table` & `color_palette` Options to limit the color of bricks used in mosaics, as not all colors produced by LEGO are readily available. Set `color_palette` to 'universal' or `c('universal', 'generic')` to limit colors to the most common ones. Use a subset of the data frame `lego_colors` as the `color_table` to specify a custom palette.
- `method` Technique used to map image colors into the allowed brick colors. Defaults to 'cie94`, but other options include 'cie2000' and 'euclidean'. Also includes the option 'brickr_classic', used in previous version of the package.
## 3D Models
Currently, 3D models can be built from one of two data input formats: `bricks_from_table()` or `bricks_from_coords()`.
The `bricks_from_*` series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using [Tyler Morgan-Wall](https://twitter.com/tylermorganwall)'s [rayshader](https://www.rayshader.com/) package.
**These functions are very experimental and will change. Better documentation will be released soon.**
- `bricks_from_table()` & `bricks_from_excel()` convert a matrix-shaped table of integers into LEGO bricks. For simple models, this table can be made manually using `data.frame()` or `tibble::tribble()`. For more advanced models, it's recommended you use MS Excel or a .csv file. The left-most column in the table is associated with the Level or z-axis of the model. `bricks_from_excel()` is a wrapper function to more easily build models designed using a Microsoft Excel template. Please see this repo: [brickr toybox](https://github.com/ryantimpe/brickr_toybox).
- `bricks_from_table()` converts a matrix-shaped table of integers into LEGO bricks. For simple models, this table can be made manually using `data.frame()` or `tibble::tribble()`. For more advanced models, it's recommended you use MS Excel or a .csv file. The left-most column in the table is associated with the Level or z-axis of the model. The function by default converts this to numeric for you. Each other column is an x-coordinate and each row is a y-coordinate. More flexible inputs will be available in a future release.
- `bricks_from_coords()` takes a data frame with `x`, `y`, & `z` integer values, and `Color` columns, where each combination of x, y, & z is a point in 3-dimensional space. Color must be an official LEGO color name from `build_colors()`. This format is much more flexible than `bricks_from_table()` and allows the programmatic development of 3D models.
- `bricks_from_excel()` is a wrapper function to more easily build models designed using a Microsoft Excel template. Please see this repo: [brickr toybox](https://github.com/ryantimpe/brickr_toybox).
-`bricks_from_mosaic()` converts a 2D [mosaic](#mosaics) object from an image into 3D LEGO models, respectively. `bricks_from_rayshader()` creates a LEGO model from the same input as `rayshader::plot_3d()`.
- `bricks_from_coords()` takes a data frame with `x`, `y`, & `z` integer values, and `Color` columns, where each combination of x, y, & z is a point in 3-dimensional space. Color must be an official LEGO color name from `display_colors()`. This format is much more flexible than `bricks_from_table()` and allows the programatic development of 3D models.
Pass the output from any `bricks_from_*()` function to `display_bricks()` to see the 3D model.
Pass the output from any `bricks_from_*()` function to `build_bricks()` to see the 3D model. The `brick_res` option allows for higher resolution bricks in 'hd' or 'uhd', which will take longer to render.
```{r bricks_1, echo=TRUE, warning=FALSE, message=FALSE, fig.width=3, fig.height=3}
library(brickr)
@@ -58,92 +94,22 @@ library(brickr)
#This is a brick
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
X2 = rep(3,4)
)
brick
brick %>%
bricks_from_table() %>%
display_bricks()
build_bricks(brick_res = "uhd")
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
```
### Brick Colors
There are 2 ways to assign the color of the bricks. The `display_colors()` function helps with ID numbers and names
- Use the `brickrID` value instead of '1' in the model input table. Values of '0' are blank spaces.
- Create a table of color assignments and pass this to `bricks_from_table()`
```{r bricks_2, echo=TRUE, warning=FALSE, message=FALSE, fig.width=3, fig.height=3}
brick_colors <- data.frame(
.value = 1,
Color = "Bright blue"
)
brick %>%
bricks_from_table(brick_colors) %>%
display_bricks()
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
rayshader::render_snapshot( clear = TRUE)
```
### Stacking bricks
The Level column in the input table determines the height of the bricks. `bricks_from_table()` will convert alphanumeric levels into a z coordinate.
The Level column in the input table determines the elevation of the bricks. `bricks_from_table()` will convert alphanumeric levels into a z coordinate.
```{r bricks_3, echo=TRUE, warning=FALSE, message=FALSE, fig.width=3, fig.height=4}
# A is the bottom Level, B is the top
brick <- data.frame(
Level= c(rep("A",4), rep("B",4)),
X1 = rep(1,4),
X2 = rep(1,4)
)
brick %>%
bricks_from_table(brick_colors) %>%
display_bricks()
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
```
The same process works with many levels
```{r bricks_4, echo=TRUE, warning=FALSE, message=FALSE, fig.width=6, fig.height=3}
#You can stack many bricks ----
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
)
#... And they can all be different colors ----
1:10 %>%
purrr::map_df(~dplyr::mutate(brick, Level = LETTERS[.x], X1 = .x, X2 = .x)) %>%
bricks_from_table() %>%
display_bricks()
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
```
# Full Models
For larger models, use `tibble::tribble()` to more easily visualize the model. For very large models, use MS Excel.
For larger models, use `tibble::tribble()` to more easily visualize the model. For very large models, use a csv or Excel.
```{r bricks_5, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
my_first_model <- tibble::tribble(
@@ -178,12 +144,9 @@ brick_colors <- tibble::tribble(
my_first_model %>%
bricks_from_table(brick_colors) %>%
display_bricks(theta = 210)
build_bricks(theta = 210, brick_res = "hd")
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
rayshader::render_snapshot(clear = TRUE)
```
### Programmatically build models
@@ -209,12 +172,9 @@ sphere_coords <- expand.grid(
sphere_coords %>%
bricks_from_coords() %>%
display_bricks(phi = 30, theta = 30)
build_bricks(phi = 30, theta = 30)
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
rayshader::render_snapshot(clear = TRUE)
```
### Examples
@@ -225,74 +185,55 @@ More examples using `bricks_from_table()` and `bricks_from_coords()` can be foun
- [**Build an owl**](https://gist.github.com/ryantimpe/ceab2ed6b8a4737077280fc9b0d1c886) with `bricks_from_table()` by manually placing each brick.
- Generate a punny [**random forest model**](https://gist.github.com/ryantimpe/a7363a5e99dceabada150a43925beec7) using `bricks_from_coords()` and {purrr}.
- [**brickr toybox**](https://github.com/ryantimpe/brickr_toybox) repo for tools and resources to get started.
## Charts
## Mosaics
brickr includes functions to render [ggplot2](https://ggplot2.tidyverse.org/) bar charts as bricks with LEGO color themes. The main function is `geom_brick_col()`, which is the brickr equivalent of `geom_col()`. Additional functions are highly recommended to ensure that proper the chart is rendered in the proper functions and proportions.
The mosaic functions renders an imported JPG or PNG file using LEGO colors and bricks. The resulting mosaic can be viewed in 2D and 3D. A full explanation can be found on [this blog post](http://www.ryantimpe.com/post/lego-mosaic1/), this [follow-up post](http://www.ryantimpe.com/post/lego-mosaic2/),and this [third post](http://www.ryantimpe.com/post/lego-mosaic3/).
```{r geom_brick, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
```{r m1_set, fig.width = 3, fig.height=3, echo = TRUE, message = FALSE, warning = FALSE}
mosaic1 <- jpeg::readJPEG("Images/goldengirls.jpg") %>%
image_to_bricks(img_size = 48) #Length of each side of mosaic in "bricks"
#For official LEGO colors, use with scale_fill_brick and theme_brick.
ggplot(df, aes(trt, outcome)) +
geom_brick_col(aes(fill = trt)) +
scale_fill_brick() +
coord_brick() +
theme_brick()
#Plot 2D mosaic
mosaic1 %>% display_set()
```
If you had previously created mosaics before the package release, the script below will still work.
Both `scale_fill_brick()` and `theme_brick()` take an input 'brick_theme', which ensures all colors match official LEGO brick colors. See `build_themes()` for a sample of all available brick theme.
```{r geom_brick2, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
df <- data.frame(trt = letters[1:6], outcome = rnorm(6, mean = 5, sd = 2))
use_theme <- "hp"
ggplot(df, aes(trt, outcome)) +
geom_brick_col(aes(fill = trt), two_knob = F) +
scale_fill_brick(use_theme) +
coord_brick_flip() +
theme_brick(use_theme) +
theme(legend.position = "none")
```{r m1_set2, eval=FALSE, echo = TRUE}
mosaic1 <- jpeg::readJPEG("Images/goldengirls.jpg") %>%
scale_image(img_size = 48) %>% #Length of each side of mosaic in "bricks"
legoize() %>%
collect_bricks()
```
### 2D Mosaics
## IRL
`image_to_bricks()` can take a few important arguments:
- `img_size` Providing a single value, such as `48`, crops the image to a square. Inputting a 2-element array, `c(56, 48)`, will output a rectangular image of `c(width, height)`.
- `color_table` Data frame of possible brick colors in the mosaic. Defaults to the included data set `lego_colors`.
- `brightness` adjusts the light of the image. Values greater than 1 will lighten the image, while value less than 1 will darken it.
`display_set()` creates a ggplot of the image.
### 3D Mosaics
Two additional functions can convert the `image_to_bricks()` output into a 3D mosaic using the [rayshader](https://github.com/tylermorganwall/rayshader) package by [Tyler Morgan-Wall](https://twitter.com/tylermorganwall).
- `collect_3d()` translates the 2D LEGO mosaic into two matrices - one for the color image and one for the elevation of each point on the image. By default, the produced image has the height of 6 LEGO plates (2 LEGO bricks) with lighter colors having a higher elevation. Use `mosaic_height` to change the height of the mosaic and set `highest_el = 'dark'` to set the darker colors as the tallest bricks.
- `display_3d()` simply calls `rayshader::plot_3d()`, but pulls both the hillshade and elevation matrices from the output of `collect_3d()` and fixes some of the arguments. See `?rayshader::plot_3d()` for more information.
```{r m1_3d, echo=TRUE,warning=FALSE, message=FALSE}
library(rayshader)
mosaic1 %>%
collect_3d() %>%
display_3d(fov=0,theta=-20,phi=30,windowsize=c(1000,800),zoom=0.7)
render_snapshot()
```
## LEGO Mosaics IRL
Additional functions assist in the translation from the LEGO mosaic image into a real LEGO set.
Additional functions assist in the translation of brickr objects into actual LEGO bricks.
### Instructions
Use `generate_instructions()` to break the LEGO mosaic image into easier-to-read steps for building the set. This defaults to 6 steps, but passing any integer value will generate that many steps.
Use `build_instructions()` to break the mosaics and 3D models into easier-to-read steps for building the set. This defaults to 6 steps, but passing any integer value will generate that many steps.
```{r m1_instructions, fig.width = 8, fig.height=7, message = FALSE, warning = FALSE}
mosaic1 %>% generate_instructions(9)
mosaic1 %>% build_instructions(9)
```
### Piece list and count
Use `display_pieces()` to generate a graphic and count of all required plates or bricks (for stacked mosaics). These are sorted by color and size for easy purchase on LEGO.com's [Pick-a-Brick](https://shop.lego.com/en-US/Pick-a-Brick) section using the advanced search option. Alternatively, use `table_pieces()` to produce a data frame table of all required bricks.
Use `build_pieces()` to generate a graphic and count of all required plates or bricks (for stacked mosaics). These are sorted by color and size for easy purchase on LEGO.com's [Pick-a-Brick](https://shop.lego.com/en-US/Pick-a-Brick) section using the advanced search option. Alternatively, use `table_pieces()` to produce a data frame table of all required bricks.
```{r m1_pieces, fig.width = 9, fig.height=9, message = FALSE, warning = FALSE}
mosaic1 %>% display_pieces()
```{r m1_pieces, fig.width = 8, fig.height=7, message = FALSE, warning = FALSE}
mosaic1 %>% build_pieces()
```
+136 -193
View File
@@ -1,25 +1,44 @@
LEGO Mosaics in R
The LEGO® System in R
================
# brickr <img src='man/figures/logo.png' align="right" height="138" />
<!-- <!-- badges: start -->
<!-- <!-- badges: start -->
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- <!-- badges: end -->
<!-- <!-- badges: end -->
## Overview
**brickr** is a package for creating LEGO-esque 2D and 3D models using
the R [tidyverse](https://www.tidyverse.org/) and [Tyler
Morgan-Wall](https://twitter.com/tylermorganwall)s
[rayshader](https://github.com/tylermorganwall/rayshader) package.
**brickr** is a package for bringing the LEGO® experience into the R and
[tidyverse](https://www.tidyverse.org/) ecosystem.
The package has two key uses:
The package is divided into 3 separate systems:
- Converting image files in to 2D and 3D LEGO mosaics
- Building 3D LEGO models from simple data frames
- [**Mosaics**](#mosaics): Convert image files into mosaics that could
be built using LEGO® bricks.
- [**3D Models**](#3d-models): Build 3D LEGO® models from simple data
formats & [rayshader](https://www.rayshader.com/).
- [**Charts**](#charts): A [ggplot2](https://ggplot2.tidyverse.org/)
extension to generate plots that resemble LEGO® bricks.
brickr also includes tools help users create the Mosaics and 3D model
output using real LEGO® elements.
### Whats the point?
The goal of {brickr} is to provide a series of tools to integrate the
LEGO® system with R by:
- Enhancing a real world building experience with mosaics, generated
instructions, and piece counts.
- Generating interest in R and coding for new audiences with
easy-to-create 3D models.
- or just embracing pure novelty.
*brickr is developed using publicly available information about LEGO®
products and is not officially affiliated with The LEGO Group*
## Installation
@@ -32,37 +51,76 @@ devtools::install_github("ryantimpe/brickr")
install.packages("rayshader")
```
## Mosaics
The mosaic functions renders an imported JPG or PNG file using LEGO
colors and bricks.
``` r
mosaic1 <- png::readPNG("Images/mf_unicorn.PNG") %>%
image_to_mosaic(img_size = 36) #Length of each side of mosaic in "bricks"
#Plot 2D mosaic
mosaic1 %>% build_mosaic()
```
![](README_files/figure-gfm/m1_set-1.png)<!-- -->
In general, any {brickr} function that begins with `build_` generates a
graphical output from a {brickr} list object from other functions.
### Customization
`image_to_mosaic()` can take a few important arguments. See
`?image_to_mosaic()` for full detail.
- `img_size` Providing a single value, such as `48`, crops the image
to a square. Inputting a 2-element array, `c(56, 48)`, will output a
rectangular image of `c(width, height)`.
- `color_table` & `color_palette` Options to limit the color of bricks
used in mosaics, as not all colors produced by LEGO are readily
available. Set `color_palette` to universal or `c('universal',
'generic')` to limit colors to the most common ones. Use a subset of
the data frame `lego_colors` as the `color_table` to specify a
custom palette.
- `method` Technique used to map image colors into the allowed brick
colors. Defaults to cie94\`, but other options include cie2000
and euclidean. Also includes the option brickr\_classic, used in
previous version of the package.
## 3D Models
Currently, 3D models can be built from one of two data input formats:
`bricks_from_table()` or `bricks_from_coords()`.
The `bricks_from_*` series of functions creates 3D models of LEGO bricks
from a variety of input formats. These models are rendered using [Tyler
Morgan-Wall](https://twitter.com/tylermorganwall)s
[rayshader](https://www.rayshader.com/) package.
**These functions are very experimental and will change. Better
documentation will be released soon.**
- `bricks_from_table()` converts a matrix-shaped table of integers
into LEGO bricks. For simple models, this table can be made manually
using `data.frame()` or `tibble::tribble()`. For more advanced
models, its recommended you use MS Excel or a .csv file. The
left-most column in the table is associated with the Level or z-axis
of the model. The function by default converts this to numeric for
you. Each other column is an x-coordinate and each row is a
y-coordinate. More flexible inputs will be available in a future
release.
- `bricks_from_excel()` is a wrapper function to more easily build
- `bricks_from_table()` & `bricks_from_excel()` convert a
matrix-shaped table of integers into LEGO bricks. For simple models,
this table can be made manually using `data.frame()` or
`tibble::tribble()`. For more advanced models, its recommended you
use MS Excel or a .csv file. The left-most column in the table is
associated with the Level or z-axis of the model.
`bricks_from_excel()` is a wrapper function to more easily build
models designed using a Microsoft Excel template. Please see this
repo: [brickr toybox](https://github.com/ryantimpe/brickr_toybox).
- `bricks_from_coords()` takes a data frame with `x`, `y`, & `z`
integer values, and `Color` columns, where each combination of x, y,
& z is a point in 3-dimensional space. Color must be an official
LEGO color name from `display_colors()`. This format is much more
flexible than `bricks_from_table()` and allows the programatic
LEGO color name from `build_colors()`. This format is much more
flexible than `bricks_from_table()` and allows the programmatic
development of 3D models.
Pass the output from any `bricks_from_*()` function to
`display_bricks()` to see the 3D model.
\-`bricks_from_mosaic()` converts a 2D [mosaic](#mosaics) object from an
image into 3D LEGO models, respectively. `bricks_from_rayshader()`
creates a LEGO model from the same input as `rayshader::plot_3d()`.
Pass the output from any `bricks_from_*()` function to `build_bricks()`
to see the 3D model. The `brick_res` option allows for higher resolution
bricks in hd or uhd, which will take longer to render.
``` r
library(brickr)
@@ -70,105 +128,27 @@ library(brickr)
#This is a brick
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
X2 = rep(3,4)
)
brick
```
## Level X1 X2
## 1 A 1 1
## 2 A 1 1
## 3 A 1 1
## 4 A 1 1
``` r
brick %>%
bricks_from_table() %>%
display_bricks()
build_bricks(brick_res = "uhd")
rayshader::render_snapshot()
rayshader::render_snapshot( clear = TRUE)
```
![](README_files/figure-gfm/bricks_1-1.png)<!-- -->
### Brick Colors
There are 2 ways to assign the color of the bricks. The
`display_colors()` function helps with ID numbers and names
- Use the `brickrID` value instead of 1 in the model input table.
Values of 0 are blank spaces.
- Create a table of color assignments and pass this to
`bricks_from_table()`
<!-- end list -->
``` r
brick_colors <- data.frame(
.value = 1,
Color = "Bright blue"
)
brick %>%
bricks_from_table(brick_colors) %>%
display_bricks()
rayshader::render_snapshot()
```
![](README_files/figure-gfm/bricks_2-1.png)<!-- -->
### Stacking bricks
The Level column in the input table determines the height of the bricks.
`bricks_from_table()` will convert alphanumeric levels into a z
The Level column in the input table determines the elevation of the
bricks. `bricks_from_table()` will convert alphanumeric levels into a z
coordinate.
``` r
# A is the bottom Level, B is the top
brick <- data.frame(
Level= c(rep("A",4), rep("B",4)),
X1 = rep(1,4),
X2 = rep(1,4)
)
brick %>%
bricks_from_table(brick_colors) %>%
display_bricks()
rayshader::render_snapshot()
```
![](README_files/figure-gfm/bricks_3-1.png)<!-- -->
The same process works with many levels
``` r
#You can stack many bricks ----
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
)
#... And they can all be different colors ----
1:10 %>%
purrr::map_df(~dplyr::mutate(brick, Level = LETTERS[.x], X1 = .x, X2 = .x)) %>%
bricks_from_table() %>%
display_bricks()
rayshader::render_snapshot()
```
![](README_files/figure-gfm/bricks_4-1.png)<!-- -->
# Full Models
For larger models, use `tibble::tribble()` to more easily visualize the
model. For very large models, use MS Excel.
model. For very large models, use a csv or Excel.
``` r
my_first_model <- tibble::tribble(
@@ -203,9 +183,9 @@ brick_colors <- tibble::tribble(
my_first_model %>%
bricks_from_table(brick_colors) %>%
display_bricks(theta = 210)
build_bricks(theta = 210, brick_res = "hd")
rayshader::render_snapshot()
rayshader::render_snapshot(clear = TRUE)
```
![](README_files/figure-gfm/bricks_5-1.png)<!-- -->
@@ -236,9 +216,9 @@ sphere_coords <- expand.grid(
sphere_coords %>%
bricks_from_coords() %>%
display_bricks(phi = 30, theta = 30)
build_bricks(phi = 30, theta = 30)
rayshader::render_snapshot()
rayshader::render_snapshot(clear = TRUE)
```
![](README_files/figure-gfm/bricks_6-1.png)<!-- -->
@@ -260,105 +240,68 @@ be found at the links below.
- [**brickr toybox**](https://github.com/ryantimpe/brickr_toybox) repo
for tools and resources to get started.
## Mosaics
## Charts
The mosaic functions renders an imported JPG or PNG file using LEGO
colors and bricks. The resulting mosaic can be viewed in 2D and 3D. A
full explanation can be found on [this blog
post](http://www.ryantimpe.com/post/lego-mosaic1/), this [follow-up
post](http://www.ryantimpe.com/post/lego-mosaic2/),and this [third
post](http://www.ryantimpe.com/post/lego-mosaic3/).
brickr includes functions to render
[ggplot2](https://ggplot2.tidyverse.org/) bar charts as bricks with LEGO
color themes. The main function is `geom_brick_col()`, which is the
brickr equivalent of `geom_col()`. Additional functions are highly
recommended to ensure that proper the chart is rendered in the proper
functions and proportions.
``` r
mosaic1 <- jpeg::readJPEG("Images/goldengirls.jpg") %>%
image_to_bricks(img_size = 48) #Length of each side of mosaic in "bricks"
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
#Plot 2D mosaic
mosaic1 %>% display_set()
#For official LEGO colors, use with scale_fill_brick and theme_brick.
ggplot(df, aes(trt, outcome)) +
geom_brick_col(aes(fill = trt)) +
scale_fill_brick() +
coord_brick() +
theme_brick()
```
![](README_files/figure-gfm/m1_set-1.png)<!-- -->
![](README_files/figure-gfm/geom_brick-1.png)<!-- -->
If you had previously created mosaics before the package release, the
script below will still work.
Both `scale_fill_brick()` and `theme_brick()` take an input
brick\_theme, which ensures all colors match official LEGO brick
colors. See `build_themes()` for a sample of all available brick
theme.
``` r
mosaic1 <- jpeg::readJPEG("Images/goldengirls.jpg") %>%
scale_image(img_size = 48) %>% #Length of each side of mosaic in "bricks"
legoize() %>%
collect_bricks()
df <- data.frame(trt = letters[1:6], outcome = rnorm(6, mean = 5, sd = 2))
use_theme <- "hp"
ggplot(df, aes(trt, outcome)) +
geom_brick_col(aes(fill = trt), two_knob = F) +
scale_fill_brick(use_theme) +
coord_brick_flip() +
theme_brick(use_theme) +
theme(legend.position = "none")
```
### 2D Mosaics
![](README_files/figure-gfm/geom_brick2-1.png)<!-- -->
`image_to_bricks()` can take a few important arguments:
## IRL
- `img_size` Providing a single value, such as `48`, crops the image
to a square. Inputting a 2-element array, `c(56, 48)`, will output a
rectangular image of `c(width, height)`.
- `color_table` Data frame of possible brick colors in the mosaic.
Defaults to the included data set `lego_colors`.
- `brightness` adjusts the light of the image. Values greater than 1
will lighten the image, while value less than 1 will darken it.
`display_set()` creates a ggplot of the image.
### 3D Mosaics
Two additional functions can convert the `image_to_bricks()` output into
a 3D mosaic using the
[rayshader](https://github.com/tylermorganwall/rayshader) package by
[Tyler Morgan-Wall](https://twitter.com/tylermorganwall).
- `collect_3d()` translates the 2D LEGO mosaic into two matrices - one
for the color image and one for the elevation of each point on the
image. By default, the produced image has the height of 6 LEGO
plates (2 LEGO bricks) with lighter colors having a higher
elevation. Use `mosaic_height` to change the height of the mosaic
and set `highest_el = 'dark'` to set the darker colors as the
tallest bricks.
- `display_3d()` simply calls `rayshader::plot_3d()`, but pulls both
the hillshade and elevation matrices from the output of
`collect_3d()` and fixes some of the arguments. See
`?rayshader::plot_3d()` for more information.
<!-- end list -->
``` r
library(rayshader)
mosaic1 %>%
collect_3d() %>%
display_3d(fov=0,theta=-20,phi=30,windowsize=c(1000,800),zoom=0.7)
render_snapshot()
```
![](README_files/figure-gfm/m1_3d-1.png)<!-- -->
## LEGO Mosaics IRL
Additional functions assist in the translation from the LEGO mosaic
image into a real LEGO set.
Additional functions assist in the translation of brickr objects into
actual LEGO bricks.
### Instructions
Use `generate_instructions()` to break the LEGO mosaic image into
Use `build_instructions()` to break the mosaics and 3D models into
easier-to-read steps for building the set. This defaults to 6 steps, but
passing any integer value will generate that many steps.
``` r
mosaic1 %>% generate_instructions(9)
mosaic1 %>% build_instructions(9)
```
![](README_files/figure-gfm/m1_instructions-1.png)<!-- -->
### Piece list and count
Use `display_pieces()` to generate a graphic and count of all required
Use `build_pieces()` to generate a graphic and count of all required
plates or bricks (for stacked mosaics). These are sorted by color and
size for easy purchase on LEGO.coms
[Pick-a-Brick](https://shop.lego.com/en-US/Pick-a-Brick) section using
@@ -366,7 +309,7 @@ the advanced search option. Alternatively, use `table_pieces()` to
produce a data frame table of all required bricks.
``` r
mosaic1 %>% display_pieces()
mosaic1 %>% build_pieces()
```
![](README_files/figure-gfm/m1_pieces-1.png)<!-- -->
Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

+29
View File
@@ -0,0 +1,29 @@
destination: docs
url: http://brickr.org
reference:
- title: Mosaics
desc: Create a LEGO mosaic from an image
contents:
- build_mosaic
- image_to_mosaic
- title: 3D Models
desc: Build 3D models from various inputs
contents:
- starts_with("bricks_")
- build_bricks
- title: ggplot Extension
desc: Brick bar charts in ggplot
contents:
- starts_with("coord_")
- starts_with("geom_")
- starts_with("scale_")
- starts_with("theme_")
- title: Bricks IRL
desc: Helper functions to create bricks and build them IRL.
contents:
- build_colors
- build_instructions
- starts_with("build_pieces")
- build_themes
+6
View File
@@ -0,0 +1,6 @@
colorspace_bobcat.png
colorspace_flower.png
colorspace_me.png
colorspace_testing.R
colorspace_unicorn.png
palettes_reduced.png
+47
View File
@@ -0,0 +1,47 @@
library(tidyverse)
library(brickr)
dat <- iris %>%
group_by(Species) %>%
summarize_if(is.numeric, mean) %>%
gather(Series, avg, -Species)
# dat$avg <- dat$avg * sample(c(-1, 1), nrow(dat), replace=T)
theme_list_for_loop <- unique(brickr_themes$theme)
# themesss <- "hp"
for(i in seq_along(theme_list_for_loop)){
title = theme_list_for_loop[i]
subtitle <- paste0("brickr::scale_fill_brick( brick_theme = '", theme_list_for_loop[i], "')")
p <- ggplot(dat, aes(x=Species, y = avg)) +
geom_brick_col(aes(fill = Series), two_knob = F, split_bricks = T,
label = "brickr", min_radius_for_text = 0 ) +
labs(title = title, caption = subtitle)
if(i <= 8){
p <- p +
scale_fill_brick(theme_list_for_loop[i]) +
coord_brick() +
theme_brick(theme_list_for_loop[i])
} else {
p <- p +
scale_fill_brick(theme_list_for_loop[i]) +
coord_brick_flip() +
theme_brick(theme_list_for_loop[i]) +
theme(legend.position = "bottom")
}
ggsave(paste0("admin_color_tools/demos/img", i+1, ".png"), plot = p, device = "png", width = 7, height = 5)
}
#
# movie_input <- list.files(pattern = "demo")
# av::av_encode_video(movie_input, output = "brickrdemo.mp4", framerate = 1,
# vfilter = "null", codec = NULL, audio = NULL, verbose = TRUE)
Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
#Create data of colors for the package
library(tidyverse)
rgb2hex <- function(r,g,b) rgb(r, g, b, maxColorValue = 255)
names(brickr::lego_colors)
color_df <- readxl::read_xlsx("admin_color_tools/Colors_Master.xlsx")
names(color_df)
lego_colors <- color_df %>%
select(-Sample) %>%
rename_at(vars("R", "G", "B"), list(~paste0(., "_lego"))) %>%
filter(c_Palette2016, !c_Metallic, !c_Transparent, !c_Glow) %>%
select(-starts_with("c_")) %>%
mutate(Palette = factor(Palette, levels = c("Universal", "Generic", "Special")),
hex = rgb2hex(R_lego, G_lego, B_lego)) %>%
mutate_at(vars(R_lego, G_lego, B_lego), list(~./255)) %>%
arrange(Palette, LEGONo) %>%
mutate(brickrID = row_number()) %>%
select(brickrID, Color, LEGONo, Palette, everything()) %>%
#Calculate brightness of color
# https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
mutate(lum = 0.299*R_lego + 0.587*G_lego + 0.114*B_lego)
usethis::use_data(lego_colors, overwrite = T)
Binary file not shown.
+17
View File
@@ -0,0 +1,17 @@
library(tidyverse)
raw <- readxl::read_xlsx("admin_color_tools/color_themes.xlsx")
themes <- raw[, 1:(which(grepl("..", names(raw), fixed = T))[1]-1)]
color_key <- brickr::lego_colors
brickr_themes <- themes %>%
filter(!is.na(TYPE)) %>%
mutate(index = row_number() - 2) %>%
gather(theme, brickrID, -TYPE, -index) %>%
filter(!is.na(brickrID)) %>%
inner_join(color_key %>% select(brickrID, hex)) %>%
select(-brickrID)
usethis::use_data(brickr_themes, overwrite = T)
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
brickr.org
Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 KiB

+163
View File
@@ -0,0 +1,163 @@
<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>License • brickr</title>
<!-- favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="apple-touch-icon.png" />
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="apple-touch-icon-60x60.png" />
<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script>
<!-- sticky kit -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script>
<!-- pkgdown -->
<link href="pkgdown.css" rel="stylesheet">
<script src="pkgdown.js"></script>
<meta property="og:title" content="License" />
<meta property="og:image" content="http://brickr.org/logo.png" />
<meta name="twitter:card" content="summary" />
<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-title-body">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header>
<div class="row">
<div class="contents col-md-9">
<div class="page-header">
<h1>License</h1>
</div>
<pre>YEAR: 2019
COPYRIGHT HOLDER: Ryan Timpe
</pre>
</div>
</div>
<footer>
<div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
+383
View File
@@ -0,0 +1,383 @@
<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GNU General Public License • brickr</title>
<!-- favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="apple-touch-icon.png" />
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="apple-touch-icon-60x60.png" />
<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script>
<!-- sticky kit -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script>
<!-- pkgdown -->
<link href="pkgdown.css" rel="stylesheet">
<script src="pkgdown.js"></script>
<meta property="og:title" content="GNU General Public License" />
<meta property="og:image" content="http://brickr.org/logo.png" />
<meta name="twitter:card" content="summary" />
<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-title-body">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header>
<div class="row">
<div class="contents col-md-9">
<div class="page-header">
<h1>GNU General Public License</h1>
</div>
<div id="gnu-general-public-license" class="section level1">
<p><em>Version 3, 29 June 2007</em><br><em>Copyright © 2007 Free Software Foundation, Inc. &lt;<a href="http://fsf.org/" class="uri">http://fsf.org/</a>&gt;</em></p>
<p>Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.</p>
<div id="preamble" class="section level2">
<h2 class="hasAnchor">
<a href="#preamble" class="anchor"></a>Preamble</h2>
<p>The GNU General Public License is a free, copyleft license for software and other kinds of works.</p>
<p>The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a programto make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.</p>
<p>When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.</p>
<p>To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.</p>
<p>For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.</p>
<p>Developers that use the GNU GPL protect your rights with two steps: <strong>(1)</strong> assert copyright on the software, and <strong>(2)</strong> offer you this License giving you legal permission to copy, distribute and/or modify it.</p>
<p>For the developers and authors protection, the GPL clearly explains that there is no warranty for this free software. For both users and authors sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.</p>
<p>Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.</p>
<p>Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.</p>
<p>The precise terms and conditions for copying, distribution and modification follow.</p>
</div>
<div id="terms-and-conditions" class="section level2">
<h2 class="hasAnchor">
<a href="#terms-and-conditions" class="anchor"></a>TERMS AND CONDITIONS</h2>
<div id="0-definitions" class="section level3">
<h3 class="hasAnchor">
<a href="#0-definitions" class="anchor"></a>0. Definitions</h3>
<p>“This License” refers to version 3 of the GNU General Public License.</p>
<p>“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.</p>
<p>“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.</p>
<p>To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.</p>
<p>A “covered work” means either the unmodified Program or a work based on the Program.</p>
<p>To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.</p>
<p>To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.</p>
<p>An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that <strong>(1)</strong> displays an appropriate copyright notice, and <strong>(2)</strong> tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.</p>
</div>
<div id="1-source-code" class="section level3">
<h3 class="hasAnchor">
<a href="#1-source-code" class="anchor"></a>1. Source Code</h3>
<p>The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.</p>
<p>A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.</p>
<p>The “System Libraries” of an executable work include anything, other than the work as a whole, that <strong>(a)</strong> is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and <strong>(b)</strong> serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.</p>
<p>The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the works System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.</p>
<p>The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.</p>
<p>The Corresponding Source for a work in source code form is that same work.</p>
</div>
<div id="2-basic-permissions" class="section level3">
<h3 class="hasAnchor">
<a href="#2-basic-permissions" class="anchor"></a>2. Basic Permissions</h3>
<p>All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.</p>
<p>You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.</p>
<p>Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.</p>
</div>
<div id="3-protecting-users-legal-rights-from-anti-circumvention-law" class="section level3">
<h3 class="hasAnchor">
<a href="#3-protecting-users-legal-rights-from-anti-circumvention-law" class="anchor"></a>3. Protecting Users Legal Rights From Anti-Circumvention Law</h3>
<p>No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.</p>
<p>When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the works users, your or third parties legal rights to forbid circumvention of technological measures.</p>
</div>
<div id="4-conveying-verbatim-copies" class="section level3">
<h3 class="hasAnchor">
<a href="#4-conveying-verbatim-copies" class="anchor"></a>4. Conveying Verbatim Copies</h3>
<p>You may convey verbatim copies of the Programs source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.</p>
<p>You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.</p>
</div>
<div id="5-conveying-modified-source-versions" class="section level3">
<h3 class="hasAnchor">
<a href="#5-conveying-modified-source-versions" class="anchor"></a>5. Conveying Modified Source Versions</h3>
<p>You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:</p>
<ul>
<li>
<strong>a)</strong> The work must carry prominent notices stating that you modified it, and giving a relevant date.</li>
<li>
<strong>b)</strong> The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.</li>
<li>
<strong>c)</strong> You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.</li>
<li>
<strong>d)</strong> If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.</li>
</ul>
<p>A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilations users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.</p>
</div>
<div id="6-conveying-non-source-forms" class="section level3">
<h3 class="hasAnchor">
<a href="#6-conveying-non-source-forms" class="anchor"></a>6. Conveying Non-Source Forms</h3>
<p>You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:</p>
<ul>
<li>
<strong>a)</strong> Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.</li>
<li>
<strong>b)</strong> Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either <strong>(1)</strong> a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or <strong>(2)</strong> access to copy the Corresponding Source from a network server at no charge.</li>
<li>
<strong>c)</strong> Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.</li>
<li>
<strong>d)</strong> Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.</li>
<li>
<strong>e)</strong> Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.</li>
</ul>
<p>A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.</p>
<p>A “User Product” is either <strong>(1)</strong> a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or <strong>(2)</strong> anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.</p>
<p>“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.</p>
<p>If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).</p>
<p>The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.</p>
<p>Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.</p>
</div>
<div id="7-additional-terms" class="section level3">
<h3 class="hasAnchor">
<a href="#7-additional-terms" class="anchor"></a>7. Additional Terms</h3>
<p>“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.</p>
<p>When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.</p>
<p>Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:</p>
<ul>
<li>
<strong>a)</strong> Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or</li>
<li>
<strong>b)</strong> Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or</li>
<li>
<strong>c)</strong> Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or</li>
<li>
<strong>d)</strong> Limiting the use for publicity purposes of names of licensors or authors of the material; or</li>
<li>
<strong>e)</strong> Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or</li>
<li>
<strong>f)</strong> Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.</li>
</ul>
<p>All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.</p>
<p>If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.</p>
<p>Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.</p>
</div>
<div id="8-termination" class="section level3">
<h3 class="hasAnchor">
<a href="#8-termination" class="anchor"></a>8. Termination</h3>
<p>You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).</p>
<p>However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated <strong>(a)</strong> provisionally, unless and until the copyright holder explicitly and finally terminates your license, and <strong>(b)</strong> permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.</p>
<p>Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.</p>
<p>Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.</p>
</div>
<div id="9-acceptance-not-required-for-having-copies" class="section level3">
<h3 class="hasAnchor">
<a href="#9-acceptance-not-required-for-having-copies" class="anchor"></a>9. Acceptance Not Required for Having Copies</h3>
<p>You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.</p>
</div>
<div id="10-automatic-licensing-of-downstream-recipients" class="section level3">
<h3 class="hasAnchor">
<a href="#10-automatic-licensing-of-downstream-recipients" class="anchor"></a>10. Automatic Licensing of Downstream Recipients</h3>
<p>Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.</p>
<p>An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the partys predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.</p>
<p>You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.</p>
</div>
<div id="11-patents" class="section level3">
<h3 class="hasAnchor">
<a href="#11-patents" class="anchor"></a>11. Patents</h3>
<p>A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributors “contributor version”.</p>
<p>A contributors “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.</p>
<p>Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributors essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.</p>
<p>In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.</p>
<p>If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either <strong>(1)</strong> cause the Corresponding Source to be so available, or <strong>(2)</strong> arrange to deprive yourself of the benefit of the patent license for this particular work, or <strong>(3)</strong> arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipients use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.</p>
<p>If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.</p>
<p>A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license <strong>(a)</strong> in connection with copies of the covered work conveyed by you (or copies made from those copies), or <strong>(b)</strong> primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.</p>
<p>Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.</p>
</div>
<div id="12-no-surrender-of-others-freedom" class="section level3">
<h3 class="hasAnchor">
<a href="#12-no-surrender-of-others-freedom" class="anchor"></a>12. No Surrender of Others Freedom</h3>
<p>If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.</p>
</div>
<div id="13-use-with-the-gnu-affero-general-public-license" class="section level3">
<h3 class="hasAnchor">
<a href="#13-use-with-the-gnu-affero-general-public-license" class="anchor"></a>13. Use with the GNU Affero General Public License</h3>
<p>Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.</p>
</div>
<div id="14-revised-versions-of-this-license" class="section level3">
<h3 class="hasAnchor">
<a href="#14-revised-versions-of-this-license" class="anchor"></a>14. Revised Versions of this License</h3>
<p>The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.</p>
<p>Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.</p>
<p>If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxys public statement of acceptance of a version permanently authorizes you to choose that version for the Program.</p>
<p>Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.</p>
</div>
<div id="15-disclaimer-of-warranty" class="section level3">
<h3 class="hasAnchor">
<a href="#15-disclaimer-of-warranty" class="anchor"></a>15. Disclaimer of Warranty</h3>
<p>THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</p>
</div>
<div id="16-limitation-of-liability" class="section level3">
<h3 class="hasAnchor">
<a href="#16-limitation-of-liability" class="anchor"></a>16. Limitation of Liability</h3>
<p>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
</div>
<div id="17-interpretation-of-sections-15-and-16" class="section level3">
<h3 class="hasAnchor">
<a href="#17-interpretation-of-sections-15-and-16" class="anchor"></a>17. Interpretation of Sections 15 and 16</h3>
<p>If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.</p>
<p><em>END OF TERMS AND CONDITIONS</em></p>
</div>
</div>
<div id="how-to-apply-these-terms-to-your-new-programs" class="section level2">
<h2 class="hasAnchor">
<a href="#how-to-apply-these-terms-to-your-new-programs" class="anchor"></a>How to Apply These Terms to Your New Programs</h2>
<p>If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.</p>
<p>To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode R"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="op">&lt;</span>one line to give the program<span class="st">'s name and a brief idea of what it does.&gt;</span></a>
<a class="sourceLine" id="cb1-2" title="2"><span class="st">Copyright (C) 2019 Ryan Timpe</span></a>
<a class="sourceLine" id="cb1-3" title="3"></a>
<a class="sourceLine" id="cb1-4" title="4"><span class="st">This program is free software: you can redistribute it and/or modify</span></a>
<a class="sourceLine" id="cb1-5" title="5"><span class="st">it under the terms of the GNU General Public License as published by</span></a>
<a class="sourceLine" id="cb1-6" title="6"><span class="st">the Free Software Foundation, either version 3 of the License, or</span></a>
<a class="sourceLine" id="cb1-7" title="7"><span class="st">(at your option) any later version.</span></a>
<a class="sourceLine" id="cb1-8" title="8"></a>
<a class="sourceLine" id="cb1-9" title="9"><span class="st">This program is distributed in the hope that it will be useful,</span></a>
<a class="sourceLine" id="cb1-10" title="10"><span class="st">but WITHOUT ANY WARRANTY; without even the implied warranty of</span></a>
<a class="sourceLine" id="cb1-11" title="11"><span class="st">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></a>
<a class="sourceLine" id="cb1-12" title="12"><span class="st">GNU General Public License for more details.</span></a>
<a class="sourceLine" id="cb1-13" title="13"></a>
<a class="sourceLine" id="cb1-14" title="14"><span class="st">You should have received a copy of the GNU General Public License</span></a>
<a class="sourceLine" id="cb1-15" title="15"><span class="st">along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></a></code></pre></div>
<p>Also add information on how to contact you by electronic and paper mail.</p>
<p>If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode R"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">brickr <span class="kw">Copyright</span> (C) <span class="dv">2019</span> Ryan Timpe</a>
<a class="sourceLine" id="cb2-2" title="2">This program comes with ABSOLUTELY NO WARRANTY; <span class="cf">for</span> details type <span class="st">'show w'</span>.</a>
<a class="sourceLine" id="cb2-3" title="3">This is free software, and you are welcome to redistribute it</a>
<a class="sourceLine" id="cb2-4" title="4">under certain conditions; type <span class="st">'show c'</span> <span class="cf">for</span> details.</a></code></pre></div>
<p>The hypothetical commands <code>show w</code> and <code>show c</code> should show the appropriate parts of the General Public License. Of course, your programs commands might be different; for a GUI interface, you would use an “about box”.</p>
<p>You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see &lt;<a href="http://www.gnu.org/licenses/" class="uri">http://www.gnu.org/licenses/</a>&gt;.</p>
<p>The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read &lt;<a href="http://www.gnu.org/philosophy/why-not-lgpl.html" class="uri">http://www.gnu.org/philosophy/why-not-lgpl.html</a>&gt;.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

+244
View File
@@ -0,0 +1,244 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ggplot with brickr • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="ggplot with brickr">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>ggplot with brickr</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/graphs.Rmd"><code>vignettes/graphs.Rmd</code></a></small>
<div class="hidden name"><code>graphs.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>brickr includes functions to render <a href="https://ggplot2.tidyverse.org/">ggplot2</a> bar charts as bricks with LEGO color themes. The main function is <code><a href="../reference/geom_brick_col.html">geom_brick_col()</a></code>, which is the brickr equivalent of <code>geom_col()</code>. Additional functions are highly recommended to ensure that proper the chart is rendered in the proper functions and proportions.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">df &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">trt =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"a"</span>, <span class="st">"b"</span>, <span class="st">"c"</span>), <span class="dt">outcome =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">2.3</span>, <span class="fl">1.9</span>, <span class="fl">3.2</span>))</a>
<a class="sourceLine" id="cb1-2" title="2"></a>
<a class="sourceLine" id="cb1-3" title="3"><span class="co">#For official LEGO colors, use with scale_fill_brick and theme_brick.</span></a>
<a class="sourceLine" id="cb1-4" title="4"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(trt, outcome)) <span class="op">+</span></a>
<a class="sourceLine" id="cb1-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> trt)) <span class="op">+</span></a>
<a class="sourceLine" id="cb1-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb1-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb1-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>()</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/getting_started-1.png" width="384"></p>
<ul>
<li>
<a href="#geoms"><code><a href="../reference/geom_brick_col.html">geom_brick_col()</a></code></a> draws data columns as bricks.</li>
<li>
<a href="#scale-and-themes"><code><a href="../reference/scale_fill_brick.html">scale_fill_brick()</a></code></a> is a discrete color scales, rendering columns in LEGO brick colors.</li>
<li>
<a href="#coords"><code><a href="../reference/coord-brick.html">coord_brick()</a></code></a> fixes the ratio between brick width and height. Any excess height is rendered as a residual brick without knobs.</li>
<li>
<a href="#scale-and-themes"><code><a href="../reference/theme_brick.html">theme_brick()</a></code></a> is a modified version of <code><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html">ggplot2::theme_minimal()</a></code>.</li>
</ul>
<p>See sections below for full detail.</p>
</div>
<div id="geoms" class="section level2">
<h2 class="hasAnchor">
<a href="#geoms" class="anchor"></a>Geoms</h2>
<div id="geom_brick_col" class="section level3">
<h3 class="hasAnchor">
<a href="#geom_brick_col" class="anchor"></a>geom_brick_col()</h3>
<p>Column / bar charts are rendered using the same structure as <code><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html">ggplot2::geom_col()</a></code>, with a few additional inputs.</p>
<ul>
<li>
<code>two_knob = TRUE</code> (the default) renders columns with a width two LEGO knobs, generating 2x4, 2x3, 2x2, and 2x1 knob bricks. Set to <code>FALSE</code> for columns with a width of 1 knob. This is useful when the chart has many columns and you dont want to lose brick detail.</li>
<li>
<code>split_bricks = TRUE</code> breaks columns into individual bricks, up to 4 knobs in length, as well as a residual brick at the top. Set this to <code>FALSE</code> to remove the splits, while retaining the knobs. *<code>min_radius_for_text</code> specifies the lower bound of knob radius (as a percent of the plot view port) required to display the embossed text inside the knobs. This ensures the plot looks clean when there are many columns. Defaults to 0.02.</li>
<li>
<code>label</code> is the text to display inside the brick knobs. A maximum of six characters.</li>
<li>
<code>label_scale</code> helps to ensure that the text size of the label fits within the knob circumference. When the graphical device is rendered, brickr makes a best guess on the size of the text. This isnt always the most aesthetic guess, so use <code>label_scale</code> values to adjust the size. Values &gt;1 will increase the size proportional, while values &lt;1 will decrease the size.
<ul>
<li>
<strong>Important</strong> This best guess is calculated in the initial rendering of the chart, so the text will NOT increase in size when using the zoom feature in RStudio. To share charts, its best to use <code>ggsave()</code> rather than screen shots.</li>
</ul>
</li>
</ul>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">df &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">x =</span> LETTERS[<span class="dv">1</span><span class="op">:</span><span class="dv">10</span>], <span class="dt">y =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">2</span><span class="op">:</span><span class="dv">10</span>, <span class="dv">10</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>))</a>
<a class="sourceLine" id="cb2-2" title="2"></a>
<a class="sourceLine" id="cb2-3" title="3"><span class="co">#For official LEGO colors, use with scale_fill_brick and theme_brick.</span></a>
<a class="sourceLine" id="cb2-4" title="4"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) <span class="op">+</span></a>
<a class="sourceLine" id="cb2-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> x), <span class="dt">two_knob =</span> <span class="ot">FALSE</span>, <span class="dt">label =</span> <span class="st">"LEGO"</span>, <span class="dt">label_scale =</span> <span class="fl">0.9</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb2-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb2-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>()</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/geom_brick-1.png" width="480"></p>
</div>
</div>
<div id="coords" class="section level2">
<h2 class="hasAnchor">
<a href="#coords" class="anchor"></a>Coords</h2>
<p>Using <code><a href="../reference/coord-brick.html">coord_brick()</a></code> ensures that bricks are rendered with correct proportions. Unlike other <code>coord_*</code> functions in ggplot, no other inputs are necessary.</p>
<p>For horizontal bars, use <code><a href="../reference/coord-brick.html">coord_brick_flip()</a></code>.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">df &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">x =</span> LETTERS[<span class="dv">1</span><span class="op">:</span><span class="dv">8</span>], <span class="dt">y =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">2</span><span class="op">:</span><span class="dv">10</span>, <span class="dv">8</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>))</a>
<a class="sourceLine" id="cb3-2" title="2"></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) <span class="op">+</span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> x), <span class="dt">two_knob =</span> <span class="ot">FALSE</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb3-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb3-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick_flip</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb3-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb3-8" title="8"><span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.position =</span> <span class="st">"none"</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/coord-1.png" width="480"></p>
</div>
<div id="scale-and-themes" class="section level2">
<h2 class="hasAnchor">
<a href="#scale-and-themes" class="anchor"></a>Scale and themes</h2>
<p>There are 41 LEGO brick colors available in brickr. See <code><a href="../reference/build_colors.html">build_colors()</a></code> or <code><a href="https://www.rdocumentation.org/packages/utils/topics/View">View(lego_colors)</a></code> for the complete list. The easiest way to use theme colors with plots are the <code><a href="../reference/scale_fill_brick.html">scale_fill_brick()</a></code> and the <code><a href="../reference/theme_brick.html">theme_brick()</a></code> functions.</p>
<p>These functions default to using the classic LEGO color theme, but can take any of the 21 themes included in brickr.</p>
<div id="scales" class="section level3">
<h3 class="hasAnchor">
<a href="#scales" class="anchor"></a>Scales</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">df &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">x =</span> LETTERS[<span class="dv">1</span><span class="op">:</span><span class="dv">8</span>], <span class="dt">y =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">2</span><span class="op">:</span><span class="dv">10</span>, <span class="dv">8</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>))</a>
<a class="sourceLine" id="cb4-2" title="2"></a>
<a class="sourceLine" id="cb4-3" title="3">use_theme &lt;-<span class="st"> "hp"</span></a>
<a class="sourceLine" id="cb4-4" title="4"></a>
<a class="sourceLine" id="cb4-5" title="5"><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) <span class="op">+</span></a>
<a class="sourceLine" id="cb4-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/geom_brick_col.html">geom_brick_col</a></span>(<span class="kw">aes</span>(<span class="dt">fill =</span> x)) <span class="op">+</span></a>
<a class="sourceLine" id="cb4-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>(<span class="dt">brick_theme =</span> use_theme) <span class="op">+</span></a>
<a class="sourceLine" id="cb4-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb4-9" title="9"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>(<span class="dt">brick_theme =</span> use_theme) <span class="op">+</span></a>
<a class="sourceLine" id="cb4-10" title="10"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title =</span> use_theme)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/scales-1.png" width="384"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/scales2-1.png" width="960"></p>
</div>
<div id="themes" class="section level3">
<h3 class="hasAnchor">
<a href="#themes" class="anchor"></a>Themes</h3>
<p>For a complete list of available themes, use <code><a href="../reference/build_themes.html">build_themes()</a></code>.</p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/themes-1.png" width="672"></p>
</div>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#geoms">Geoms</a></li>
<li><a href="#coords">Coords</a></li>
<li><a href="#scale-and-themes">Scale and themes</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

+169
View File
@@ -0,0 +1,169 @@
<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Articles • brickr</title>
<!-- favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png" />
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png" />
<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script>
<!-- sticky kit -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script>
<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>
<meta property="og:title" content="Articles" />
<meta property="og:image" content="http://brickr.org/logo.png" />
<meta name="twitter:card" content="summary" />
<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article-index">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header>
<div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1>Articles</h1>
</div>
<div class="section ">
<h3>All vignettes</h3>
<p class="section-desc"></p>
<ul>
<li><a href="graphs.html">ggplot with brickr</a></li>
<li><a href="models-from-other.html">3D Models from mosaics &amp; rayshader</a></li>
<li><a href="models-from-program.html">3D Models programmatically</a></li>
<li><a href="models-from-tables.html">3D models from tables</a></li>
<li><a href="mosaics.html">Mosaics with brickr</a></li>
</ul>
</div>
</div>
</div>
<footer>
<div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
+219
View File
@@ -0,0 +1,219 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Models from mosaics &amp; rayshader • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="3D Models from mosaics &amp; rayshader">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>3D Models from mosaics &amp; rayshader</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/models-from-other.Rmd"><code>vignettes/models-from-other.Rmd</code></a></small>
<div class="hidden name"><code>models-from-other.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>The <code>bricks_from_*</code> series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a>s <a href="https://www.rayshader.com/">rayshader</a> package. This package must be installed.</p>
</div>
<div id="d-mosaics" class="section level2">
<h2 class="hasAnchor">
<a href="#d-mosaics" class="anchor"></a>3D mosaics</h2>
<p>Begin with a brickr mosaic from an image. Rather than graphically rendering the mosaic using <code><a href="../reference/build_mosaic.html">build_mosaic()</a></code>, use <code><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic()</a></code>. This function takes two other inputs:</p>
<ul>
<li>
<code>mosaic_height</code> is the number of bricks stacked at the mosaics highest point. The default is 6.</li>
<li>
<code>highest_el</code> specifies if light or dark color bricks should be the tallest in the model. The default is light.</li>
</ul>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">mosaic &lt;-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>()</a>
<a class="sourceLine" id="cb1-3" title="3"></a>
<a class="sourceLine" id="cb1-4" title="4">mosaic <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_6-1.png" width="384"></p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1"></a>
<a class="sourceLine" id="cb2-2" title="2">mosaic <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic</a></span>(<span class="dt">highest_el =</span> <span class="st">"dark"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">phi =</span> <span class="dv">60</span>, <span class="dt">theta =</span> <span class="dv">15</span>)</a>
<a class="sourceLine" id="cb2-5" title="5"></a>
<a class="sourceLine" id="cb2-6" title="6">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_6-2.png" width="384"></p>
</div>
<div id="models-from-rayshader" class="section level2">
<h2 class="hasAnchor">
<a href="#models-from-rayshader" class="anchor"></a>Models from rayshader</h2>
<p><a href="https://www.rayshader.com/">rayshader</a> by <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a> is an open source package for producing 2D and 3D data visualizations in R. rayshader uses elevation data in a base R matrix and a combination of raytracing, spherical texture mapping, overlays, and ambient occlusion to generate beautiful topographic 2D and 3D maps. (Note: text lifted straight from <a href="https://www.rayshader.com/">rayshader.com</a>.)</p>
<p>3D models in <strong>brickr</strong> are rendered using the functions in <strong>rayshader</strong>. Using <code><a href="../reference/bricks_from_rayshader.html">bricks_from_rayshader()</a></code>, you can convert rayshader map output into a brickr model. This function takes three inputs:</p>
<ul>
<li>
<code>hillshade</code> is topographic image matrix with an RGB channel (much like the mosaics).</li>
<li>
<code>heightmap</code> is a two-dimensional matrix specifiying the height of the image at each location.</li>
<li>
<code>max_height</code> is the number of bricks stacked at the mosaics highest point. The default is 12.</li>
<li>
<code>img_size</code> is the number of bricks on each side of the model. The default is 48.</li>
</ul>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(rayshader)</a>
<a class="sourceLine" id="cb3-2" title="2"></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="co">#Example from rayshader.com</span></a>
<a class="sourceLine" id="cb3-4" title="4"></a>
<a class="sourceLine" id="cb3-5" title="5"><span class="co">#Here, I load a map with the raster package.</span></a>
<a class="sourceLine" id="cb3-6" title="6">loadzip =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/tempfile">tempfile</a></span>() </a>
<a class="sourceLine" id="cb3-7" title="7"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/download.file">download.file</a></span>(<span class="st">"https://tylermw.com/data/dem_01.tif.zip"</span>, loadzip)</a>
<a class="sourceLine" id="cb3-8" title="8">localtif =<span class="st"> </span>raster<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/raster">raster</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/unzip">unzip</a></span>(loadzip, <span class="st">"dem_01.tif"</span>))</a>
<a class="sourceLine" id="cb3-9" title="9"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/unlink">unlink</a></span>(loadzip)</a>
<a class="sourceLine" id="cb3-10" title="10"></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="co">#And convert it to a matrix:</span></a>
<a class="sourceLine" id="cb3-12" title="12">elmat =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">matrix</a></span>(raster<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/extract">extract</a></span>(localtif, raster<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/extent">extent</a></span>(localtif), <span class="dt">buffer =</span> <span class="dv">1000</span>),</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="dt">nrow =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/nrow">ncol</a></span>(localtif), <span class="dt">ncol =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/nrow">nrow</a></span>(localtif))</a>
<a class="sourceLine" id="cb3-14" title="14"></a>
<a class="sourceLine" id="cb3-15" title="15">rayshader_object &lt;-<span class="st"> </span>elmat <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-16" title="16"><span class="st"> </span><span class="kw">sphere_shade</span>(<span class="dt">texture =</span> <span class="st">"desert"</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-17" title="17"><span class="st"> </span><span class="kw">add_water</span>(<span class="kw">detect_water</span>(elmat), <span class="dt">color =</span> <span class="st">"desert"</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-18" title="18"><span class="st"> </span><span class="kw">add_shadow</span>(<span class="kw">ray_shade</span>(elmat, <span class="dt">zscale =</span> <span class="dv">3</span>, <span class="dt">maxsearch =</span> <span class="dv">300</span>), <span class="fl">0.5</span>) </a>
<a class="sourceLine" id="cb3-19" title="19"></a>
<a class="sourceLine" id="cb3-20" title="20"><span class="co">#Plot with rayshader</span></a>
<a class="sourceLine" id="cb3-21" title="21">rayshader_object <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-22" title="22"><span class="st"> </span><span class="kw">plot_3d</span>(elmat, <span class="dt">zscale =</span> <span class="dv">10</span>, <span class="dt">fov =</span> <span class="dv">0</span>, <span class="dt">theta =</span> <span class="dv">135</span>, <span class="dt">zoom =</span> <span class="fl">0.75</span>, <span class="dt">phi =</span> <span class="dv">45</span>, <span class="dt">windowsize =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1000</span>, <span class="dv">800</span>))</a>
<a class="sourceLine" id="cb3-23" title="23"></a>
<a class="sourceLine" id="cb3-24" title="24">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_rayshader-1.png" width="384"></p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"></a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co">#Plot as bricks</span></a>
<a class="sourceLine" id="cb4-3" title="3">rayshader_object <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_rayshader.html">bricks_from_rayshader</a></span>(elmat) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">135</span>, <span class="dt">zoom =</span> <span class="fl">0.75</span>, <span class="dt">phi =</span> <span class="dv">45</span>)</a>
<a class="sourceLine" id="cb4-6" title="6"></a>
<a class="sourceLine" id="cb4-7" title="7">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_rayshader-2.png" width="384"></p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#d-mosaics">3D mosaics</a></li>
<li><a href="#models-from-rayshader">Models from rayshader</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

+260
View File
@@ -0,0 +1,260 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Models programmatically • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="3D Models programmatically">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>3D Models programmatically</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/models-from-program.Rmd"><code>vignettes/models-from-program.Rmd</code></a></small>
<div class="hidden name"><code>models-from-program.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>The <code>bricks_from_*</code> series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a>s <a href="https://www.rayshader.com/">rayshader</a> package. This package must be installed.</p>
<p>Use <code><a href="../reference/bricks_from_coords.html">bricks_from_coords()</a></code> to programmatically build 3D LEGO models rather than manually drawing them in a spreadsheet or table. Prove the function with a data frame with x, y, and z coordinates, along with an official LEGO color name for each point.</p>
</div>
<div id="a-simple-programmed-model" class="section level2">
<h2 class="hasAnchor">
<a href="#a-simple-programmed-model" class="anchor"></a>A simple programmed model</h2>
<p>Below, we create a 8x8x8 cube by expanding a data frame with the array 1:8 as the x-, y-, and z-coordinates. We then assign each row of that data frame one of three colors: Bright blue, Bright yellow, or Bright red.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">use_colors &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Bright blue"</span>, <span class="st">"Bright yellow"</span>, <span class="st">"Bright red"</span>)</a>
<a class="sourceLine" id="cb1-2" title="2"></a>
<a class="sourceLine" id="cb1-3" title="3">cube &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(</a>
<a class="sourceLine" id="cb1-4" title="4"> <span class="dt">x =</span> <span class="dv">1</span><span class="op">:</span><span class="dv">8</span>,</a>
<a class="sourceLine" id="cb1-5" title="5"> <span class="dt">y =</span> <span class="dv">1</span><span class="op">:</span><span class="dv">8</span>,</a>
<a class="sourceLine" id="cb1-6" title="6"> <span class="dt">z =</span> <span class="dv">1</span><span class="op">:</span><span class="dv">8</span> </a>
<a class="sourceLine" id="cb1-7" title="7">) </a>
<a class="sourceLine" id="cb1-8" title="8"></a>
<a class="sourceLine" id="cb1-9" title="9">cube<span class="op">$</span>Color &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(use_colors, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/nrow">nrow</a></span>(cube), <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">5</span>, <span class="dv">3</span>, <span class="dv">1</span>))</a>
<a class="sourceLine" id="cb1-10" title="10"></a>
<a class="sourceLine" id="cb1-11" title="11">cube <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-12" title="12"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-13" title="13"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>, <span class="dt">phi =</span> <span class="dv">30</span>, <span class="dt">theta =</span> <span class="dv">30</span>)</a>
<a class="sourceLine" id="cb1-14" title="14"></a>
<a class="sourceLine" id="cb1-15" title="15">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_6-1.png" width="384"></p>
<p>Using the same logic, we can build a sphere with a specified radius, and then apply rules to color each brick based on its coordinates.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">radius &lt;-<span class="st"> </span><span class="dv">4</span></a>
<a class="sourceLine" id="cb2-2" title="2">sphere_coords &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(</a>
<a class="sourceLine" id="cb2-3" title="3"> <span class="dt">x =</span> <span class="dv">1</span><span class="op">:</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((radius<span class="op">*</span><span class="fl">2.5</span>)),</a>
<a class="sourceLine" id="cb2-4" title="4"> <span class="dt">y =</span> <span class="dv">1</span><span class="op">:</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((radius<span class="op">*</span><span class="fl">2.5</span>)),</a>
<a class="sourceLine" id="cb2-5" title="5"> <span class="dt">z =</span> <span class="dv">1</span><span class="op">:</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((radius<span class="op">/</span>(<span class="dv">6</span><span class="op">/</span><span class="dv">5</span>)<span class="op">*</span><span class="fl">2.5</span>)) <span class="co">#A brick is 6/5 taller than it is wide/deep</span></a>
<a class="sourceLine" id="cb2-6" title="6">) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(</a>
<a class="sourceLine" id="cb2-8" title="8"> <span class="co">#Distance of each coordinate from center</span></a>
<a class="sourceLine" id="cb2-9" title="9"> <span class="dt">dist =</span> (((x<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/mean">mean</a></span>(x))<span class="op">^</span><span class="dv">2</span> <span class="op">+</span><span class="st"> </span>(y<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/mean">mean</a></span>(y))<span class="op">^</span><span class="dv">2</span> <span class="op">+</span><span class="st"> </span>(z<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/mean">mean</a></span>(z))<span class="op">^</span><span class="dv">2</span>)<span class="op">^</span>(<span class="dv">1</span><span class="op">/</span><span class="dv">2</span>)),</a>
<a class="sourceLine" id="cb2-10" title="10"> <span class="dt">Color =</span> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span>(</a>
<a class="sourceLine" id="cb2-11" title="11"> <span class="co">#Yellow stripes on the surface with a 2to4 thickness</span></a>
<a class="sourceLine" id="cb2-12" title="12"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(dist, (radius<span class="dv">-1</span>), radius) <span class="op">&amp;</span><span class="st"> </span>(x<span class="op">+</span>y<span class="op">+</span>z) <span class="op">%%</span><span class="st"> </span><span class="dv">6</span> <span class="op">%in%</span><span class="st"> </span><span class="dv">0</span><span class="op">:</span><span class="dv">1</span> <span class="op">~</span><span class="st"> "Bright yellow"</span>,</a>
<a class="sourceLine" id="cb2-13" title="13"> <span class="co">#Otherwise, sphere is blue</span></a>
<a class="sourceLine" id="cb2-14" title="14"> dist <span class="op">&lt;=</span><span class="st"> </span>radius <span class="op">~</span><span class="st"> "Bright blue"</span></a>
<a class="sourceLine" id="cb2-15" title="15"> ))</a>
<a class="sourceLine" id="cb2-16" title="16"></a>
<a class="sourceLine" id="cb2-17" title="17">sphere_coords <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-18" title="18"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-19" title="19"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>, <span class="dt">phi =</span> <span class="dv">30</span>, <span class="dt">theta =</span> <span class="dv">30</span>)</a>
<a class="sourceLine" id="cb2-20" title="20"></a>
<a class="sourceLine" id="cb2-21" title="21">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_7-1.png" width="384"></p>
</div>
<div id="it-takes-a-village" class="section level2">
<h2 class="hasAnchor">
<a href="#it-takes-a-village" class="anchor"></a>It takes a village</h2>
<p>Rather than directly writing a data frame for a model, you can write a function that returns a data frame with x, y, z, and Color coordinates given initial starting parameters.</p>
<p>Below, the function <code>brick_house()</code> creates a LEGO house with randomized colors. The x- and y-coordinates and the size of the house are inputs to the functions.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">brick_house &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">x_coord =</span> <span class="dv">0</span>, <span class="dt">y_coord =</span> <span class="dv">0</span>, <span class="dt">width=</span><span class="dv">6</span>, <span class="dt">length=</span><span class="dv">5</span>, <span class="dt">height=</span><span class="dv">6</span>){</a>
<a class="sourceLine" id="cb3-2" title="2"> roof_colors &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Dark orange"</span>, <span class="st">"Dark brown"</span>, <span class="st">"Medium nougat"</span>, <span class="st">"Medium stone grey"</span>)</a>
<a class="sourceLine" id="cb3-3" title="3"> roof_col &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(roof_colors, <span class="dv">1</span>)</a>
<a class="sourceLine" id="cb3-4" title="4"> </a>
<a class="sourceLine" id="cb3-5" title="5"> house_colors &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Bright blue"</span>, <span class="st">"Bright red"</span>, <span class="st">"Dark red"</span>, <span class="st">"Dark azur"</span>, <span class="st">"Nougat"</span>, <span class="st">"Bright reddish violet"</span>)</a>
<a class="sourceLine" id="cb3-6" title="6"> house_col &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(house_colors, <span class="dv">1</span>)</a>
<a class="sourceLine" id="cb3-7" title="7"> </a>
<a class="sourceLine" id="cb3-8" title="8"> house_coords &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(</a>
<a class="sourceLine" id="cb3-9" title="9"> <span class="dt">x =</span> <span class="dv">1</span><span class="op">:</span>width, <span class="dt">y =</span> <span class="dv">1</span><span class="op">:</span>length, <span class="dt">z =</span> (<span class="dv">1</span><span class="op">:</span>height)<span class="op">+</span><span class="dv">1</span></a>
<a class="sourceLine" id="cb3-10" title="10"> ) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(</a>
<a class="sourceLine" id="cb3-12" title="12"> <span class="dt">roof =</span> (z <span class="op">&gt;</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((<span class="dv">1</span><span class="op">/</span><span class="dv">2</span>)<span class="op">*</span>height)),</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="dt">Color =</span> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span>(</a>
<a class="sourceLine" id="cb3-14" title="14"> <span class="co">#Roof</span></a>
<a class="sourceLine" id="cb3-15" title="15"> roof <span class="op">&amp;</span><span class="st"> </span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/MathFun">abs</a></span>(y <span class="op">-</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">floor</a></span>(length<span class="op">/</span><span class="dv">2</span>) <span class="dv">-1</span>) <span class="op">&lt;=</span><span class="st"> </span>(height<span class="op">-</span>z)) <span class="op">~</span><span class="st"> </span>roof_col,</a>
<a class="sourceLine" id="cb3-16" title="16"> roof <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-17" title="17"> <span class="co">#Door and windows</span></a>
<a class="sourceLine" id="cb3-18" title="18"> x <span class="op">==</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>(width<span class="op">/</span><span class="dv">2</span>) <span class="op">&amp;</span><span class="st"> </span>z <span class="op">==</span><span class="st"> </span><span class="dv">1</span> <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-19" title="19"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(x, <span class="dv">2</span>, width<span class="dv">-1</span>) <span class="op">&amp;</span><span class="st"> </span>x <span class="op">%%</span><span class="st"> </span><span class="dv">2</span> <span class="op">==</span><span class="st"> </span><span class="dv">0</span> <span class="op">&amp;</span><span class="st"> </span>y <span class="op">&gt;</span><span class="st"> </span><span class="dv">1</span> <span class="op">&amp;</span><span class="st"> </span>z <span class="op">==</span><span class="st"> </span><span class="dv">2</span> <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-20" title="20"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(y, <span class="dv">2</span>, length<span class="dv">-1</span>) <span class="op">&amp;</span><span class="st"> </span>y <span class="op">%%</span><span class="st"> </span><span class="dv">2</span> <span class="op">==</span><span class="st"> </span><span class="dv">0</span> <span class="op">&amp;</span><span class="st"> </span>z <span class="op">==</span><span class="st"> </span><span class="dv">2</span> <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-21" title="21"> x <span class="op">%in%</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>, width) <span class="op">|</span><span class="st"> </span>y <span class="op">%in%</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>, length) <span class="op">~</span><span class="st"> </span>house_col),</a>
<a class="sourceLine" id="cb3-22" title="22"> <span class="dt">x =</span> x<span class="op">+</span>x_coord, </a>
<a class="sourceLine" id="cb3-23" title="23"> <span class="dt">y =</span> y<span class="op">+</span>y_coord</a>
<a class="sourceLine" id="cb3-24" title="24"> )</a>
<a class="sourceLine" id="cb3-25" title="25"> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/function">return</a></span>(house_coords)</a>
<a class="sourceLine" id="cb3-26" title="26">}</a>
<a class="sourceLine" id="cb3-27" title="27"></a>
<a class="sourceLine" id="cb3-28" title="28"><span class="co">#Build one house</span></a>
<a class="sourceLine" id="cb3-29" title="29"><span class="kw">brick_house</span>() <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-30" title="30"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">225</span>)</a>
<a class="sourceLine" id="cb3-31" title="31">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_8-1.png" width="384"></p>
<p>Next, we write one more function, <code>brick_street()</code> to build a road and grass foundation. The, for an arbitrary number of houses and neighborhood size, use <code><a href="https://purrr.tidyverse.org/reference/map2.html">purrr::pmap_df</a></code> to generate many houses and place them along the road.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">brick_street &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">width =</span> <span class="dv">100</span>, <span class="dt">length =</span> <span class="dv">40</span>){</a>
<a class="sourceLine" id="cb4-2" title="2"> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(<span class="dt">x=</span><span class="dv">1</span><span class="op">:</span>width, <span class="dt">y=</span><span class="dv">1</span><span class="op">:</span>length, <span class="dt">z=</span><span class="dv">1</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(</a>
<a class="sourceLine" id="cb4-4" title="4"> <span class="dt">Color =</span> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span>(</a>
<a class="sourceLine" id="cb4-5" title="5"> y <span class="op">==</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>(length<span class="op">/</span><span class="dv">2</span>) <span class="op">&amp;</span><span class="st"> </span>x <span class="op">%%</span><span class="st"> </span><span class="dv">4</span> <span class="op">%in%</span><span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">4</span> <span class="op">~</span><span class="st"> "Bright yellow"</span>,</a>
<a class="sourceLine" id="cb4-6" title="6"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(y, length<span class="op">/</span><span class="dv">2</span> <span class="dv">-5</span>, length<span class="op">/</span><span class="dv">2</span> <span class="op">+</span><span class="dv">5</span>) <span class="op">~</span><span class="st"> "Dark stone grey"</span>,</a>
<a class="sourceLine" id="cb4-7" title="7"> <span class="ot">TRUE</span> <span class="op">~</span><span class="st"> "Dark green"</span></a>
<a class="sourceLine" id="cb4-8" title="8"> ))</a>
<a class="sourceLine" id="cb4-9" title="9">}</a>
<a class="sourceLine" id="cb4-10" title="10"></a>
<a class="sourceLine" id="cb4-11" title="11"><span class="co">#Build a village, houses on 2 sides of a street</span></a>
<a class="sourceLine" id="cb4-12" title="12">n_houses =<span class="st"> </span><span class="dv">14</span></a>
<a class="sourceLine" id="cb4-13" title="13">sz =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">100</span>, <span class="dv">40</span>)</a>
<a class="sourceLine" id="cb4-14" title="14"></a>
<a class="sourceLine" id="cb4-15" title="15"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/list">list</a></span>(<span class="dt">x_coord =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/seq">seq</a></span>(<span class="dv">10</span>, sz[<span class="dv">1</span>]<span class="op">-</span><span class="dv">10</span>, <span class="dt">by =</span> <span class="dv">10</span>), n_houses<span class="op">/</span><span class="dv">2</span>),</a>
<a class="sourceLine" id="cb4-16" title="16"> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/seq">seq</a></span>(<span class="dv">10</span>, sz[<span class="dv">1</span>]<span class="op">-</span><span class="dv">10</span>, <span class="dt">by =</span> <span class="dv">10</span>), n_houses<span class="op">/</span><span class="dv">2</span>)),</a>
<a class="sourceLine" id="cb4-17" title="17"> <span class="dt">y_coord =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(sz[<span class="dv">2</span>]<span class="op">/</span><span class="dv">2-15</span>, n_houses<span class="op">/</span><span class="dv">2</span>), <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(sz[<span class="dv">2</span>]<span class="op">/</span><span class="dv">2</span><span class="op">+</span><span class="dv">10</span>, n_houses<span class="op">/</span><span class="dv">2</span>)),</a>
<a class="sourceLine" id="cb4-18" title="18"> <span class="dt">width =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">4</span><span class="op">:</span><span class="dv">10</span>, n_houses, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb4-19" title="19"> <span class="dt">length =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">4</span><span class="op">:</span><span class="dv">8</span>, n_houses, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb4-20" title="20"> <span class="dt">height =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">5</span><span class="op">:</span><span class="dv">8</span>, n_houses, <span class="dt">replace =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb4-21" title="21"> ) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-22" title="22"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map2.html">pmap_df</a></span>(brick_house) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-23" title="23"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/bind.html">bind_rows</a></span>(<span class="kw">brick_street</span>(sz[<span class="dv">1</span>], sz[<span class="dv">2</span>])) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-24" title="24"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-25" title="25"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>()</a>
<a class="sourceLine" id="cb4-26" title="26"></a>
<a class="sourceLine" id="cb4-27" title="27">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_camera">render_camera</a></span>(<span class="dt">theta =</span> <span class="dv">60</span>, <span class="dt">phi =</span> <span class="dv">20</span>, <span class="dt">zoom =</span> <span class="fl">0.75</span>)</a>
<a class="sourceLine" id="cb4-28" title="28">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_9-1.png" width="384"></p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#a-simple-programmed-model">A simple programmed model</a></li>
<li><a href="#it-takes-a-village">It takes a village</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

+261
View File
@@ -0,0 +1,261 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D models from tables • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="3D models from tables">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>3D models from tables</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/models-from-tables.Rmd"><code>vignettes/models-from-tables.Rmd</code></a></small>
<div class="hidden name"><code>models-from-tables.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>The <code>bricks_from_*</code> series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a>s <a href="https://www.rayshader.com/">rayshader</a> package. This package must be installed.</p>
<p><code><a href="../reference/bricks_from_table.html">bricks_from_table()</a></code> converts a matrix-shaped table of integers into LEGO bricks, where most columns are x-coordinates, rows are y-coordinates, and a special <code>Level</code> column denotes the elevation of the row. For simple models, this table can be made manually using <code><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame()</a></code> or <code><a href="https://tibble.tidyverse.org/reference/tribble.html">tibble::tribble()</a></code>.</p>
<p>For more advanced models, its recommended you use MS Excel or a .csv file. <code><a href="../reference/bricks_from_excel.html">bricks_from_excel()</a></code> is a wrapper function to more easily build models designed using a Microsoft Excel template. Please see this repo: <a href="https://github.com/ryantimpe/brickr_toybox">brickr toybox</a>.</p>
<p>Pass the output of any <code>bricks_from_*()</code> function to <code><a href="../reference/build_bricks.html">build_bricks()</a></code> to render it as a 3D model.</p>
</div>
<div id="individual-bricks" class="section level2">
<h2 class="hasAnchor">
<a href="#individual-bricks" class="anchor"></a>Individual bricks</h2>
<p>Create a single 2x4 brick with a 2x4 data frame, with an additional column to specify the Level. These can be letters or numbers.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="co">#This is a 2 (columns) x 4 (rows) brick</span></a>
<a class="sourceLine" id="cb1-2" title="2">(brick &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(</a>
<a class="sourceLine" id="cb1-3" title="3"> <span class="dt">Level=</span><span class="st">"A"</span>,</a>
<a class="sourceLine" id="cb1-4" title="4"> <span class="dt">X1 =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(<span class="dv">3</span>,<span class="dv">4</span>), <span class="co">#The number 3 is the brickrID for 'bright red'</span></a>
<a class="sourceLine" id="cb1-5" title="5"> <span class="dt">X2 =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(<span class="dv">3</span>,<span class="dv">4</span>)</a>
<a class="sourceLine" id="cb1-6" title="6">))</a>
<a class="sourceLine" id="cb1-7" title="7"><span class="co">#&gt; Level X1 X2</span></a>
<a class="sourceLine" id="cb1-8" title="8"><span class="co">#&gt; 1 A 3 3</span></a>
<a class="sourceLine" id="cb1-9" title="9"><span class="co">#&gt; 2 A 3 3</span></a>
<a class="sourceLine" id="cb1-10" title="10"><span class="co">#&gt; 3 A 3 3</span></a>
<a class="sourceLine" id="cb1-11" title="11"><span class="co">#&gt; 4 A 3 3</span></a>
<a class="sourceLine" id="cb1-12" title="12"></a>
<a class="sourceLine" id="cb1-13" title="13">brick <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-14" title="14"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-15" title="15"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>) <span class="co">#Bricks available in standard def, high def, and ultra hd. </span></a>
<a class="sourceLine" id="cb1-16" title="16"></a>
<a class="sourceLine" id="cb1-17" title="17">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>( <span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_1-1.png" width="288"></p>
<p>Stack many bricks by changing the Level value in the data frame. The script below uses <code><a href="https://purrr.tidyverse.org/reference/map.html">purrr::map_df()</a></code> to avoid copying and pasting. Changing the numeric values inside the data frame for each level creates different colors.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1"><span class="dv">1</span><span class="op">:</span><span class="dv">10</span> <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map.html">map_df</a></span>(<span class="op">~</span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(brick,</a>
<a class="sourceLine" id="cb2-3" title="3"> <span class="dt">Level =</span> LETTERS[.x], </a>
<a class="sourceLine" id="cb2-4" title="4"> <span class="dt">X1 =</span> .x,</a>
<a class="sourceLine" id="cb2-5" title="5"> <span class="dt">X2 =</span> .x)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>)</a>
<a class="sourceLine" id="cb2-8" title="8"></a>
<a class="sourceLine" id="cb2-9" title="9">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>( <span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_2-1.png" width="288"></p>
</div>
<div id="full-models" class="section level2">
<h2 class="hasAnchor">
<a href="#full-models" class="anchor"></a>Full models</h2>
<p>The most direct way to create a 3D model is to manually create a data frame. Below, we create a data frame using <code><a href="https://tibble.tidyverse.org/reference/tribble.html">tibble::tribble()</a></code> so we can more easily see the structure as its written.</p>
<p>The data frame has 3 numbers as input (values of 0 are void spaces in the model). Rather than use the default brickr colors for the values of 1, 2, and 3, we define another data frame brick_colors</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">tree_or_mushroom &lt;-<span class="st"> </span>tibble<span class="op">::</span><span class="kw"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span>(</a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="op">~</span>Level, <span class="op">~</span>X1, <span class="op">~</span>X2, <span class="op">~</span>X3, <span class="op">~</span>X4, <span class="op">~</span>X5, <span class="op">~</span>X6,</a>
<a class="sourceLine" id="cb3-3" title="3"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-4" title="4"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-5" title="5"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-6" title="6"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-7" title="7"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-8" title="8"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-9" title="9"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-10" title="10"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-11" title="11"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-12" title="12"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-14" title="14"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-15" title="15"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-16" title="16"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-17" title="17"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-18" title="18"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-19" title="19"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-20" title="20"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-21" title="21"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-22" title="22"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-23" title="23"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-24" title="24"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-25" title="25"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-26" title="26"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-27" title="27"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-28" title="28"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-29" title="29"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-30" title="30"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span></a>
<a class="sourceLine" id="cb3-31" title="31">)</a>
<a class="sourceLine" id="cb3-32" title="32"></a>
<a class="sourceLine" id="cb3-33" title="33">brick_colors &lt;-<span class="st"> </span>tibble<span class="op">::</span><span class="kw"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span>(</a>
<a class="sourceLine" id="cb3-34" title="34"> <span class="op">~</span><span class="st">`</span><span class="dt">.value</span><span class="st">`</span>, <span class="op">~</span>Color,</a>
<a class="sourceLine" id="cb3-35" title="35"> <span class="dv">1</span>, <span class="st">"Bright green"</span>,</a>
<a class="sourceLine" id="cb3-36" title="36"> <span class="dv">2</span>, <span class="st">"Dark orange"</span>,</a>
<a class="sourceLine" id="cb3-37" title="37"> <span class="dv">3</span>, <span class="st">"Dark green"</span></a>
<a class="sourceLine" id="cb3-38" title="38">)</a>
<a class="sourceLine" id="cb3-39" title="39"> </a>
<a class="sourceLine" id="cb3-40" title="40">tree_or_mushroom <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-41" title="41"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>(brick_colors) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-42" title="42"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">210</span>, <span class="dt">phi =</span> <span class="dv">20</span>, <span class="dt">brick_res =</span> <span class="st">"hd"</span>)</a>
<a class="sourceLine" id="cb3-43" title="43"></a>
<a class="sourceLine" id="cb3-44" title="44">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_5-1.png" width="384"></p>
<div id="plates-instead-of-bricks" class="section level3">
<h3 class="hasAnchor">
<a href="#plates-instead-of-bricks" class="anchor"></a>Plates instead of bricks</h3>
<p>Thats clearly a tree, right? Why is the data frame called tree_or_mushroom?</p>
<p>Use the input brick_type=“plate”’ to render the 3D model using LEGO plates rather than bricks, which are 1/3 as tall.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">brick_colors &lt;-<span class="st"> </span>tibble<span class="op">::</span><span class="kw"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span>(</a>
<a class="sourceLine" id="cb4-2" title="2"> <span class="op">~</span><span class="st">`</span><span class="dt">.value</span><span class="st">`</span>, <span class="op">~</span>Color,</a>
<a class="sourceLine" id="cb4-3" title="3"> <span class="dv">1</span>, <span class="st">"Dark green"</span>,</a>
<a class="sourceLine" id="cb4-4" title="4"> <span class="dv">2</span>, <span class="st">"Light nougat"</span>,</a>
<a class="sourceLine" id="cb4-5" title="5"> <span class="dv">3</span>, <span class="st">"Bright red"</span></a>
<a class="sourceLine" id="cb4-6" title="6">)</a>
<a class="sourceLine" id="cb4-7" title="7"> </a>
<a class="sourceLine" id="cb4-8" title="8">tree_or_mushroom <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-9" title="9"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>(brick_colors) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-10" title="10"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">210</span>, <span class="dt">phi =</span> <span class="dv">10</span>, <span class="dt">brick_res =</span> <span class="st">"hd"</span>, <span class="dt">brick_type=</span><span class="st">"plate"</span>)</a>
<a class="sourceLine" id="cb4-11" title="11"></a>
<a class="sourceLine" id="cb4-12" title="12">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_5a-1.png" width="384"></p>
</div>
</div>
<div id="bricks-from-excel" class="section level2">
<h2 class="hasAnchor">
<a href="#bricks-from-excel" class="anchor"></a>Bricks from Excel</h2>
<p>When designing larger models, it is much easier to use a spreadsheet program to lay out the bricks for each level.</p>
<p>See <a href="https://github.com/ryantimpe/brickr_toybox">the brickr toybox</a> GitHub repo for some examples and templates.</p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#individual-bricks">Individual bricks</a></li>
<li><a href="#full-models">Full models</a></li>
<li><a href="#bricks-from-excel">Bricks from Excel</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

+258
View File
@@ -0,0 +1,258 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mosaics with brickr • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Mosaics with brickr">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>Mosaics with brickr</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/mosaics.Rmd"><code>vignettes/mosaics.Rmd</code></a></small>
<div class="hidden name"><code>mosaics.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>You can generate a brickr mosaic object from an image using <code><a href="../reference/image_to_mosaic.html">brickr::image_to_mosaic()</a></code>. Pass this object to <code><a href="../reference/build_mosaic.html">build_mosaic()</a></code> to construct a visualization of the mosaic.</p>
<p><img src="../Images/mf_unicorn.PNG" width="250"></p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">mosaic &lt;-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>()</a>
<a class="sourceLine" id="cb1-3" title="3"></a>
<a class="sourceLine" id="cb1-4" title="4">mosaic <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/g1-1.png" width="700"></p>
<p>The default is to create a mosaic with 48 knobs (brick studs) on each side. Change this using the <code>img_size</code> input. A single value will create a square mosaic, while an array of two values represent the width and length.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dt">img_size =</span> <span class="dv">32</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/g2-1.png" width="700"></p>
</div>
<div id="colors" class="section level2">
<h2 class="hasAnchor">
<a href="#colors" class="anchor"></a>Colors</h2>
<p>A key feature in <code><a href="../reference/image_to_mosaic.html">image_to_mosaic()</a></code> is the conversion of the original image into colors produced by LEGO. The default is to map each individual pixel to any of the 41 flat colors currently used for brick production using the <a href="https://en.wikipedia.org/wiki/Color_difference#CIE94">CIE94</a> algorithm. These defaults can be changed.</p>
<div id="color-palettes" class="section level3">
<h3 class="hasAnchor">
<a href="#color-palettes" class="anchor"></a>Color palettes</h3>
<p>There are currently 2 main ways to control the color palettes to build mosaics in brickr.</p>
<ul>
<li>The <code>color_palette</code> input takes a list of pre-defined palettes to create the mosaic.</li>
<li>The <code>color_table</code> input can take a data frame of specific colors. Usually a subset of the included <code>lego_colors</code> table.</li>
</ul>
<div id="default-color-palettes" class="section level4">
<h4 class="hasAnchor">
<a href="#default-color-palettes" class="anchor"></a>Default color palettes</h4>
<p>Each of the 41 colors belongs to one of three categories:</p>
<ul>
<li>universal colors are the most common. This list includes white/black/grays/brown and the classic yellow, red, blue, and green colors. All brick sizes should be readily available in these colors.</li>
<li>generic colors are commonly used in LEGO products, though it might be more difficult to find every brick in these colors.</li>
<li>special colors are typically reserved for certain products and its likely that bricks might not be actively produced in these colors.</li>
</ul>
<p>Use the <code>color_palette</code> input in the <code><a href="../reference/image_to_mosaic.html">image_to_mosaic()</a></code> function to limit the bricks used to any combination of these three categories.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">p1 &lt;-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_palette =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">'universal'</span>, <span class="st">'generic'</span>)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="st">"universal &amp; generic"</span>)</a>
<a class="sourceLine" id="cb3-4" title="4"></a>
<a class="sourceLine" id="cb3-5" title="5">p2 &lt;-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_palette =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">'universal'</span>)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="st">"universal"</span>)</a>
<a class="sourceLine" id="cb3-8" title="8"></a>
<a class="sourceLine" id="cb3-9" title="9">gridExtra<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/gridExtra/topics/arrangeGrob">grid.arrange</a></span>(p1, p2, <span class="dt">layout_matrix =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">matrix</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">ncol=</span><span class="dv">2</span>))</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/c_palettes-1.png" width="576"></p>
</div>
<div id="grayscale" class="section level4">
<h4 class="hasAnchor">
<a href="#grayscale" class="anchor"></a>Grayscale</h4>
<p>For grayscale or black and white mosaics, use <code>color_palette = 'bw'</code>. This creates the mosaic by measuring the brightness of each pixel in the image and mapping it one of the four shades of gray. Use the contrast input to adjust the relative brightness of the pixels.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_palette =</span> <span class="st">'bw'</span>, <span class="dt">contrast =</span> <span class="fl">1.1</span>)<span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/c_bw-1.png" width="700"></p>
</div>
<div id="custom-color-palettes" class="section level4">
<h4 class="hasAnchor">
<a href="#custom-color-palettes" class="anchor"></a>Custom color palettes</h4>
<p>With the <code>color_table</code> input, it is possible to restrict the colors in the mosaic to a custom palette.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1"><span class="co">#Remove blue and azure colors from lego_colors</span></a>
<a class="sourceLine" id="cb5-2" title="2">lego_colors_wo_blue &lt;-<span class="st"> </span>lego_colors <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(<span class="op">!</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/grep">grepl</a></span>(<span class="st">"blue|azur"</span>, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/chartr">tolower</a></span>(Color)))</a>
<a class="sourceLine" id="cb5-4" title="4"></a>
<a class="sourceLine" id="cb5-5" title="5">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb5-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>, <span class="dt">color_table =</span> lego_colors_wo_blue)<span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb5-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="st">"Mosaic without blue or azur"</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/c_custom-1.png" width="700"></p>
</div>
</div>
<div id="color-matching" class="section level3">
<h3 class="hasAnchor">
<a href="#color-matching" class="anchor"></a>Color matching</h3>
<p>brickr uses the <a href="https://cran.r-project.org/web/packages/farver/index.html"><code>farver</code></a> package to match image colors to the subset of LEGO colors. Technical details of the different algorithms can be found on <a href="https://en.wikipedia.org/wiki/Color_difference">Wikipedia</a>.</p>
<p>The default algorithm is cie94, though the other farver options are available using the <code>method</code> input. The farver euclidean is not very accurate, so brickr_classic returns a manually calculated version for Euclidean RGB distance matching.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"cie94"</span>, <span class="st">"cie2000"</span>, <span class="st">"euclidean"</span>, <span class="st">"brickr_classic"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-2" title="2"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map.html">map</a></span>(<span class="op">~</span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">24</span>, <span class="dt">method =</span>.x) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> .x )) -&gt;<span class="st"> </span>mosaics_by_method</a>
<a class="sourceLine" id="cb6-5" title="5"></a>
<a class="sourceLine" id="cb6-6" title="6">gridExtra<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/gridExtra/topics/arrangeGrob">grid.arrange</a></span>(<span class="dt">grobs =</span> mosaics_by_method, <span class="dt">layout_matrix =</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/cbind">rbind</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>,<span class="dv">2</span>),<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">3</span>,<span class="dv">4</span>)))</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/c_methods-1.png" width="480"></p>
</div>
<div id="dithering" class="section level3">
<h3 class="hasAnchor">
<a href="#dithering" class="anchor"></a>Dithering</h3>
<p>When rendering a mosaic from a photographic with many shades of similar colors, using <a href="https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering">dithering</a> by setting <code>dithering = TRUE</code> will help to add texture to the mosaic and avoid large areas of the same color. This works particularly well for large mosaics, but is purely a stylist preference.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="ot">FALSE</span>, <span class="ot">TRUE</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb7-2" title="2"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map.html">map</a></span>(<span class="op">~</span>jpeg<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/jpeg/topics/readJPEG">readJPEG</a></span>(<span class="st">"../Images/goldengirls.JPG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb7-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dt">dithering =</span> .x) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb7-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>(<span class="dt">title =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/paste">paste</a></span>(<span class="st">"dithering ="</span>, .x))) -&gt;<span class="st"> </span>mosaics_by_dither</a>
<a class="sourceLine" id="cb7-5" title="5"></a>
<a class="sourceLine" id="cb7-6" title="6">gridExtra<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/gridExtra/topics/arrangeGrob">grid.arrange</a></span>(<span class="dt">grobs =</span> mosaics_by_dither, <span class="dt">layout_matrix =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">matrix</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">ncol=</span><span class="dv">2</span>))</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/c_dither-1.png" width="576"></p>
</div>
<div id="other-color-options" class="section level3">
<h3 class="hasAnchor">
<a href="#other-color-options" class="anchor"></a>Other color options</h3>
<p>The input <code>brightness</code> can be used to scale up or down the RGB values of the image before color matching. The default is 1.</p>
</div>
</div>
<div id="d-mosaics" class="section level2">
<h2 class="hasAnchor">
<a href="#d-mosaics" class="anchor"></a>3D Mosaics</h2>
<p>With <a href="https://www.rayshader.com/">rayshader</a> installed, passing the mosaic object to <code><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic()</a></code> will render a 3D object, stacking layers of bricks on each other to create an elevated mosaic. By default, the lightest color bricks will be on top, but this can be changed using the <code>highest_el = 'dark'</code> option.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1">png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb8-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>(<span class="dv">32</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb8-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic</a></span>(<span class="dt">highest_el =</span> <span class="st">"dark"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb8-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_type =</span> <span class="st">"plate"</span>)</a>
<a class="sourceLine" id="cb8-5" title="5"></a>
<a class="sourceLine" id="cb8-6" title="6">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_camera">render_camera</a></span>(<span class="dt">theta =</span> <span class="dv">15</span>)</a>
<a class="sourceLine" id="cb8-7" title="7">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/mosaics_files/figure-html/c_threed-1.png" width="700"></p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#colors">Colors</a></li>
<li><a href="#d-mosaics">3D Mosaics</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Some files were not shown because too many files have changed in this diff Show More