/*------------------------------------------------------------ Displaying live YTD stock prices using Yahoo as data source. Author: Michael Goldwasser This project is derivative of an original example acompanying the book: Processing: Creative Coding and Generative Art in Processing 2 By Ira Greenberg, Dianna Xu, and Deepak Kumar Friends of Ed (An APress Company), 2013 ISBN-13 978-1430244646 Please refer to the associated README for a full disclaimer. Copyright (c) 2013, Friends of Ed (An Apress Company) All rights reserved. ------------------------------------------------------------*/ String symbol = "GOOG"; // initial choice class Entry { float price; // we'll use adjusted close int volume; int month; int date; int year; }; Entry[] quotes; float minPrice, maxPrice; float increment = 10; // how can this be better tailored? float X1, Y1, X2, Y2; PFont legendFont = createFont("SansSerif", 20); void setup() { // drawing setup size(800, 600); X1 = 50; Y1 = 50; X2 = width - 50; Y2 = height - 50; textFont(legendFont); refresh(); } // setup() // used to (re)load stop information and to render the graph void refresh() { symbol = symbol.toUpperCase(); loadData(); drawGraph(); symbol = ""; // reset; can use keyboard to enter a new symbol } void loadData() { // Load the historical data file... String url = "http://ichart.yahoo.com/table.csv?s="; url += symbol; url += "&a=0&b=1&c=1900"; // start date url += "&d=" + (month()-1); url += "&e=" + day(); url += "&f=" + year(); url += "&ignore=.csv"; String[] lines = loadStrings(url); if (lines == null) { println("Unable to load information about symbol: " + symbol); quotes = null; } else { lines = reverse(lines); // Yahoo returns newest first // How long is the dataset quotes = new Entry[lines.length-1]; // subtract one to ignore header line // Parse the needed data for (int i=0; i= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) { symbol += key; } }