Exporting PDF using a timer in an animation

SBDSBD
edited October 2017 in Library Questions

I've managed to export a .tiff from a timer from this animation code below. But I cannot work out how to do the same with a PDF. I've looked up the PDF ref... any help with code appreciated. This uses the hype framework (http://www.hypeframework.org/)

// sketch set up

import hype.*;
import hype.extended.layout.HGridLayout;
import hype.extended.behavior.HTimer;


int           myStageW         = 700;
int           myStageH         = 700;

color         clrBG            = #FF3300;

String        pathDATA         = "../../data/";

// ************************************************************************************************************

// sound set up

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim           minim;
AudioInput      myAudio; // to get the audio input - either a line in or a mic etc
//AudioPlayer       myAudio; // this one is to get audio in through the mp3...
FFT             myAudioFFT;

boolean         showVisualizer      = false;    

int             myAudioRange        = 11;
int             myAudioMax          = 100;

float           myAudioAmp          = 40.0;
float           myAudioIndex        = 0.2;
float           myAudioIndexAmp     = myAudioIndex;
float           myAudioIndexStep    = 0.35;

float[]         myAudioData         = new float[myAudioRange];

// ************************************************************************************************************

HDrawablePool   pool;
int             poolCols            = 5;
int             poolRows            = 5;
int             poolDepth           = 5;

//              picks are made from the ranIndex
//                                      v bass (orange)             v snare (blue)
color[]         palette             = { #000000, #666666, #666666,  #FFFFFF,   #666666, #666666, #666666, #666666, #666666, #666666, #666666 };

int             rotateNumX          = 0;
int             rotateNumY          = 0;
int             rotateNumZ          = 0;

// ************************************************************************************************************

HTimer timer;

// ************************************************************************************************************

void settings() {
    size(myStageW,myStageH,P3D);
}

void setup() {
    H.init(this).background(clrBG).use3D(true).autoClear(true);

    minim   = new Minim(this);
    myAudio = minim.getLineIn(Minim.MONO);

    // myAudio = minim.loadFile(pathDATA + "HECQ_With_Angels_Trifonic_Remix.wav");
    // myAudio.loop();

    myAudioFFT = new FFT(myAudio.bufferSize(), myAudio.sampleRate()); // buffersize = 1024 (comes from the audio file id if not specified). samplerate = 44100.00 (again, from fileif not specified).
    myAudioFFT.linAverages(myAudioRange); // calculates the average by grouping the frequency bands 'lineraly'. (using 256 here from the 'myAudioRange').
    //myAudioFFT.window(FFT.GAUSS);

    pool = new HDrawablePool(poolCols*poolRows*poolDepth);
    pool.autoAddToStage()
        .add(new HSphere())
        .layout (new HGridLayout().startX(-300).startY(-300).startZ(-300).spacing(150, 150, 150).rows(poolRows).cols(poolCols))
        .onCreate ( 
            new HCallback() {
                public void run(Object obj) {
                    int ranIndex = (int)random(myAudioRange);

                    HSphere d = (HSphere) obj;
                    d
                        .size(10)
                        .strokeWeight(0)
                        .noStroke()
                        .fill(palette[ranIndex], 225)
                        .anchorAt(H.CENTER)
                        .extras( new HBundle().num("i", ranIndex) )
                    ;
                }
            }
        )
        .requestAll()
    ;

// ************************************************************************************************************

// Timer - prints a frame every second (numCycles is in there to stop it printing tonnes whilst testing)

    timer = new HTimer()
        .numCycles(10)
        .interval(1000)
        .callback(
            new HCallback() {
                public void run(Object obj){
                    //Output
                    saveFrame("../frames/######.tif");
                }
            }

        )
    ;

}

void draw() {
    myAudioFFT.forward(myAudio.mix);
    myAudioDataUpdate();

    lights();
    sphereDetail(20);

    // do the rotation in the push/pop matrix

    pushMatrix();
        translate(width/2, height/2, -900);

        rotateX( map(rotateNumX, 0, myAudioMax, -(TWO_PI / 20), TWO_PI / 20) );
        rotateY( map(rotateNumY, 0, myAudioMax, -(TWO_PI / 20), TWO_PI / 20) );
        rotateZ( map(rotateNumZ, 0, myAudioMax, -(TWO_PI / 20), TWO_PI / 20) ) ;

        int fftRotateX = (int)map(myAudioData[0], 0, myAudioMax, -1, 20); //contolled by [0] = bass
        int fftRotateY = (int)map(myAudioData[3], 0, myAudioMax, -1, 20); //contolled by [3] = snare
        int fftRotateZ = (int)map(myAudioData[5], 0, myAudioMax, 1, -20); //contolled by [5] = can choose random one here inc another snare/bass

        rotateNumX += fftRotateX;
        rotateNumY += fftRotateY;
        rotateNumZ += fftRotateZ;

        H.drawStage();

        // draw the translucent box

        //stroke(#333333); fill(#242424, 50); box(600); noStroke(); noFill();

    popMatrix();

    for (HDrawable d : pool) {
        HBundle tempExtra = d.extras();
        int i = (int)tempExtra.num("i");

        int fftSize;
        if (i==0)       fftSize = (int)map(myAudioData[i], 0, myAudioMax, -200, 350); // bass
        else if (i==3)  fftSize = (int)map(myAudioData[i], 0, myAudioMax, 50, 350); // snare
        else            fftSize = (int)map(myAudioData[i], 0, myAudioMax, 2, 150); // snare

        d.size(fftSize);
    }

    //CALL TO WIDGET SHOULD BE THE LAST ITEM IN THE DRAW() FUNCTION, SO IT APPEARS ABOVE ALL OTHER VISUAL ASSETS
    if (showVisualizer) myAudioDataWidget();
}

void myAudioDataUpdate() {
    for(int i = 0; i < myAudioRange; ++i) {
        float tempIndexAvg = (myAudioFFT.getAvg(i) * myAudioAmp) * myAudioIndexAmp;
        float tempIndexCon = constrain(tempIndexAvg, 0, myAudioMax);
        myAudioData[i] = tempIndexCon;
        myAudioIndexAmp += myAudioIndexStep;
    }
    myAudioIndexAmp = myAudioIndex;

}

// ************************************************************************************************************

void myAudioDataWidget() {
    noLights();
    hint(DISABLE_DEPTH_TEST);
    noStroke(); fill(0, 200); rect(0, height-112, width, 102);

        for(int i = 0; i < myAudioRange; ++i) {
            fill(#CCCCCC);
            rect(10 + (i * 5), (height - myAudioData[i]) - 11, 4, myAudioData[i]);
        }
        hint(ENABLE_DEPTH_TEST);
}

// ************************************************************************************************************


void stop(){
    myAudio.close();
    minim.stop();
    super.stop();
}
Tagged:

Answers

Sign In or Register to comment.