Created
November 4, 2015 15:40
-
-
Save davepape/480b04b716130a9abdcc to your computer and use it in GitHub Desktop.
read earthquake data live, using Unity's WWW class, and turn that into a simple bar of a bar chart
This file contains hidden or 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 | |
| import SimpleJSON; | |
| public var min = 0; | |
| public var max = 2; | |
| public var url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.geojson"; | |
| private var dataurl : WWW; | |
| private var done = 0; | |
| function Start () | |
| { | |
| dataurl = new WWW(url); | |
| } | |
| function Update() | |
| { | |
| if ((!done) && (dataurl.isDone)) | |
| { | |
| Debug.Log(url + ' loaded'); | |
| var data = JSON.Parse(dataurl.text); | |
| 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)); | |
| done = 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment