import processing.opengl.*; import traer.physics.*; import lll.wrj4P5.*; import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; // globals - need a physics and a sound machine and a wii and some pictures ParticleSystem physics; SoundStar[] starbits; Particle orbiter, stationary,comet; Attraction superGrav,cometlink; AudioOutput sound; Wrj4P5 wii; PImage orbitimg, starimg, cometimg,gravfield,cometalpha,halo; PFont graphFont,announce; int skheight,skwidth; int wiiconnected; // crappy bookkeeping junk int loopcount,counter,timekeeper; float orbitx,orbity,cometx,comety; color gravfil; float cr,cg,cb; String[] axisname; //sound modelling stuff float distcon; //wiitracking stuff int axis; float tempx; float[] xTime,yTime,zTime,workArray,wiiVal,sa,la; //wiiVal, small average and large average become arrays for fun-flipping purposes void setup(){ //setup screen skheight = 700; skwidth = 800; size(skwidth,skheight,OPENGL); frameRate(25); smooth(); graphFont = loadFont("Consolas.vlw"); announce = loadFont("narkisim.vlw"); //setup generics distcon = 10000; wiiconnected = 1; axis = 0; axisname = new String[3]; axisname[0] = "X"; axisname[1] = "Y"; axisname[2] = "Z"; //image loading and masking (alpha) orbitimg = loadImage("star.jpg"); orbitimg.mask(orbitimg); starimg = loadImage("star.jpg"); starimg.mask(starimg); cometimg = loadImage("moon.jpg"); cometalpha = loadImage("moonalpha.jpg"); cometimg.mask(cometalpha); gravfield = loadImage("gravityalpha.bmp"); gravfield.mask(gravfield); halo = loadImage("halo.jpg"); halo.mask(halo); workArray = new float[100]; //starfield tint: cb = 0.0; cr = 0.0; cg = 0.0; //setup wiimote + tracking! wiiVal = new float[3]; wiiVal[0] = 500; sa = new float[3]; sa[0] = 500; xTime = new float[25]; yTime = new float[25]; zTime = new float[25]; for (int c=0;c<=24;c++){ xTime[c] = 0.0; yTime[c] = 0.0; zTime[c] = 0.0; } wii = new Wrj4P5(this); wii.connect(); //setup physics physics = new ParticleSystem(0,0); orbiter = physics.makeParticle(1,random(0,width),random(0,height),0); stationary = physics.makeParticle(10,width/2,height/2,0); stationary.makeFixed(); superGrav = physics.makeAttraction(stationary,orbiter,5000,100); superGrav.turnOff(); comet = physics.makeParticle(5,random(0,width),random(0,height),0); cometlink = physics.makeAttraction(comet,orbiter,500,50); //setup sound Minim.start(this); sound = Minim.getLineOut(Minim.STEREO); //generate soundstars - I will want to replace this with a function which does them randomly but nicely spread out, later. starbits = new SoundStar[50]; //starbits[0] = new SoundStar(400,100); for (int a=110; a<=590; a+=120){ int spacemod; //a = x -> we want every second y level to be displaced in x loopcount =0; for (int b=110; b<=590; b+=104){ loopcount++; //counts loops for odd or even if ((loopcount%2)>0){ spacemod= -60; } else { spacemod= 0; } starbits[counter] = new SoundStar (a-spacemod, b); counter++; } } } void draw(){ //if (wii.isConnecting()) return; // time since last comet meeting timekeeper++; //fade-wipe fill(0,0,0,50); rect(0,0,skwidth,skheight); //wii processing - this should give us a slightly smoothed wii from -1000 to 1000 //tempx = wii.rimokon.senced.x; wiiVal[0] = (50 * int(20*wii.rimokon.senced.x)); wiiVal[1] = (50 * int(-20*wii.rimokon.senced.y)); wiiVal[2] = (50 * int(20*wii.rimokon.senced.z)); arraycopy(xTime,1,xTime,0,24); arraycopy(yTime,1,yTime,0,24); arraycopy(zTime,1,zTime,0,24); xTime[24]=wiiVal[0]; yTime[24]=wiiVal[1]; zTime[24]=wiiVal[2]; // replace wiiVal with smallAverage, for smoothing purposes. float saX=0.0; float saY=0.0; float saZ=0.0; for (int a=20;a<=24;a++){ //last 5 frames worth for averaging saX+=xTime[a]; saY+=yTime[a]; saZ+=zTime[a]; } sa[0] = saX/5; sa[1] = saY/5; sa[2] = saZ/5; //draw gravity indicators - zero point and current value: stroke(0,255,0); float zeropoint = map(0,1000,-1000,0,skheight); float heightmap = map(sa[axis],1000,-1000,0,skheight); line (10,heightmap,30,heightmap); stroke (255); line (0,zeropoint,40,zeropoint); fill (255); textFont(graphFont); text("+\n0 GRAVITY\n-",50,zeropoint-2.5); text(axisname[axis],10,10); //get orbit position orbitx = orbiter.position().x(); orbity = orbiter.position().y(); //get comet position cometx = comet.position().x(); comety = comet.position().y(); //alter orbit position if need be if(orbitx<0) orbitx=width; if(orbitx>width) orbitx=0; if(orbity<0) orbity=height; if(orbity>height) orbity=0; orbiter.moveTo(orbitx,orbity,0); //alter comet position if need be if(cometx<0) cometx=width; if(cometx>width) cometx=0; if(comety<0) comety=height; if(comety>height) comety=0; comet.moveTo(cometx,comety,0); //check distance if (dist(cometx,comety,orbitx,orbity)<50){ if (timekeeper >25) { axis++; if (axis >1) axis = 0; // set this test to >2 for Z-axis timekeeper =0; } if (random(0,1)>0.5) wii.rimokon.vibrateFor(20); } //move physics physics.tick(0.25); //starfield distort colour; if (wiiVal[axis]>40){ //blue cb = map(wiiVal[axis],0,1000,0,255); cr = 0.0; } if (wiiVal[axis]<-40){ //red cr = map(wiiVal[axis],0,-1000,0,255); cb = 0.0; } //draw starbits tint(180, 180, 255, 126); for (int a=0; a