String versionString = "NPZvisualizer v1.5 "; String creditsString = "Neil Banas / UW Applied Physics Lab / banasn@u.washington.edu"; /* statemachine 1.5 : neil banas oct 08 new: -cases from v1.4 and 1.2 merged to do: -Runge-Kutta? Verlet? the timestepping is still a little hokey -figure out why achieved speed lags intended speed so often -new buttons: Record Movie, Take Snapshot, Export Data -better history graph -switch to generic_gui_classes */ String ncpath = "/Users/guest1/Desktop/"; boolean Online = true; dynamicalSystem[] systems; dynamicalSystem system; multistatePolyButton[] syschoices; toolbar controller; slider speedslider; int nan = -99999; float big = 1e10; int[] baseNetworkRect, networkRect, phasespaceRect, historyRect, syschoicesRect, paramRect, initialParamRect, U, unocc; int lastFrameTime, currSysID, nleft, dframes; float dt_desired, dt, totalN0, desired_speed, real_speed; int rewBtn, playBtn, rewParamsBtn, arrowsBtn, historyBtn, detailsBtn; int playState = 1; int stopState = 2; int showState = 2; int hideState = 1; boolean isPlaying, rewindRequested, paramResetRequested, showArrows; color activeSysColor, inactiveSysColor, bkgndColor; int errorMsg, pcount; int NSYSTEMS, initialSystem; boolean zoomed = false; dragSelector dragger = null; // graphics settings ------------------------------------------------------------------------------------ int spacing = 12; int btnSize = 24; int syschoicesAspectRatio = 5; int windowWidth, windowHeight; // ------------------------------------------------------------------------------------------------------ void setup() { size(950, 550); windowWidth = width; windowHeight = height; smooth(); createFonts("Futura-Medium",9,12,18); activeSysColor = dkGrayColor; inactiveSysColor = grayColor; bkgndColor = ltGrayColor; // polygons for toolbar poly rewindPoly = new poly(8); rewindPoly.assign3(0, 1, 1, 1, 1, 0, 2, 0.25, 0.5); rewindPoly.assign3(3, 0.25, 0, 4, 0, 0, 5, 0, 1 ); rewindPoly.assign2(6, 0.25, 1, 7, 0.25, 0.5); poly playPoly = new poly(3); playPoly.assign3(0, 0, 1, 1, 0, 0, 2, 0.866, 0.5); poly stopPoly = new poly(4); stopPoly.assign2(0, 0, 0.1, 1, 0, 0.9); stopPoly.assign2(2, 0.8, 0.9, 3, 0.8, 0.1); poly arrowsPoly = new poly(7); arrowsPoly.assign3(0, 0.5,0, 1, 0.8,0.7, 2, 0.55,0.6); arrowsPoly.assign3(3, 0.55,1, 4, 0.45,1, 5, 0.45,0.6); arrowsPoly.assign(6, 0.2,0.7); arrowsPoly.rotate(-45); poly morePoly = new poly(12); morePoly.assign3(0,.35,0, 1,.65,0, 2,.65,.35); morePoly.assign3(3,1,.35, 4,1,.65, 5,.65,.65); morePoly.assign3(6,.65,1, 7,.35,1, 8,.35,.65); morePoly.assign3(9,0,.65, 10,0,.35, 11,.35,.35); poly lessPoly = new poly(4); lessPoly.assign2(0,0,.35, 1,1,.35); lessPoly.assign2(2,1,.65, 3,0,.65); // build toolbar: rewind, play, reset params controller = new toolbar(spacing,spacing,windowWidth-2*spacing-2*btnSize,btnSize,spacing,10); rewBtn = controller.addButton(1,"left"); controller.buttons[rewBtn].assign(1,"REW","",rewindPoly,blueColor); playBtn = controller.addButton(2,"left"); controller.buttons[playBtn].assign(playState,"PLAY","",playPoly,greenColor); controller.buttons[playBtn].assign(stopState,"PAUSE","",stopPoly,redColor); controller.buttons[playBtn].current = 2; rewParamsBtn = controller.addButton(1,"right"); controller.buttons[rewParamsBtn].assign(1,"RESET PARAMS","",rewindPoly,blueColor); arrowsBtn = controller.addButton(2,"left"); controller.buttons[arrowsBtn].assign(showState,"SHOW","",arrowsPoly,blueColor); controller.buttons[arrowsBtn].assign(hideState,"HIDE","",arrowsPoly,blueColor); controller.buttons[arrowsBtn].current = 2; detailsBtn = controller.addButton(2,"left"); controller.buttons[detailsBtn].assign(showState,"MORE","INFO",morePoly,blueColor); controller.buttons[detailsBtn].assign(hideState,"LESS","INFO",lessPoly,blueColor); controller.buttons[detailsBtn].current = 2; // add speed slider unocc = controller.unoccupied(); speedslider = new slider(unocc[0],unocc[1]+round(btnSize/2),4*btnSize,round(btnSize/2),1); speedslider.showVal = true; speedslider.highlightColor = dkGrayColor; // window layout paramRect = defineRect(windowWidth-3*spacing-5*btnSize,3*spacing+round(1.5*btnSize),4*btnSize,btnSize/2); syschoicesRect = defineRect(spacing,spacing*4+btnSize,syschoicesAspectRatio*btnSize,btnSize); int availHeight = windowHeight-(btnSize+4*spacing); int historyHeight = round(availHeight/4); int networkMargin = 2*spacing; // assemble list of dynamical systems buildsystemlist(); if ((NSYSTEMS > 1) && (windowWidth>=800)) { baseNetworkRect = defineRect(2*spacing+syschoicesRect[2]+networkMargin, 2*spacing+btnSize+networkMargin, availHeight-2*networkMargin, availHeight-2*networkMargin); } else { baseNetworkRect = defineRect(spacing+networkMargin, 2*spacing+btnSize+networkMargin, availHeight-2*networkMargin, availHeight-2*networkMargin); } // create system-choices buttons and sliders for each system syschoices = new multistatePolyButton[NSYSTEMS]; for (int id=0; id1) { // add system choices syschoices[id] = new multistatePolyButton(1,syschoicesRect[0],syschoicesRect[1],syschoicesRect[2],syschoicesRect[3]); syschoices[id].assign(1,systems[id].shortname,"",rectPoly(0,0,1,1),inactiveSysColor); syschoices[id].showName = true; syschoices[id].colors[0] = lighten(inactiveSysColor); syschoicesRect[1] = syschoicesRect[1] + btnSize + spacing; } } dragger = new dragSelector(new float[] {systems[0].networkRect[0]-networkMargin, systems[0].networkRect[1]-networkMargin, systems[0].networkRect[2]+2*networkMargin, systems[0].networkRect[3]+2*networkMargin}); selectSystem(initialSystem); lastFrameTime = millis(); speedslider.setPos(0.5); } void draw() { background(bkgndColor); if (NSYSTEMS>1) { setFont("med"); for (int id=0; id1) { for (int id=0; id1) { syschoices[currSysID].colors[0] = lighten(inactiveSysColor); syschoices[currSysID].colors[1] = inactiveSysColor; } currSysID = id; if (NSYSTEMS>1) { syschoices[currSysID].colors[0] = activeSysColor; syschoices[currSysID].colors[1] = activeSysColor; } system = systems[currSysID]; system.select(); desired_speed = system.modelTimePerSecond; if (system.showFluxes) {controller.buttons[arrowsBtn].current=hideState;} else {controller.buttons[arrowsBtn].current=showState;} if (system.showDetails) {controller.buttons[detailsBtn].current=hideState;} else {controller.buttons[detailsBtn].current=showState;} if (system.showDetailsButton) {controller.buttons[detailsBtn].hidden = false;} else {controller.buttons[detailsBtn].hidden = true;} } void titleText(String title) { setFont("big"); textAlign(CENTER); fill(dkGrayColor); int[] unocc = controller.unoccupied(); int extraSpaceOnLeft = 80; textVAlign(title,unocc[0]+unocc[2]/2+extraSpaceOnLeft,unocc[1]+unocc[3]/2,bigfontsize,"middle"); } void displayCredits() { String S = versionString + " / " + creditsString; setFont("small"); fill(blueColor); if (system.showHistory) { textAlign(LEFT); text(S,smallfontsize/2,windowHeight-smallfontsize/2); } else { textAlign(RIGHT); text(S,windowWidth-smallfontsize/2,windowHeight-smallfontsize/2); } }