Skip to content

Instantly share code, notes, and snippets.

@veev
Created February 17, 2012 06:11
Show Gist options
  • Save veev/1851136 to your computer and use it in GitHub Desktop.
Save veev/1851136 to your computer and use it in GitHub Desktop.
float[] volume;
float[] adjClose;
float closeY;
float time;
float index;
float volumeColor;
int width = 512;
int height = 512;
ArrayList<PVector> values;
void setup() {
size(width, height);
background(0);
values = new ArrayList();
String lines[] = loadStrings("amazon.csv");
// parse data
volume = new float [lines.length - 1];
adjClose = new float [lines.length - 1];
for ( int i = 1; i < lines.length; i++) {
String[] splits = lines[i].split(",");
volume[i - 1] = float(splits[0]);
adjClose[i - 1] = float(splits[1]);
//println(splits[0] + " " + splits[1]);
}
// map index to x and adjClose to y --> make an image
for (int i = 1; i < lines.length; i++)
{
for (int j = 1; j < adjClose.length; j++)
{
for (int k = 1; k < volume.length; k++)
{
time = map(i, 0, lines.length - 1, 0, width-1);
closeY = map(adjClose[j], min(adjClose), max(adjClose), 0, height-1);
//index = time + closeY * width;
//values[index] = volumeColor;
volumeColor = map(volume[k], min(volume), max(volume), 0, 255);
//println("index: " + index + " closing: " + closeY);
values.add(new PVector(index, closeY, volumeColor));
}
}
}
}
void draw() {
//println(closeY);
//println(index);
//stroke(255);
for (int i = 0; i < values.size(); i++)
{
PVector pt = (PVector) values.get(i);
//int index = x + y*width;
float rad = map(pt.z, 0, 255, 20, 0); // draw smaller circles at the brighter (higher) spots
fill(pt.z);
ellipse(pt.x, pt.y, rad, rad);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment