-
Notifications
You must be signed in to change notification settings - Fork 310
Optical Illusion
Thomas Lin Pedersen edited this page Sep 4, 2018
·
3 revisions
submitted by Colin Fay
This animation is an example of a “gradient illusion”, which is an illustration of how the perception of a color is influenced by the surrounding of this color.
When looking at the animation, we perceive the color in the square as changing (from darker to lighter), when in fact it stays the same (as you can see, the fill
is argument is always #7E7E7E
).
# Coordinates for 10 squares
d <- data.frame(
x1 = 1:10, x2 = 2:11,
y1 = 4, y2 = 5,
t = 1:10
)
# Creating the gradient background
library(grid)
g <- rasterGrob(
t(colorRampPalette(c("#000000", "#FFFFFF"))(1000)),
width = unit(1, "npc"), height = unit(1, "npc")
)
# Creating the animation
library(ggplot2)
library(ggmap) # For theme_nothing()
library(gganimate)
ggplot() +
annotation_custom(g, -Inf, Inf, -Inf, Inf) +
geom_rect(
data = d,
mapping = aes(xmin = x1, xmax = x2, ymin = y1, ymax = y2),
color = "black", fill = "#7E7E7E"
) +
ylim(c(1, 8)) +
theme_nothing() +
transition_time(t)
Remaking ‘Luminance-gradient-dependent lightness illusion’ with R
Install gganimate using devtools::install_github('thomasp85/gganimate')
The Grammar
Misc
Examples