# Plot Data: x,y,r
x <- numeric(length=50)
y <- numeric(length=50)
r <- numeric(length=50)
color <- character(length=50)
for(t in 1:50) {
xy <- exp(1i * t/2 - t/12)
x[t] <- Re(xy)
y[t] <- Im(xy)
r[t] <- sqrt(x[t]^2 + y[t]^2)
color[t] <- rgb(t/50,0,1-t/50)
}
# New class object
m <- LightMapper4$new(xdim=500, ydim = 400, blend_mode = "additive")
# Map data on to raster
m$map(x=x, y=y, color = color, radius = r/30+0.01, falloff_exponent = 1, distance_exponent = 2)
# Output raster data as a dataframe
pd <- m$output_dataframe(saturation = 1)
# Plot with ggplot
ggplot(pd, aes(x = x, y = y, fill = rgb(r,g,b,a))) +
geom_raster(show.legend = FALSE) +
scale_fill_identity() +
coord_fixed(ratio = m$aspect(), xlim = m$xlim(), ylim = m$ylim(), expand = FALSE) +
theme_night(bgcolor = "black")
Run the code above in your browser using DataLab