Skip to content

Commit 4c30053

Browse files
committed
fix: move ambient to suggests
1 parent 50539bc commit 4c30053

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ RoxygenNote: 7.2.3
1515
Depends:
1616
R (>= 4.1)
1717
Imports:
18-
ambient,
1918
ape,
2019
cowplot,
2120
dplyr,
@@ -39,6 +38,7 @@ Imports:
3938
tidyr,
4039
treemapify
4140
Suggests:
41+
ambient,
4242
deldir,
4343
elevatr,
4444
ggstream,

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## aRt 1.4.2
22

33
* Add `gradients()`
4+
* Move {ambient} to Suggests
45

56
## aRt 1.4.1
67

R/flow_fields.R

+42-38
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,53 @@ flow_fields <- function(n = 10000,
2626
if (!requireNamespace("particles")) {
2727
stop("Please install {particles} to use this function.")
2828
} else {
29-
set.seed(s)
30-
grid <- ambient::long_grid(seq(1, 10, length.out = granularity),
31-
seq(1, 10, length.out = granularity)) |>
32-
dplyr::mutate(
33-
x1 = .data$x + ambient::gen_simplex(x = .data$x, y = .data$y, frequency = x_freq),
34-
y1 = .data$y + ambient::gen_simplex(x = .data$x, y = .data$y, frequency = y_freq)
35-
)
29+
if (!requireNamespace("ambient")) {
30+
stop("Please install {ambient} to use this function.")
31+
} else {
32+
set.seed(s)
33+
grid <- ambient::long_grid(seq(1, 10, length.out = granularity),
34+
seq(1, 10, length.out = granularity)) |>
35+
dplyr::mutate(
36+
x1 = .data$x + ambient::gen_simplex(x = .data$x, y = .data$y, frequency = x_freq),
37+
y1 = .data$y + ambient::gen_simplex(x = .data$x, y = .data$y, frequency = y_freq)
38+
)
3639

37-
curl <- ambient::curl_noise(ambient::gen_perlin, x = grid$x1, y = grid$y1)
38-
grid$angle <- atan2(curl$y, curl$x) - atan2(grid$y1, grid$x1)
40+
curl <- ambient::curl_noise(ambient::gen_perlin, x = grid$x1, y = grid$y1)
41+
grid$angle <- atan2(curl$y, curl$x) - atan2(grid$y1, grid$x1)
3942

40-
field <- as.matrix(grid, grid$x, value = grid$angle)
43+
field <- as.matrix(grid, grid$x, value = grid$angle)
4144

42-
sim <- tidygraph::create_empty(n) |>
43-
particles::simulate(alpha_decay = 0, setup = particles::aquarium_genesis(vel_max = 0)) |>
44-
particles::wield(particles::reset_force, xvel = 0, yvel = 0) |>
45-
particles::wield(particles::field_force, angle = field, vel = 0.1, xlim = c(-5, 5), ylim = c(-5, 5)) |>
46-
particles::evolve(100, particles::record)
45+
sim <- tidygraph::create_empty(n) |>
46+
particles::simulate(alpha_decay = 0, setup = particles::aquarium_genesis(vel_max = 0)) |>
47+
particles::wield(particles::reset_force, xvel = 0, yvel = 0) |>
48+
particles::wield(particles::field_force, angle = field, vel = 0.1, xlim = c(-5, 5), ylim = c(-5, 5)) |>
49+
particles::evolve(100, particles::record)
4750

48-
traces <- data.frame(do.call(rbind, lapply(sim$history, particles::position)))
49-
names(traces) <- c("x", "y")
51+
traces <- data.frame(do.call(rbind, lapply(sim$history, particles::position)))
52+
names(traces) <- c("x", "y")
5053

51-
traces <-
52-
traces |>
53-
dplyr::mutate(particle = rep(1:n, 100)) |>
54-
dplyr::group_by(.data$particle) |>
55-
dplyr::mutate(colour = sample(line_col, 1, replace = TRUE))
54+
traces <-
55+
traces |>
56+
dplyr::mutate(particle = rep(1:n, 100)) |>
57+
dplyr::group_by(.data$particle) |>
58+
dplyr::mutate(colour = sample(line_col, 1, replace = TRUE))
5659

57-
p <- ggplot2::ggplot() +
58-
ggplot2::geom_path(data = traces,
59-
mapping = ggplot2::aes(x = .data$x,
60-
y = .data$y,
61-
group = .data$particle,
62-
colour = .data$colour),
63-
size = 0.3,
64-
alpha = alpha) +
65-
ggplot2::coord_cartesian(expand = FALSE) +
66-
ggplot2::scale_color_identity(guide = "none") +
67-
ggplot2::theme_void() +
68-
ggplot2::theme(panel.background = ggplot2::element_rect(fill = bg_col, colour = bg_col),
69-
plot.background = ggplot2::element_rect(fill = bg_col, colour = bg_col),
70-
legend.position = "none",
71-
plot.margin = ggplot2::unit(c(0, 0, 0, 0), "cm"))
72-
return(p)
60+
p <- ggplot2::ggplot() +
61+
ggplot2::geom_path(data = traces,
62+
mapping = ggplot2::aes(x = .data$x,
63+
y = .data$y,
64+
group = .data$particle,
65+
colour = .data$colour),
66+
size = 0.3,
67+
alpha = alpha) +
68+
ggplot2::coord_cartesian(expand = FALSE) +
69+
ggplot2::scale_color_identity(guide = "none") +
70+
ggplot2::theme_void() +
71+
ggplot2::theme(panel.background = ggplot2::element_rect(fill = bg_col, colour = bg_col),
72+
plot.background = ggplot2::element_rect(fill = bg_col, colour = bg_col),
73+
legend.position = "none",
74+
plot.margin = ggplot2::unit(c(0, 0, 0, 0), "cm"))
75+
return(p)
76+
}
7377
}
7478
}

0 commit comments

Comments
 (0)