boolean showIt; int delay, holdi, wait, w, h; float holdr; int [] d, x, y, ix, iy, oldvarx, varx, corrord, biggest, biggestp, tx, s; float [][] datax, datay; float[] corrm, oldcorr, nux, dex, nuy, dey, corrx, corry, corr, sumcdx, sumcdy, sumcx, sumcy, sumdx, sumdy, sumc2x, sumc2y, sumd2x, sumd2y, gain; PImage donut, homer, bart, lisa, burns; int stage; void setup() { SetVariables(); frameRate(20); size(700, 600); w = width/2; h=height/2; donut = loadImage("donut.gif"); homer = loadImage("homer.gif"); bart = loadImage("bart.gif"); lisa = loadImage("lisa.gif"); burns = loadImage("burns.gif"); } void draw() { Display(); Calculate(); } void Display() { background(150); wait = wait+1 % 1000; for (int i = 0;i<9;i++) { tx[i] = tx[i] + s[i]; if (tx[i]>(width)) tx[i] = 0; if (tx[i]<0) tx[i] = width; image(donut,i*((2*h)/10)+20,400-tx[i]); } if (biggest[0] == 1 && wait > 100) image(burns, x[0]+w, 30); else image(homer, x[0]+w, 30); if (biggest[1] == 1 && wait > 100) image(burns, x[1]+w, 130); else image(bart, x[1]+w, 130); if (biggest[2] == 1 && wait > 100) image(burns, x[2]+w, 230); else image(lisa, x[2]+w, 230); if (showIt == true) fill(0); else fill (150); for (int l = 0;l<3; l++) { text(nf(corr[l], 1, 2), 100+l*160, 575); } text("Homer", 100, 550); text ("Bart", 260, 550); text ("Lisa", 425, 550); } void Calculate() { for (int i=0;i<3;i++) { x[i] = 2*(mouseX - w)+d[ix[i]]; y[i] = 2*(mouseY - h) +d[iy[i]]; x[i] = (int)((1.0- abs(corr[i]))* x[i]); y[i] = (int)((1.0- abs(corr[i]))* y[i]); x[i] = (int) (sin(TWO_PI*x[i]/( w * 4))*((float)w *.8)); y[i] = (int) (sin(TWO_PI*y[i]/((float) h * 4))*((float)h *.8)); ix[i]++; iy[i]++; if (ix[i]>199)ix[i] = 0; if (iy[i]>199)iy[i] = 0; } for (int i = 0;i<3;i++) { sumcdx [i] = sumcdx [i] + ((float) (x[i] * (float) d[ix[i]]) - (datax [i] [199] * datax [i+3] [199])); sumcdy [i] = sumcdy [i] + ((float) (y[i]* (float) d[iy[i]]) - (datay [i] [199] * datay [i+3] [199])); sumcx [i] = sumcx [i] + ((float) x[i] - datax [i] [199]); sumcy[i] = sumcy [i] + ((float) y[i] - datay [i] [199]); sumdx [i] = sumdx [i] + ((float) d[ix[i]]- datax [i+3] [199]); sumdy [i] = sumdy [i] + ((float) d[iy[i]]- datay [i+3] [199]); sumc2x [i] = sumc2x [i] + ((float) (x[i] * (float) x[i])- (datax [i] [199]*datax [i] [199])); sumc2y [i] = sumc2y [i] + ((float) (y[i] * (float) y[i])- (datay [i] [199]*datay [i] [199])); sumd2x [i] = sumd2x [i] + ((float)(d[ix[i]]* (float) d[ix[i]])- (datax [i+3] [199]*datax [i+3] [199])); sumd2y [i] = sumd2y [i] + ((float) (d[iy[i]]* (float) d[iy[i]])- (datay [i+3] [199]*datay [i+3] [199])); nux[i] = 200.0*sumcdx[i]-sumcx[i]*sumdx[i]; dex[i] = sqrt((200.0*sumc2x[i]-sumcx[i]*sumcx[i])*(200.0*sumd2x[i]-sumdx[i]*sumdx[i])); nuy[i] = 200.0*sumcdy[i]-sumcy[i]*sumdy[i]; dey[i] = sqrt((200.0*sumc2y[i]-sumcy[i]*sumcy[i])*(200.0*sumd2y[i]-sumdy[i]*sumdy[i])); oldcorr[i] = corr [i]; if (dex[i]>0.0) corrx[i] = nux[i]/dex[i]; else corrx [i] = 0.0; if (dey[i]>0.0) corry[i] = abs(nuy[i]/dey[i]); else corry [i] = 0.0; corr[i] = abs(corrx[i]); corrm[i] = corr[i]; } for (int j = 199;j>0;j--) { for (int k = 0;k<6;k++) { datax [k] [j] = datax [k] [j-1]; datay [k] [j] = datay [k] [j-1]; } } for (int l = 0;l<3;l++) { datax [l] [0] = (float) x[l]; datax [l+3] [0] = (float) d[ix[l]]; datay [l] [0] = (float) y[l]; datay [l+3] [0] = (float) d[iy[l]]; biggestp[l] = biggest[l]; biggest[l] = 0; corrord[l] = l; } for (int m = 0;m<2; m++) { for (int n = m+1;n<3;n++) { if (corrm[n].5) s[i] = int(random(10)+2); else s[i] = int ((-1*(random(10)+2))); } }