Skip to content

Instantly share code, notes, and snippets.

View davepape's full-sized avatar

Dave Pape davepape

View GitHub Profile
#pragma strict
public var rows = 30;
public var cols = 30;
private var myVertices = Array();
private var myUVs = Array();
private var myTriangles = Array();
function Start ()
@davepape
davepape / plotquakes.js
Last active November 2, 2015 18:20
Visualize earthquake data from USGS
#pragma strict
// Script to visualize earthquake data in GeoJSON format from USGS
// (http://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php)
// Requires the SimpleJSON plugin from http://wiki.unity3d.com/index.php/SimpleJSON
// The script should be attached to a model of the Earth such as a sphere
// with a 20 unit diameter. A prefab to use for marking the quakes should
// be assigned to the variable "prefab" in the Unity editor.
import SimpleJSON;
@davepape
davepape / barchart.js
Last active November 2, 2015 18:10
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");
@davepape
davepape / barchart3.js
Created November 4, 2015 15:40
read earthquake data live, using Unity's WWW class, and turn that into a simple bar of a bar chart
#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;
@davepape
davepape / airnow-linegraph.js
Last active November 11, 2015 15:53
Plot some AirNow data as a line graph
#pragma strict
// Script to take AirNow AQI data and turn it into a line graph
// Data is assumed to be a time sequence for a single station, from the "Observations by Monitoring Site" query tool
// The data file should be in JSON format, and placed in a folder called "data" within the Assets folder
// This must be attached to a GameObject that has a Mesh Renderer and an empty Mesh Filter
// Using a Mesh Renderer, rather than a Line Renderer, allows us to set per-vertex colors.
import SimpleJSON;
@davepape
davepape / plotaqi.js
Created November 16, 2015 15:52
Plot AQI data from AirNow, similar to the plotquakes.js example
#pragma strict
// Script to visualize AQI data in JSON format from airnowapi.org
// Requires the SimpleJSON plugin from http://wiki.unity3d.com/index.php/SimpleJSON
// The script should be attached to a model of the Earth such as a sphere
// scaled by a factor of 20 and positioned at (0,0,0). A prefab to use for marking
// the readings should be assigned to the variable "prefab" in the Unity editor.
import SimpleJSON;
@davepape
davepape / gpw.js
Created November 18, 2015 16:00
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);
#pragma strict
// Script that creates a Unity mesh with 2 triangles, with per-vertex colors
// Note that this requires the vertexColor shader (https://gist.github.com/davepape/6b74369986ff6324c47a)
// to also be in your project's assets
function Start () {
gameObject.AddComponent(MeshFilter);
gameObject.AddComponent(MeshRenderer);
GetComponent(Renderer).material = new Material(Shader.Find("Custom/Vertex Colored"));
#pragma strict
// Script to create a Unity mesh containing a sphere
// The sphere is warped with a sine wave pattern over time
var verts1 : Vector3[];
function Start () {
gameObject.AddComponent(MeshFilter);
gameObject.AddComponent(MeshRenderer);
@davepape
davepape / plotquakes2.js
Created March 1, 2017 17:53
plot earthquake data from USGS - uses WWW module and JSONObject plugin
#pragma strict
// Script to visualize earthquake data in GeoJSON format from USGS
// (http://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php)
// Requires the JSONObject plugin from http://wiki.unity3d.com/index.php/JSONObject
// The script should be attached to a model of the Earth such as a sphere
// with a 20 unit diameter. A prefab to use for marking the quakes should
// be assigned to the variable "prefab" in the Unity editor.
import JSONObject;