-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
135 lines (109 loc) · 5.24 KB
/
README.Rmd
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
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-")
```
# scanline <img src="data-raw/scanline-hex/hex.png" align="right" height="160"/>
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
## Update
* June 2023
* **This project is in development and is buggy - it is not a finished product!**
* I have completely re-written `{scanline}` after stumbling upon [Ole Ivar Rudi’s CRT scanline hack](https://twitter.com/oleivarrudi/status/895665025251123201?s=20).
* **There are a tonne of breaking changes - nothing will work as before!**
* The return image is still a ggplot render, but the parametrisation is very different
* Please log any bugs you find!
## Intro
* I have always loved the aesthetic feel of David Fincher's Alien 3 film. From the cavernous, brutal and liminal environments, to the desolate and isolated nature of the story. In fact, I have always really loved the aesthetic of the Alien films in general, and more recently the incredible Alien Isolation game.
* At the start of Alien 3, several 'retro-futuristic' scanline portrait images are seen (shown below), and I was keen to see if I could recreate this scanline style for any given image with R.
* This project has been on the back-burner for a long time, but the rough code I initially wrote years ago has now turned into this `{scanline}` package. This package is super niche and is just for fun.
```{r fig.height = 3, fig.width = 9, echo=FALSE, fig.subcap='Alien 3 scanline images'}
patchwork::wrap_plots(
magick::image_read('data-raw/ripley.png') |> magick::image_ggplot(),
magick::image_read('data-raw/hicks.png') |> magick::image_ggplot(),
magick::image_read('data-raw/bishop.png') |> magick::image_ggplot()) &
ggplot2::theme(plot.margin = ggplot2::unit(c(1,1,1,1), "mm"))
```
* `{scanline}` can be installed from github
```{r, eval=FALSE}
remotes::install_github('https://github.com/cj-holmes/scanline')
```
* Add `{scanline}` to the search path
```{r warning=FALSE, message=FALSE}
library(scanline)
```
## Example outputs
* The default arguments try to replicate the overall feel of the original scanline images shown above. However, custom parameters can be chosen to significantly change the look of the output
### Ripley
```{r fig.width=3, fig.height=3*(438/780)}
i <- 'https://www.looper.com/img/gallery/why-alien-3-almost-never-got-released/intro-1632832833.jpg'
magick::image_read(i) |> magick::image_ggplot()
```
```{r out.width="75%", dpi = 600, fig.width=6, fig.height=6*0.614}
scanline(i, n_scanlines = 50)
```
### Dillon
* Apparently he likes R
```{r out.width="50%", dpi = 600, fig.width=6, fig.height=6*(1365/2048)}
i <-
'https://m.media-amazon.com/images/M/MV5BMTM0OTI2MTg0MV5BMl5BanBnXkFtZTcwNjg3ODEyMw@@._V1_.jpg' |>
magick::image_read() |>
magick::image_resize("x500")
magick::image_ggplot(i)
```
```{r out.width="75%", dpi = 600, fig.width=6, fig.height=6*0.8299319}
i |>
magick::image_extent(geometry = "x600" ,color = "black", gravity = "north") |>
magick::image_annotate("I like R", size = 80, color = "white", gravity = "south", font = "Alien3") |>
scanline(n_scanlines = 100)
```
## Clemens
```{r fig.width=3, fig.height=3*(240/320)}
i <- 'https://i.pinimg.com/originals/35/3c/40/353c40acae809215af994c06ea10d86d.jpg'
magick::image_read(i) |> magick::image_ggplot()
```
```{r out.width="75%", dpi = 600, fig.width=6, fig.height=6*0.79166}
scanline(i)
```
## Morse
```{r fig.width=3, fig.height=3*(600/483)}
i <- 'https://static.wikia.nocookie.net/alienanthology/images/3/3b/Alien_3_Danny_Webb1.jpg/revision/latest?cb=20210320141122'
magick::image_read(i) |> magick::image_ggplot()
```
* Noise can also be added to achieve a certain aesthetic
```{r out.width="75%", dpi = 600, fig.width=6, fig.height=6*1.181}
scanline(i, n_scanlines = 100, add_noise = TRUE)
```
## GIFs
* Gif from [here](https://garrettzecker.files.wordpress.com/2017/04/alien-1979.gif)
```{r out.width="75%", warning = FALSE, message = FALSE, echo=FALSE}
magick::image_read('data-raw/alien-1979.gif')
```
* `scanline_gif()` is an experimental function for creation of gifs
```{r out.width="75%", warning = FALSE, message = FALSE}
scanline_gif('data-raw/alien-1979.gif', width = 762, height = 456, add_noise = TRUE)
```
## Charts
* **Not recommended!!** - but you absolutely could make your plots look like they are being viewed on a terminal onboard the Nostromo! Using the `{magick}` graphics device to create an image of the plot which is then passed to `scanline()`
```{r fig.width=9, fig.height=5.4, dpi = 600}
library(ggplot2)
fig <- magick::image_device(1800, 1000, res = 450)
diamonds |>
ggplot() +
geom_density(aes(price, after_stat(scaled)), fill = "grey70")+
stat_ecdf(aes(price))+
theme_linedraw()+
theme(panel.grid = element_blank())+
labs(
title = "Diamond price distribution",
x = "Price",
y = "Scaled density")
dev.off()
fig |> magick::image_negate() |> scanline(n_scanlines = 160, border_size = 0, frame_size = 0)
```