We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Colouring a SVG and drawing to screen - unknown er
Page Index Toggle Pages: 1
Colouring a SVG and drawing to screen - unknown er (Read 1018 times)
Colouring a SVG and drawing to screen - unknown er
May 17th, 2010, 4:59pm
 
Hey,

I have a SVG file which I want to load and change the colour, then redraw to screen.  I thought I had it sussed following a recent example but I am getting an error.  Can anyone help please?

Code:
PGraphics splatcolored;
PShape splat_shapeA, splat_shapeB, splat_shapeC, splat_shapeD, splat_shapeE;

void setup() {

 size(500,500);
 
 splat_shapeA = loadShape("cursorSplat1_large.svg");
 splat_shapeB = loadShape("cursorSplat2_large.svg");
 splat_shapeC = loadShape("cursorSplat3_large.svg");
 splat_shapeD = loadShape("cursorSplat4_large.svg");
 splat_shapeE = loadShape("cursorSplat5_large.svg");
 
  // SPLAT!
 stroke(-65536,5);
 fill (-65536);

 
}

void draw() {

if (mousePressed) {
      splatcolored = createGraphics(325, 324, JAVA2D);
   splatcolored.beginDraw();
   
   // Randomise between the 5 splats
   int ri = int(random(1,6));
   
   if (ri == 1) {
     splat_shapeA.disableStyle();
     splatcolored.fill(-65536);
     splatcolored.stroke(-65536);
     splatcolored.shape(splat_shapeA, 0, 0);
     splatcolored.endDraw();
     image(splatcolored, mouseX - (splatcolored.width / 2), mouseY - (splatcolored.height / 2));
   }
   else if (ri == 2) {
     splat_shapeB.disableStyle();
     splatcolored.fill(-65536);
     splatcolored.stroke(-65536);
     splatcolored.shape(splat_shapeB, 0, 0);
     image(splatcolored, mouseX - (splatcolored.width / 2), mouseY - (splatcolored.height / 2));
   }
   else if (ri == 3) {
     splat_shapeC.disableStyle();
     splatcolored.fill(-65536);
     splatcolored.stroke(-65536);
     splatcolored.shape(splat_shapeC, 0, 0);
     image(splatcolored, mouseX - (splatcolored.width / 2), mouseY - (splatcolored.height / 2));
   }
   else if (ri == 4) {
     splat_shapeD.disableStyle();  
     splatcolored.fill(-65536);
     splatcolored.stroke(-65536);
     splatcolored.shape(splat_shapeD, 0, 0);
     image(splatcolored, mouseX - (splatcolored.width / 2), mouseY - (splatcolored.height / 2));
   }
   else if (ri == 5) {
     splat_shapeE.disableStyle();
     splatcolored.fill(-65536);
     splatcolored.stroke(-65536);
     splatcolored.shape(splat_shapeE, 0, 0);
     image(splatcolored, mouseX - (splatcolored.width / 2), mouseY - (splatcolored.height / 2));
   }
   else {  
     splat_shapeC.disableStyle();
     splatcolored.fill(-65536);
     splatcolored.stroke(-65536);
     splatcolored.shape(splat_shapeC, 0, 0);
     image(splatcolored, mouseX - (splatcolored.width / 2), mouseY - (splatcolored.height / 2));
   }
}
 
}


Here is the error I get :(

Code:
Exception in thread "Animation Thread" java.lang.NullPointerException
at java.lang.System.arraycopy(Native Method)
at sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:412)
at processing.core.PGraphicsJava2D.updatePixels(Unknown Source)
at processing.core.PGraphicsJava2D.imageImpl(Unknown Source)
at processing.core.PGraphics.image(Unknown Source)
at processing.core.PApplet.image(Unknown Source)
at coloursvg.draw(coloursvg.java:74)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)

Re: Colouring a SVG and drawing to screen - unknown er
Reply #1 - May 18th, 2010, 2:08am
 
I wonder why you draw to a secondary graphic buffer instead of using shape directly on the sketch's area. You create lot of buffers with this method...
Anyway, you correctly use endDraw() on the first shape, but you forgot it on the others. You can move it, and the image() call after, at the end of the tests (like you put beginDraw() before the tests).
Re: Colouring a SVG and drawing to screen - unknown er
Reply #2 - May 18th, 2010, 2:45am
 
PhiLho  wrote on May 18th, 2010, 2:08am:
I wonder why you draw to a secondary graphic buffer instead of using shape directly on the sketch's area.


As far as i remember because he wanted to use it as cursor using cursors()
Re: Colouring a SVG and drawing to screen - unknown er
Reply #3 - May 18th, 2010, 4:38am
 
Thanks again!  Works a dream!

Yes, that is correct Cedric, thanks again for your help! Smiley
Re: Colouring a SVG and drawing to screen - unknown er
Reply #4 - May 18th, 2010, 4:50am
 
Ah, OK, it doesn't make sense in the given example (which is still nice to show the issue) but perfect sense in the given use case... Smiley
Page Index Toggle Pages: 1