-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.R
executable file
·147 lines (111 loc) · 2.96 KB
/
main.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# INSTALL PACKAGE
install.packages("brickr")
# LOAD LIBRARIES
library(brickr)
library(dplyr)
# MOSAICS, LOAD ANY PHOTO OR IMAGE
myImage_R <- png::readPNG("img/R_logo.png")
myImage_R %>%
image_to_mosaic(
# DEFAULT SIZE IS "48x48" BRICKS
50,
brightness = 1,
contrast = 1,
# SETTING BRICKS TO USE
use_bricks = c("4x6", "2x4", "1x2", "1x1")
) %>%
build_mosaic()
ggplot2::ggsave("img/R_logo_bricks.png", device="png")
# 3D FROM MOSAIC, LOAD ANY PHOTO OR IMAGE
myImage_R_3D <- png::readPNG("img/R_logo.png")
myImage_R_3D %>%
image_to_mosaic() %>%
# CONVERT TO 3D BRICKS
bricks_from_mosaic() %>%
build_bricks()
# GET INSTRUCTIONS AND PIECES TO BUILD MODEL, LOAD ANY PHOTO OR IMAGE
myImageInstructions_R <- png::readPNG("img/R_logo.png") %>%
image_to_mosaic()
myImageInstructions_R %>%
build_mosaic()
# GENERATING INSTRUCTIONS
myImageInstructions_R %>%
build_instructions(9)
# GENERATING PIECES
myImageInstructions_R %>%
build_pieces()
# BUILD 3D BRICK FROM "bricks_from_table()" FUNCTION
data.frame(
Level = "A",
x1 = 33
) -> myBrick
myBrick %>%
# CONVERT INTO A BRICKR OBJECT
bricks_from_table() %>%
build_bricks()
# BUILD HOUSE 3D BRICKS FROM "bricks_from_table()" FUNCTION
tibble::tribble(
~Level, ~x1, ~x2, ~x3, ~x4, ~x5,
"A", 13, 13, 13, 13, 13,
"A", 3, 0, 0, 0, 3,
"A", 3, 0, 0, 0, 3,
"A", 3, 3, 0, 3, 3,
#---
"B", 13, 13, 13, 13, 13,
"B", 3, 0, 0, 0, 3,
"B", 3, 0, 0, 0, 3,
"B", 13, 13, 13, 13, 13,
#---
"C", 18, 18, 18, 18, 18,
"C", 13, 13, 13, 13, 13,
"C", 13, 13, 13, 13, 13,
"C", 18, 18, 18, 18, 18,
#---
"D", 0, 0, 0, 0, 0,
"D", 18, 18, 18, 18, 18,
"D", 18, 18, 18, 18, 18,
"D", 0, 0, 0, 0, 0
) -> myHouse
myHouse %>%
bricks_from_table() %>%
build_bricks()
# BUILD 3D BRICK FROM "bricks_from_coords()" FUNCTION
tibble::tibble(
x = 1, y = 1, z = 1, color = "Bright orange"
) %>%
bricks_from_coords() %>%
build_bricks()
# BUILD 3D DONALD FROM "bricks_from_coords()" FUNCTION
# X AND Y NOT INCLUDED SINCE THEY ARE CONSTANT
# "b" IS BRICK & "p" IS PLATE (1-unit)
# "mid_level" HAS 3 UNITS: 0, 1, 2
tibble::tribble(
~z, ~mid_level, ~piece_type, ~color,
# ORANGE FEET
1, 0, "b", "Bright orange",
# WHITE LEGS
2, 0, "b", "White",
# BLUE SHIRT
3, 0, "b", "Bright blue",
# ADD 2 PLATES HEIGHT
4, 0, "p", "Bright blue",
4, 1, "p", "Bright blue",
# BEAK
4, 2, "p", "Bright orange",
# HEAD
5, 0, "b", "White",
6, 0, "p", "White",
#CAP BRIM
6, 1, "p", "Black",
# CAP
6, 2, "p", "Bright blue"
) -> donaldBricks
# "tidyr::expand()" ADD X AND Y, WHILE DUPLICATING EACH
donaldBricks %>%
tidyr::expand(x=1:2, y=1:2,tidyr::nesting(z, mid_level, piece_type, color)
) -> myDonald
myDonald %>%
bricks_from_coords() %>%
build_bricks(
background_color = "#d8fdff"
)