diff --git a/Statistical-Monero-Logo/README.md b/Statistical-Monero-Logo/README.md new file mode 100644 index 0000000..b004cbb --- /dev/null +++ b/Statistical-Monero-Logo/README.md @@ -0,0 +1,11 @@ +# Statistical Monero Logo +These files create an animated gif that visually builds a Monero logo from random draws of a probability density function. + +The probability density function was constructed from the coordinates embedded in this SVG file: + +https://raw.githubusercontent.com/fluffypony/monero-logo-artefacts/master/Logo Subsequent%20Tweaks/monero%20file.svg + +To create the gif, first run data-construction.R . This may take days to complete since over 50 million observations have to be drawn from a cumulative distribution function that is created through numerical integration. Then run gif-construction.R . For best results, it is recommended to install Cairo, which is software separate from R. Read gif-construction.R for more details. + +The code itself is available under the MIT open source license. However, since the resultant gif is based on an SVG that is released under the CC BY-SA 4.0 license (the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/)), it is probably the case that the gif inherits the specified CC license. This means that you can copy and redistribute the material in any medium or format, and remix, transform, and build upon the material for any purpose, even commercially. However, when doing so you must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests The Monero Project endorses you or your use. + diff --git a/Statistical-Monero-Logo/Statistical-Monero-Logo.gif b/Statistical-Monero-Logo/Statistical-Monero-Logo.gif new file mode 100644 index 0000000..32cf829 Binary files /dev/null and b/Statistical-Monero-Logo/Statistical-Monero-Logo.gif differ diff --git a/Statistical-Monero-Logo/data-construction.R b/Statistical-Monero-Logo/data-construction.R new file mode 100644 index 0000000..1f8e974 --- /dev/null +++ b/Statistical-Monero-Logo/data-construction.R @@ -0,0 +1,94 @@ +# MIT License + +# Copyright (c) 2021 Rucknium + +# 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: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# 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. + + +# install.packages("rsvg") +# install.packages("grImport2") +# install.packages("GoFKernel") + +library(rsvg) +library(grImport2) +library(GoFKernel) + +M.svg <- grImport2::readPicture(rawToChar(rsvg::rsvg_svg("monero file.svg"))) +# From https://raw.githubusercontent.com/fluffypony/monero-logo-artefacts/master/Logo Subsequent%20Tweaks/monero%20file.svg +# https://github.com/fluffypony/monero-logo-artefacts/tree/master/Logo%20Subsequent%20Tweaks + +M.svg.grob <- grImport2::pictureGrob(M.svg) + +M.outline <- data.frame( + x = M.svg.grob$children[[1]]$children[[2]]$children[[2]]$x, + y = M.svg.grob$children[[1]]$children[[2]]$children[[2]]$y) + +M.outline$y <- (-1) * M.outline$y + max(abs(M.outline$y)) + +y.min <- min(M.outline$y) + +M.outline <- M.outline[(-1) * (which.min(M.outline$x) + 1):(which.max(M.outline$x) - 1), ] + +M.outline <- M.outline[(-1) * c(1, 9), ] + +M.outline <- M.outline + +M.outline$x <- M.outline$x - min(M.outline$x) +M.outline$x <- M.outline$x / max(M.outline$x) + +M.outline$x[2] <- M.outline$x[2] - 1e-10 +M.outline$x[5] <- M.outline$x[5] + 1e-10 +# Must add very small offset so that the non-unique x's are not dropped + +M.outline$y <- M.outline$y / integrate(approxfun(M.outline), 0, 1)$value + +M.pdf <- approxfun(M.outline) + +M.cdf <- function(x) { + f.vectorized <- Vectorize(function(y) {integrate(approxfun(M.outline), 0, y)$value}) + f.vectorized(x) +} + +M.inverse.cdf <- Vectorize(GoFKernel::inverse(M.cdf, lower = 0, upper = 1)) + +xmr.orange <- M.svg.grob$children[[1]]$children[[1]]$gp$fill +# "#FF6600FF" +xmr.grey <- M.svg.grob$children[[1]]$children[[2]]$gp$fill +# "#4C4C4CFF" + +save(M.outline, xmr.orange, xmr.grey, file = "logo-data.Rdata") + + +set.seed(314) + +generated.logo.observations <- M.inverse.cdf(runif(10)) + +# Running this loop may take days since numerical integration is slow. +for ( i in 3:48) { + + generated.logo.observations <- + c(generated.logo.observations, M.inverse.cdf(runif(floor(2^(i/2)))) ) + + save(generated.logo.observations, file = "generated-logo-observations.Rdata") + # When i = 48, y will be length 57280991 + + print(paste(i, length(generated.logo.observations) ) +} + + diff --git a/Statistical-Monero-Logo/gif-construction.R b/Statistical-Monero-Logo/gif-construction.R new file mode 100644 index 0000000..f3afd40 --- /dev/null +++ b/Statistical-Monero-Logo/gif-construction.R @@ -0,0 +1,139 @@ +# MIT License + +# Copyright (c) 2021 Rucknium + +# 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: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# 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. + + +# install.packages("animation") +# install.packages("plotrix") +# install.packages("Cairo") +# NOTE: Cairo is a general software package that cannot be installed by R alone. +# Search for installation instructions according to your operating system. + +library(animation) +library(plotrix) +library(Cairo) + +load("logo-data.Rdata", verbose = TRUE) +# max(M.outline$y) == 1.58044863212111 +# xmr.orange == "#FF6600FF" +# xmr.grey == "#4C4C4CFF" + +load("generated-logo-observations.Rdata", verbose = TRUE) +# generated.logo.observations + +# If Cairo in installed, use: +# ani.options(interval = 0.2, ani.dev = "CairoPNG") +# Otherwise, use: +ani.options(interval = 0.2) + +saveGIF({ + + y <- generated.logo.observations[1:10] + + for ( i in 3:73) { + + y <- c(y, generated.logo.observations[length(y) + (1:floor(2^(i/3-1))) ] ) + + par(mar = c(5, 0, 0, 0)) + + plot(0, 0, xlim = c(0 - 0.1, 1 + 0.1), ylim = c(0 , max(M.outline$y) * 2 ), + axes = FALSE, + ylab = "", xlab = "", main = "", col = "transparent", + asp = (1.2)/(max(M.outline$y) * 2)) + + mtext("Secure. Private. Untraceable.", side = 1, line = 0.5, cex = 2) + mtext("Resistant to statistical attack.", side = 1, line = 2.5, cex = 2) + mtext(paste0("N = ", prettyNum(length(y), big.mark = ",")), side = 1, line = 3.9, cex = 1) + + center_x = mean(c(0, 1)) + center_y = max(M.outline$y) + + plotrix::draw.ellipse(center_x, center_y, + 0.6, max(M.outline$y), + col = xmr.orange, border = NA) + + M.density <- density(y, bw = "SJ-dpi") + + polygon((c(M.density$x, M.density$x) * 1.5 - .5/2), + c(M.density$y, M.density$y * 1.5), border = NA, col = "white") + + hist(y, breaks = 50, col = xmr.grey, + axes = FALSE, border = NA, + xlim = c(0, 1), ylim = c(0, max(M.outline$y) * 2), + freq = FALSE, + ylab = "", xlab = "", main = "", add = TRUE) + + + # Pieced together from source of plotrix::draw.ellipse + draw1ellipse <- function(x, y, a = 1, b = 1, angle = 0, segment = NULL, + arc.only = TRUE, nv = 100, deg = TRUE, border = NULL, + col = NA, lty = 1, lwd = 1, ...) { + if (is.null(segment)) { + if (deg) + segment <- c(0, 360) + else segment <- c(0, 2 * pi) + } + if (deg) { + angle <- angle * pi/180 + segment <- segment * pi/180 + } + xyangle <- function(x, y, directed = FALSE, deg = TRUE) { + if (missing(y)) { + y <- x[, 2] + x <- x[, 1] + } + out <- atan2(y, x) + if (!directed) + out <- out%%pi + if (deg) + out <- out * 180/pi + out + } + z <- seq(segment[1], segment[2], length = nv + 1) + xx <- a * cos(z) + yy <- b * sin(z) + alpha <- xyangle(xx, yy, directed = TRUE, deg = FALSE) + rad <- sqrt(xx^2 + yy^2) + xp <- rad * cos(alpha + angle) + x + yp <- rad * sin(alpha + angle) + y + if (!arc.only) { + xp <- c(x, xp, x) + yp <- c(y, yp, y) + } + data.frame(x = xp, y = yp) + } + + + eclipse <- draw1ellipse(center_x, center_y, + 0.6, max(M.outline$y), + segment = c(0, 180), angle = 180) + + eclipse <- rbind(data.frame(x = min(eclipse$x), y = -0.05), + eclipse, + data.frame(x = max(eclipse$x), y = 0)) + + polygon(eclipse, col = "white", border = NA) + + print(paste(i, length(y))) + + } + +}, movie.name = "Statistical-Monero-Logo.gif") diff --git a/Statistical-Monero-Logo/monero file.svg b/Statistical-Monero-Logo/monero file.svg new file mode 100644 index 0000000..19e3dde --- /dev/null +++ b/Statistical-Monero-Logo/monero file.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + \ No newline at end of file