Skip to content

Instantly share code, notes, and snippets.

@davepape
Last active November 2, 2015 18:10
Show Gist options
  • Select an option

  • Save davepape/fca2f960ea881e1c8de3 to your computer and use it in GitHub Desktop.

Select an option

Save davepape/fca2f960ea881e1c8de3 to your computer and use it in GitHub Desktop.
example from class, making a single bar for a bar chart of earthquake magnitudes
#pragma strict
import SimpleJSON;
public var min = 0;
public var max = 2;
function Start ()
{
var datastring = System.IO.File.ReadAllText("q.json");
var data = JSON.Parse(datastring);
var i : int;
var mag : float;
var quantity : int = 0;
for (i=0; i < data["metadata"]["count"].AsInt; i++)
{
mag = data["features"][i]["properties"]["mag"].AsFloat;
if ((mag >= min) && (mag < max))
quantity = quantity + 1;
}
Debug.Log('quantity = ' + quantity);
quantity = quantity/10.0; // scale it down a bit to fit in the view better; this will depend on how many data points you have
transform.localScale = Vector3(1, quantity, 1);
transform.Translate(Vector3(0, quantity/2.0, 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment