Created
November 18, 2015 16:00
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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