#!/usr/bin/Rscript
### Visualize the topographical csv files output by terranostra.lisp
### Daniel Vedder, 12/9/2018

world = "world_large"
w = read.csv(paste0(world, ".csv"), header=F)

jpeg(paste0(world, "_topo.jpg"))
image(as.matrix(w), col=terrain.colors(range(w)[2]-range(w)[1]))
dev.off()

cols=c()
palette = terrain.colors(range(w)[2]-range(w)[1])
for (y in 1:length(w[1,])) {
    for (x in 2:length(w[,1])) {
        cols = c(cols, palette[w[x,y]-range(w)[1]])
    }
}

l = 720*(length(w)/100)
jpeg(paste0(world, "_iso.jpg"), width=l, height=l)
persp(1:(length(w[,1])), 1:(length(w[1,])), as.matrix(w), axes=F,
      theta=110, phi=50, expand=0.4, col=cols, box=F, shade=0.5, border=NA)
dev.off()
