img2grid

Creates grid-art from images
git clone https://src.jayvii.de/pub/img2grid.git
Log | Files | Refs

commit a9d0d1c85352fb937866e88058129b886eb8f1ab
parent bf71c739b3a5638965c748c31d4311df68f016da
Author: JayVii <jayvii@posteo.de>
Date:   Sat, 21 Dec 2019 15:37:27 +0100

CleanUp: Deleting unnecessary parts

Diffstat:
Mcologne/img2grid.R | 28+++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/cologne/img2grid.R b/cologne/img2grid.R @@ -1,13 +1,19 @@ -# Copyright (c) 2018 Jan "JayVii" <jayvii@posteo.de> +# Copyright (c) 2018-2019 Jan Weymeirsch +# Author 2019 Jan Weymeirsch # SPDX-License-Identifier: GPL-3.0 +# About this header: <https://reuse.software> # Load Packages ---------------------------------------------------------------- # {{{ +# Loading images if(!require(imager)){ install.packages("imager"); library(imager) } + +# graphics if(!require(ggplot2)){ install.packages("ggplot2"); library(ggplot2) } + +# convenience functions if(!require(dplyr)){ install.packages("dplyr"); library(dplyr) } -#if(!require(geosphere)){ install.packages("geosphere"); library(geosphere) } # }}} @@ -91,7 +97,6 @@ data <- data.df %>% # Scale data and calculate distances between each point data_st <- data / max(data) distances <- dist.xy(x = data_st[, "x"], y = data_st[, "y"], fast = TRUE) -#distances <- distm(x = data_st) # dirty. FIXME (assumes ellipsoid or sphere) #distances <- which.dist(x = data_st[, "x"], y = data_st[, "y"], values = 50, # verbose = TRUE) @@ -101,17 +106,12 @@ for (i in 1:nrow(distances)){ near[i,] <- order(distances[i,], decreasing = FALSE) } -# plot the result {{{ ---- +# }}} -ratios <- sapply(X = data, FUN = function(a){ - max(a) - min(a) - }) -ratios <- ratios["x"] / ratios["y"] +# plot the result {{{ ---- -# we want a PDF file from that (10" x 10") +# use height and width of original image for equal proportions png(file = "./bridge_grid.png", height = 4000, width = 6000, bg = "#00000000") -#pdf(file = "./bridge_grid.pdf", height = 10, width = 10 * ratios, - #bg = "#00000000") # without margins around plot par(mar=c(0, 0, 0, 0)) @@ -120,9 +120,9 @@ png(file = "./bridge_grid.png", height = 4000, width = 6000, bg = "#00000000") plot(-data_st, type = "l", col = rgb(0,0,0,alpha = 0), axes = FALSE, xlab = "", ylab = "", main = "") - # add lines connecting the nearest 20 xy-pairs to current point + # add lines connecting the nearest 50 xy-pairs to current point # also mirror data points (-) - # color is black with some low alpha value + # color is white with 50% alpha for (i in 1:length(data_st$x)){ cat(paste(i, "\n")) lines(-data_st[near[i, 1:50],], type = "l", @@ -132,3 +132,5 @@ png(file = "./bridge_grid.png", height = 4000, width = 6000, bg = "#00000000") dev.off() # }}} + +# EOF img2grid.R