Created
June 17, 2017 07:56
-
-
Save yutannihilation/c6d7c1d5ce140ce0406a4f757c6ec1da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# parameters --------- | |
steps <- 10000L | |
coil_turns <- 20L | |
rotation <- pi/2 | |
coil_waviness <- 100 | |
wave_height <- 1.5 | |
# image -------- | |
library(httr) | |
res <- GET("http://hoxo-m.com/img/team/makiyama.png") | |
img <- content(res) | |
f <- function(x, y) { | |
3 - sum(img[128 - floor(y), 128 - floor(x),]) | |
} | |
# data ---------------- | |
d <- tibble( | |
t = 2 * pi * seq(0, steps) / steps * coil_turns, | |
phi = t - rotation, | |
m = sin(t * 10/7), | |
x_orig = (cos(phi) + t * sin(phi)) / 2 / max(t) * 128 + 64, | |
y_orig = (sin(phi) - t * cos(phi)) / 2 / max(t) * 128 + 64, | |
f_val = purrr::map2_dbl(x_orig, y_orig, f), | |
x = x_orig + f_val * wave_height * sin(phi * coil_waviness) * sin(phi), | |
y = y_orig - f_val * wave_height * sin(phi * coil_waviness) * cos(phi) | |
) | |
# plot ------------------- | |
ggplot(d) + | |
geom_path(aes(x, y)) + | |
theme_minimal() + | |
coord_equal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment