Skip to content

Instantly share code, notes, and snippets.

@oganm
Created March 26, 2019 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oganm/2f1cb21b056b4630b52cb2dde1bda9d1 to your computer and use it in GitHub Desktop.
Save oganm/2f1cb21b056b4630b52cb2dde1bda9d1 to your computer and use it in GitHub Desktop.
terrain stuff
library(rayshader)
library(ambient)
k = 8
m = noise_perlin(dim = c(2^k,2^k),octaves = 9)
mToMap(m)
m = noise_simplex(c(2^k,2^k),fractal = 'fbm',octaves = 4,lacunarity = 2,gain = .5,frequency = .01)
mToMap(m,1.4/3)
mToMap = function(m,landRatio = 1/3){
map = m %>% ogbox::scaleToInt(0,1000)
raymat = ray_shade(map)
waterLimit = quantile(map,1-landRatio)
water = waterLimit>map
map = map - waterLimit
map %>%
round %>%
sphere_shade(texture = "desert") %>%
# add_water(water[,ncol(water):1], color="desert") %>%
add_shadow(raymat) %>% plot_3d(map,zscale=50,fov=0,theta=-45,phi=45,windowsize=c(1000,800),zoom=0.75,
water=TRUE, waterdepth = 0, wateralpha = 0.5,watercolor = "lightblue",
waterlinecolor = "white",waterlinealpha = 0.5)
map %>%
round %>%
sphere_shade(texture = "desert") %>%
add_water(water[,ncol(water):1], color="desert") %>%
plot_map()
}
addContinent = function(corner1,corner2){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment