Skip to content

Instantly share code, notes, and snippets.

@davepape
Created November 18, 2015 16:00
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 davepape/cce90fc33868d4161c77 to your computer and use it in GitHub Desktop.
Save davepape/cce90fc33868d4161c77 to your computer and use it in GitHub Desktop.
example from class, creating a texture based on SEDAC's Gridded Population of the World data (1 degree resolution)
#pragma strict
private var texture: Texture2D;
function Start() {
var color;
var s = new System.IO.File.ReadAllLines('Assets/data/glp00g60.asc');
var ncols = 360;
var nrows = 143;
texture = new Texture2D(ncols,180);
GetComponent.<Renderer>().material.mainTexture = texture;
for (var i=0; (i < nrows); i++)
{
var vals = s[i+6].Split(" "[0]);
for (var j=0; (j < ncols); j++)
{
var pop = parseFloat(vals[j]);
if (pop > 1000)
color = Color.white;
else if (pop > 0)
color = Color.gray;
else
color = Color.black;
texture.SetPixel(j,nrows-1 - i + 32,color);
}
}
texture.Apply();
}
function Update () {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment