2

Background: I am writing a script to analyze Minecraft worlds for biome diversity. For a given seed (say, 535310562), I can obtain a map of the world as an HTML Canvas from https://www.chunkbase.com/apps/biome-finder#535310562. I would like to download the canvas using R, and then count the number of unique colors (each color represents a different biome) to determine the number of biomes present.

Problem: I don't know how to analyze pixels in an HTML Canvas using R.

Possible solutions: I've thought of two ways of solving this problem. First, If there's a way to iterate through the pixels in an HTML Canvas using R, the problem becomes trivial. Second, I could first download the image as a gif/bmp/png and read the pixel values from the downloaded image.

Progress so far: I know how to index the canvas node using rvest, but I don't know where to go from here.

if (!require("rvest")) install.packages("rvest")
randomSeed <- floor(runif(1,-2147483648,2147483647))
urlBase <- paste("https://www.chunkbase.com/apps/biome-finder#",randomSeed,sep="")
biome_wbpg <- read_html(urlBase)
canvas <- html_node(biome_wbpg,"canvas")
Austin
  • 8,018
  • 2
  • 31
  • 37
  • 1
    Drawing to a canvas is done via javascript and `rvest` doesn't run javascript code, it just downloads raw data from websites. If you need to interact with a canvas element, you'll need to use something like RSelenium to basically run a web browser through R. Questions like this might also help you get started: https://stackoverflow.com/questions/38316402/how-to-save-a-canvas-as-png-in-selenium – MrFlick Aug 10 '20 at 00:01

0 Answers0