Hi there
I am having an issue with image() loading a PGraphics object and SVG beginRecord().
I am running windows Processing 3.5.4
If beginRecord() is commented out in setup() my code runs without issue.
If beginRecord() is active, image() throws a Null Pointer Exception when called.
Interestingly if beginRecord() is called in PDF mode the NPE does not occur…
My code (as below) creates two PGraphics objects, several lines are drawn to background and a circle is drawn for a mask before an alpha masking function is applied to background. image() is called to display the resulting PGraphic.
Ideally I’d like to export an SVG of my sketch, I may be doing something wrong here but I’m struggling to work out what, any help would be greatly appreciated!
import processing.svg.*;
PGraphics background;
PGraphics mask;
float spacing = 5;
float exponent = 0.038;
float base = 3;
void setup() {
size(594, 840);
background(255);
noLoop();
//beginRecord(SVG, "ExponentialLines.svg");
}
int[] minAlphas(PImage img, PImage img2) {
img.loadPixels();
img2.loadPixels();
int[] a = new int[img.pixels.length];
for (int i =0; i<img.pixels.length; i++) {
a[i] = min(img.pixels[i] >> 24 & 0xFF, img2.pixels[i] >> 24 & 0xFF);
}
return a;
}
void draw() {
//create background and draw lots of lines!
background = createGraphics(width, height);
background.beginDraw();
background.noFill();
background.translate((width/2), 0);
for (int i=1; i<(width/spacing)/2; i++) {
background.beginShape();
for (int j=0; j<(height/spacing); j++) {
background.curveVertex((i*spacing-pow(base, j*exponent)), j*spacing);
}
background.endShape();
}
background.endDraw();
// create mask
mask = createGraphics(width, height);
mask.beginDraw();
mask.noStroke();
mask.fill(255);
mask.circle(width/2, height/2, width*.8);
mask.endDraw();
// apply mask
background.mask(minAlphas(background, mask));
image(background, 0, 0);
endRecord();
}