diff --git a/src/io/files.js b/src/io/files.js index 1c4af91118..b9a0d23134 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -805,6 +805,56 @@ p5.prototype.httpPost = function () { * @param {function} [errorCallback] function to be executed if * there is an error, response is passed * in as first argument + * + * + * @example + *
+ * + * // Examples use USGS Earthquake API: + * // https://earthquake.usgs.gov/fdsnws/event/1/#methods + * + * // displays an animation of all USGS earthquakes + * var earthquakes; + * var eqFeatureIndex = 0; + * + * function preload() { + * var url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson'; + * httpDo(url, + * { + * method: 'GET', + * // Other Request options, like special headers for apis + * headers: { authorization: 'Bearer secretKey' } + * }, + * function(res) { + * earthquakes = res; + * }); + * } + * + * function draw() { + * // wait until the data is loaded + * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) { + * return; + * } + * clear(); + * + * var feature = earthquakes.features[eqFeatureIndex]; + * var mag = feature.properties.mag; + * var rad = mag / 11 * ((width + height) / 2); + * fill(255, 0, 0, 100); + * ellipse( + * width / 2 + random(-2, 2), + * height / 2 + random(-2, 2), + * rad, rad + * ); + * + * if (eqFeatureIndex >= earthquakes.features.length) { + * eqFeatureIndex = 0; + * } else { + * eqFeatureIndex += 1; + * } + * } + * + *
*/ /**