All the points are drawn every frame. This graph is actually within a bigger graph - when you roll over a point on the bigger graph, you get this smaller one. That's where the i in the nf(i,5) comes from.
I just use the "*100-1000" to make the points fit where I want them to. I could probably find a better way to put that in the code, but this worked fine with the ellipses, so I don't think that's the problem. Here's the entire code for the graph that actually works, with the part we're working on highlighted:
Code:int numPics = 292; // change with number of points, numPics = # pictures
PImage[] pics = new PImage[numPics];
PFont font;
PFont small;
PFont large;
String[] num;
float[] values;
void setup() {
size(1000,950);
smooth();
font = loadFont("Serif-15.vlw");
small = loadFont("Serif-12.vlw");
large = loadFont("LiSongPro-32.vlw");
for ( int k = 0; k < numPics; k++) {
String imageName = "S5_stamp_" + nf(k, 5) + ".png";
pics[k] = loadImage(imageName);
}
}
void draw() {
background(255);
String[] data = loadStrings ("S5_quantities_4.txt");
for (int i = 0; i < numPics; i++) {
num = splitTokens(data[i], WHITESPACE);
values = parseFloat(num);
ellipseMode(CENTER);
stroke(150);
fill(255);
float NII = log(values[5]/values[4])/log(10);
float OIII = log(values[7]/values[6])/log(10);
if(values[8] == 1) {
fill(0,0,255);
stroke(0,0,255);
ellipse(NII*650+800,-OIII*350+350,3,3); //transform, disk
}
else if(values[8] == 2) {
fill(0,255,0);
stroke(0,255,0);
ellipse(NII*650+800,-OIII*350+350,3,3); //transform, peculiar
}
else {
fill(255,0,0);
stroke(255,0,0);
ellipse(NII*650+800,-OIII*350+350,3,3); //transform, spheroid
}
int lim = 2;
if(abs(mouseX-(NII*650+800)) < lim && //transform
abs(mouseY-(-OIII*350+350)) < lim) {
image(pics[i-1], 50, 500, 120, 120);
textFont(font);
fill(0);
text("NII/Ha" + " " + NII + " " + "OIII/Hb" + " " + OIII, 50, 630, 300, 60);
}
if (abs(mouseX-(NII*650+800)) < lim && //transform
abs(mouseY-(-OIII*350+350)) < lim) {
String spectra = "S5_hi_spectra_" + nf(i,5) + ".txt";
println(spectra);
String[] spec = loadStrings (spectra);
for (int j = 0; j < 866; j++) {
String[] spec1 = splitTokens(spec[j], WHITESPACE);
float[] spec2 = parseFloat(spec1);
pushMatrix();
pushStyle();
fill(0);
stroke(0);
translate(50,900);
scale(0.35);
ellipse(spec2[1]*100-1000, -spec2[2]*10000,1,1);
line(-11,0,951,0);
line(0,-550,0,10);
for (int k = 0; k < width; k+=100) {
line(k,0,k,20);
}
for (int k = 0; k < 600; k+=100) {
line(0,-k,-20,-k);
}
popStyle();
popMatrix();
}
textFont(small);
float[] yscale = {0.05, 0.04, 0.03, 0.02, 0.01, 0.0};
for (int k = 0; k < 6; k++) {
text(nf(yscale[k],1,2), 15, k*35+725);
}
float[] xscale = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
for (int k = 0; k < 10; k++) {
text(nf(xscale[k],0,0), k*35+45, 920);
}
text("Flux v. Wavelength", 175, 700);
}
}
// axes and scales
stroke(0);
line(0,2,width,2); //horizontal
line(width-2,-height,width-2,height); //vertical
textFont(font);
fill(0);
text("Log[NII]6584/Ha", 10, 35);
text("Log[OIII]5007/Hb", width-150, height-10);
fill(0,0,255);
text("disk", 10, 645);
fill(0,255,0);
text("peculiar", 10, 660);
fill(255,0,0);
text("spheroid", 10, 675);
fill(0);
for(int i = 0; i < height; i+=86) {
line(width-4,i,width,i);
}
float[] yscale = {
1.25, 1, 0.75, 0.5, 0.25, 0, -0.25, -0.5, -0.75, -1.0, -1.25, -1.5, -1.75};
for (int i = 0; i < 12; i++) {
text(nf(yscale[i],0,2), width-40, (i-1)*86);
}
for(int i = -13; i < width; i+=167) {
line(i,0,i,4);
}
float[] xscale = {
-1.25, -1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0};
for(int i = 1; i < 6; i++) {
text(nf(xscale[i],0,2), (i)*167-13, 15);
}
}
This draws an entire graph of ellipses, spec2[1]*100-1000 vs -spec2[2]*10000.