Detecting percentage of terrain in a color

Posted April 28, 2021 by tbrass


Several of my students would like programs they're working on to not only detect the color of the terrain in a specific location (we've got that set) but also to detect percentage of terrain of a specific color.


If making a game or simulation where the ground is burning, the color is going from green to black. Is there a way to detect the percentage of terrain which is black?

If it helps, we've been using the method of creating a breed called terrain, setting the size to 200, stamping it a specified color, then deleting the breed. That works well for creating an appearance, but we aren't seeing a way to measure coverage when, for example, we have fire spreading with pen down.



Submitted by wellina on Thu, 04/29/2021 - 14:55 · Permalink

Good problem.

I am sure there are multiple ways to do this.  Here is one possibility.  Instead of deleting the breed just make them a stationary agent with a size of 1 and keep track of them.  If one is created or deleted have a data box reflect that.  Have a 2nd data box that turns the number in the 1st data box into a percentage (there are 10201 total tiles in spaceland).  

Here is an example -

Submitted by tbrass on Fri, 04/30/2021 - 13:05 · Permalink

Thanks! I'll dig into your example and give it a try.