Output to PDF, Null Pointer Exception
This forum was so helpful yesterday, hope I'm not abusing it! I've been banging my head agains the wall for several hours now, though. This program basically creates new letterforms based on adding variables that react to Arial.
So two problems: 1) I'm getting a Null Point Exception error at run time 2) I am trying to record the outcome to a pdf (so that when someone hits 'enter' the animation stops and creates a pdf of it - see code in yellow). So far it will stop and it creates the pdf, but the pdf has an error message saying the file type isn't supported or it's damaged (the size is 0K). Any ideas? Thanks so much in advance!!
Zoohoo is telling me that my code is too long (224 lines) to include here, so I'll break it up over a couple posts.
- import processing.opengl.*;
- import geomerative.*;
- import processing.pdf.*;
- float toldist;
- RFont f;
- RGroup grupo;
- boolean restart = false;
- Particle[] psys;
- int numPoints, numParticles;
- float maxvel;
- //------------------------ Runtime properties ----------------------------------
- // Save each frame
- boolean SAVEVIDEO = false;
- boolean SAVEFRAME = false;
- boolean APPLICATION = true;
- String DEFAULTAPPLETRENDERER = P3D;
- int DEFAULTAPPLETWIDTH = 800;
- int DEFAULTAPPLETHEIGHT = 800;
- String DEFAULTAPPLICRENDERER = OPENGL;
- int DEFAULTAPPLICWIDTH = 800;
- int DEFAULTAPPLICHEIGHT = 800;
- //------------------------------------------------------------------------------
- // Text to be written
- String STRNG = "B";
- // Font to be used
- String FONT = "arial.ttf";
- // Velocity of change
- int VELOCITY = 1;
- // Velocity of deformation
- float TOLCHANGE = 0.0001;
- // Coefficient that handles the variation of amount of ink for the drawing
- float INKERRCOEFF = 0.001;
- // Coefficient that handles the amount of ink for the drawing
- float INKCOEFF = 0.1;
- // Coefficient of precision: 0 for lowest precision
- float PRECCOEFF = 4;
- String newString = "";
- int Start_Second;
- int Gray1 = 150;
- int Gray2 = 150;
- int Gray3 = 150;
- color Color_Index[]={#e02892, #9a3594, #0094d8, #3f9a5a, #f5851f, #ed1c24};
- int Mood_Trigger[] = {0,0,0,0,0,0}; int Active_Color =0;
- int Alpha = 200;
- int widthdistancia;
- void setup(){
- int w = DEFAULTAPPLICWIDTH, h = DEFAULTAPPLICHEIGHT;
- String r = DEFAULTAPPLICRENDERER;
- if(!APPLICATION){
- // Specify the width and height at runtime
- w = int(param("width"));
- h = int(param("height"));
- r = (String)param("renderer");
- // (String) will return null if param("renderer") doesn’t exist
- if (r != OPENGL && r != P3D && r != JAVA2D && r != P2D) {
- r = DEFAULTAPPLETRENDERER;
- }
- // int() will return 0 if param("width") doesn’t exist
- if (w <= 0) {
- w = DEFAULTAPPLETWIDTH;
- }
- // int() will return 0 if param(“height”) doesn’t exist
- if (h <= 0) {
- h = DEFAULTAPPLETHEIGHT;
- }
- }
- size(w,h,r);
- beginRecord(PDF, "image.pdf");
- frameRate(35);
- try{
- smooth();
- }
- catch(Exception e){
- }
- background(255);
- RG.init(this);
- widthdistancia = 10;
- f = new RFont(this.FONT,72,RFont.CENTER);
- initialize();
- Start_Second = second();
- }
- void draw(){
- pushMatrix();
- translate(width/2, height/2);
- noStroke();
- for(int i=0;i<numParticles;i++){
- for(int j=0;j<VELOCITY;j++){
- psys[i].update(grupo);
- psys[i].draw(g);
- }
- }
- popMatrix();
- toldist =1;
- }