-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow_fields.R
209 lines (192 loc) · 7.34 KB
/
flow_fields.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
library(tidyverse)
library(ambient)
library(particles)
library(tidygraph)
library(ggforce)
library(data.table)
# # https://github.com/aschinchon/general-2D-map/blob/master/general_2d_map.R
# # https://www.williamrchase.com/post/2019/02/28/strange-attractors-12-months-of-art-february/
# # https://github.com/marcusvolz/mathart
#
# grid <- long_grid(seq(1, 10, length.out = 1000), seq(1, 10, length.out = 1000)) %>%
# mutate(noise = gen_simplex(x, y))
#
# curl <- curl_noise(gen_perlin, x = grid$x, y = grid$y)
#
# grid$angle <- atan2(curl$y, curl$x) - atan2(grid$y, grid$x)
#
# field <- as.matrix(grid, x, value = angle)
#
# sim <- create_empty(1000) %>%
# simulate(alpha_decay = 0, setup = aquarium_genesis(vel_max = 0)) %>%
# wield(reset_force, xvel = 0, yvel = 0) %>%
# wield(field_force, angle = field, vel = 0.1, xlim = c(-5, 5), ylim = c(-5, 5)) %>%
# evolve(100, record)
#
# traces <- data.frame(do.call(rbind, lapply(sim$history, position)))
# names(traces) <- c('x', 'y')
# traces$particle <- rep(1:1000, 100)
#
# #triangles
# ggplot(traces[1:100, ]) +
# geom_regon(aes(x0 = x, y0 = y, r = 1, angle = runif(100) * 180, sides = 3), size = 0.1, alpha = 0.1) +
# theme_void() +
# theme(legend.position = 'none')
#
# # sandy effect
# seed <- sample(1:2000, 1)
# grid <-
# long_grid(x = seq(0, 10, length.out = 1000),
# y = seq(0, 10, length.out = 1000)) %>%
# mutate(
# x1 = x + gen_perlin(x = x, y = y, frequency = 2, seed = seed), # tweak noise
# y1 = y + gen_perlin(x = x, y = y, frequency = 0.5, seed = seed)
# )
#
# curl <- curl_noise(gen_cubic, seed = seed, x = grid$x1, y = grid$y1) # change the gen_
#
# grid$angle <- atan2(curl$y, curl$x) - atan2(grid$y, grid$x) # tweak
#
# field <- as.matrix(grid, x, value = angle)
#
# sim <- create_ring(10000) %>%
# simulate(alpha_decay = 0, setup = petridish_genesis(vel_max = 0, max_radius = 1)) %>% # tweak velocity
# wield(reset_force, xvel = 0, yvel = 0) %>%
# wield(field_force, angle = field, vel = 0.15, xlim = c(-50, 40), ylim = c(-50, 40)) %>%
# evolve(100, record)
#
# traces <- data.frame(do.call(rbind, lapply(sim$history, position)))
# names(traces) <- c('x', 'y')
# traces$particle <- rep(1:10000, 100)
#
# bl_yl <- c('#C29F5B', '#C26F5B')
# bl_yl_bg <- '#EEEEEE'
#
# traces2 <-
# traces %>%
# group_by(particle) %>%
# mutate(color = sample(bl_yl, 1, replace = TRUE))
#
# # flow trace 1 ------------------------------------------------------------
# flow_trace1 <-
# ggplot(traces2[1:20000, ]) +
# geom_path(aes(x, y, group = particle, color = color), size = 0.035, alpha = 0.6) +
# scale_color_identity(guide = "none") +
# theme_void() +
# theme(legend.position = 'none', panel.background = element_rect(fill = "#3A6E78"))
# ggsave("flow_trace1.png", flow_trace, width = 14, height = 12, dpi = "retina")
# flow trace 2 ------------------------------------------------------------
# seed <- sample(1:2000, 1)
# grid <-
# long_grid(x = seq(0, 10, length.out = 1000),
# y = seq(0, 10, length.out = 1000)) %>%
# mutate(
# x1 = x + gen_perlin(x = x, y = y, frequency = 2, seed = seed), # tweak noise
# y1 = y + gen_perlin(x = x, y = y, frequency = 0.5, seed = seed)
# )
#
# curl <- curl_noise(gen_cubic, seed = seed, x = grid$x1, y = grid$y1) # change the gen_
#
# grid$angle <- atan2(curl$y, curl$x) - atan2(grid$y, grid$x) # tweak
#
# field <- as.matrix(grid, x, value = angle)
#
# sim <- create_ring(10000) %>%
# simulate(alpha_decay = 0, setup = petridish_genesis(vel_max = 0, max_radius = 1)) %>% # tweak velocity
# wield(reset_force, xvel = 0, yvel = 0) %>%
# wield(field_force, angle = field, vel = 0.15, xlim = c(-50, 40), ylim = c(-50, 40)) %>%
# evolve(100, record)
#
# traces <- data.frame(do.call(rbind, lapply(sim$history, position)))
# names(traces) <- c('x', 'y')
# traces$particle <- 1:100
#
# bl_yl <- c('#C29F5B', '#C26F5B')
# bl_yl_bg <- '#EEEEEE'
#
# traces2 <-
# traces %>%
# group_by(particle) %>%
# mutate(color = sample(bl_yl, 1, replace = TRUE))
#
# flow_trace1 <-
# ggplot(traces2) +
# geom_path(aes(x, y, group = particle, color = color), size = 0.035, lineend = "round", alpha = .1) +
# scale_color_identity(guide = "none") +
# theme_void() +
# theme(legend.position = 'none', panel.background = element_rect(fill = alpha("#3A6E78", .4)))
# ggsave("flow_trace2.png", width = 14, height = 12, dpi = "retina")
# flow trace 3 ------------------------------------------------------------
# seed <- sample(1:2000, 1)
# grid <-
# long_grid(x = seq(0, 10, length.out = 1000),
# y = seq(0, 10, length.out = 1000)) %>%
# mutate(
# x1 = x + gen_perlin(x = -x, y = y, frequency = 2), # tweak noise
# y1 = y + gen_perlin(x = x, y = y, frequency = 0.5)
# )
#
# curl <- curl_noise(gen_worley, seed = 1, x = grid$x1, y = grid$y1) # change the gen_
#
# grid$angle <- atan2(curl$y, curl$x) - atan2(grid$y, grid$x) # tweak
#
# field <- as.matrix(grid, x, value = angle)
#
# sim <- create_ring(10000) %>%
# simulate(alpha_decay = 0, setup = petridish_genesis(vel_max = 0, max_radius = 1)) %>%
# wield(reset_force, xvel = 0, yvel = 0) %>%
# wield(field_force, angle = field, vel = 0.15, xlim = c(-50, 40), ylim = c(-50, 40)) %>% # tweak velocity
# evolve(100, record)
#
# traces <- data.frame(do.call(rbind, lapply(sim$history, position)))
# names(traces) <- c('x', 'y')
# traces$particle <- 1:100
#
# bl_yl <- hcl.colors(4, "Berlin")
# bl_yl_bg <- '#EEEEEE'
#
# traces2 <-
# traces %>%
# group_by(particle) %>%
# mutate(color = sample(bl_yl, 1, replace = TRUE))
#
# flow_trace1 <-
# ggplot(traces2) +
# geom_path(aes(x, y, group = particle, color = color), size = 0.035, lineend = "round", alpha = .5) +
# scale_color_identity(guide = "none") +
# theme_void() +
# theme(legend.position = 'none', panel.background = element_rect(fill = alpha("#3A6E78", .4)))
# ggsave("flow_trace3.png", width = 14, height = 12, dpi = "retina")
# flow trace 4 ------------------------------------------------------------
seed <- sample(1:2000, 1)
grid <-
long_grid(x = seq(0, 10, length.out = 1000),
y = seq(0, 10, length.out = 1000)) %>%
mutate(
x1 = x + gen_perlin(x = -x, y = y, frequency = 2), # tweak noise
y1 = y + gen_perlin(x = x, y = y, frequency = 0.5)
)
curl <- curl_noise(gen_perlin, seed = 1, x = grid$x1, y = grid$y1) # change the gen_
grid$angle <- atan2(curl$y, curl$x)* - 1 - atan2(grid$y, grid$x) # tweak
field <- as.matrix(grid, x, value = angle)
sim <- create_ring(10000) %>%
simulate(alpha_decay = 0, setup = petridish_genesis(vel_max = 0, max_radius = 1)) %>%
wield(reset_force, xvel = 0, yvel = 0) %>%
wield(field_force, angle = field, vel = 0.15, xlim = c(-50, 40), ylim = c(-50, 40)) %>% # tweak velocity
evolve(100, record)
traces <- data.frame(do.call(rbind, lapply(sim$history, position)))
names(traces) <- c('x', 'y')
traces$particle <- 1:1000
bl_yl <- hcl.colors(4, "Berlin")
bl_yl_bg <- '#EEEEEE'
traces2 <-
traces %>%
group_by(particle) %>%
mutate(color = sample(bl_yl, 1, replace = TRUE))
flow_trace1 <-
ggplot(traces2) +
geom_path(aes(x, y, group = particle, color = color), size = 0.035, lineend = "round", alpha = .5) +
scale_color_identity(guide = "none") +
theme_void() +
theme(legend.position = 'none', panel.background = element_rect(fill = alpha("#3A6E78", .4)))
ggsave("flow_trace4.png", width = 14, height = 12, dpi = "retina")