// FPS test for P5 // programmed by FUKAYA Takashi (F/T) 2004.6.17 // http://dokokano.com/ /* Key operation [1] to [9] set FPS ex.) [3]=30FPS , [6]=60FPS [+],[-] inc/dec FPS [r] reset statistics [p] Play SE (RAW Style) [s] Play SE (Cooked Style) Play SE (Cooked Style) */ // setting int nFPS; // statistics int INTERVAL_NUM = 100; float fInterval[] = new float[INTERVAL_NUM]; int iInterval; float fTimeBefore; // for Draw Image float fAngle; int nYPos; int nCount; BFont bf; // for Sound BSound bsSE; int SE_NUM = 10; BSound [] bsSE2 = new BSound[SE_NUM]; float [] fPlayTime = new float[SE_NUM]; int iSE; // misc int nKeyBefore; void setup() { size(256,256); nFPS = 30; framerate(nFPS); fAngle=0; nYPos=0; nCount=0; bf = loadFont("Futura-BoldItalic.vlw.gz"); resetStat(); beginSound(); bsSE = loadSound("se.wav"); for ( int i=0; i=INTERVAL_NUM ) iInterval = 0; float fMax=0,fMin=9999,fSum=0,fAve=0; int nValid=0; for ( int i=0; i=0 ) { nValid ++; fSum += fInterval[i]; if ( fMax< fInterval[i] ) fMax = fInterval[i]; if ( fMin> fInterval[i] ) fMin = fInterval[i]; } } if ( nValid>0 ) fAve = fSum / nValid; // Draw Image background(0); push(); translate(128,128); fAngle+=PI/180*3; rotate(fAngle); noFill(); stroke(0,255,0); rect(-75,-50,150,100); pop(); nYPos++; if ( nYPos>height) nYPos = 0; line(0,nYPos,width,nYPos); nCount++; textFont(bf, 40); textMode(ALIGN_RIGHT); fill(0,255,0); text(nCount,250,250); // Key operation if ( keyPressed ) { if ( nKeyBefore != key ) { // FPS cahnge int nNewFPS = nFPS; if ( key>='1' && key<='9' ) { nNewFPS = (key-'0')*10; } if ( nNewFPS>1 && key=='-' ) nNewFPS--; if ( nNewFPS<100 && key=='+' ) nNewFPS++; if ( nNewFPS != nFPS ) { nFPS = nNewFPS; framerate( nFPS ); resetStat(); } // other if ( key=='r' ) resetStat(); if ( key=='p' ) { stop( bsSE ); play( bsSE ); } if ( key=='s' ) { playSE2(); } } nKeyBefore = key; }else{ nKeyBefore=0; } // Status textFont(bf, 24); textMode(ALIGN_LEFT); fill(255,255,255); text("Setting",10,30); text("FPS:" + nFPS ,20,50); text("Interval(ms):" + 1000/nFPS ,20,70); // graph push(); stroke(200); translate(30,240); line(-1,1,-1,-30); line(-1,1,99,1); stroke(255,0,0); for ( int i=0; i=SE_NUM ) iSE = 0; } } void autoStopSE2() { float fTime = millis()-1200; for ( int i=0; i