# Problems with .svg libraries

**URL:** <https://discourse.processing.org/t/problems-with-svg-libraries/19206>\
**Category:** Coding Questions\
**Created:** [March 30, 2020, 8:10pm UTC](https://discourse.processing.org/t/problems-with-svg-libraries/19206 "2020-03-30T20:10:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CheckschDa](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@CheckschDa](https://discourse.processing.org/u/CheckschDa)\
**Post date:** [March 30, 2020, 8:10pm UTC](https://discourse.processing.org/t/problems-with-svg-libraries/19206/1 "2020-03-30T20:10:56Z")

</div>

Hello  
I’m having some Problems withe the .svg library. I wanted to write a little code, which should export 15 .svg files. But its only exporting the last one. Is my Code broken or is the .svg exporter not able to export multiple .svg? I am new to coding and therefore maybe made a mistake.

Regards 🙂

```auto
import processing.svg.*;
//import processing.pdf.*;

int screenX=100;
int screenY=100;
boolean [][] screen = new boolean[screenX][screenY];
final int farbeWeiss=0;
final int farbeSchwarz=1;
// Wert 0 Wert 1
color [] c = { color(255,255,255), color(0,0,0)};
int maxDateien=15;

//format
void setup () {
     size(210, 297);

 for(int dateiIndex=1; dateiIndex <= maxDateien; dateiIndex++){
   background(0);
   noStroke();

   setupPattern(dateiIndex);  

   noLoop();
   beginRecord(SVG, "zufallPixel_"+dateiIndex+".svg");

     //noLoop();
     //beginRecord(PDF, "zufallPixel_"+dateiIndex+".pdf");
 }
}

void draw() {
 for(int y=0;y<screenY; y++){
 for(int x=0; x<screenX; x++){
     int mycolorindex = farbeWeiss; 
     // wenn Zellwert ist true setze die Farbe Schwarz
     if (screen[x][y])
          mycolorindex = farbeSchwarz;       
     fill(c[mycolorindex]);
     rect (x*5,y*5,5,5); 

   }
 }
}

 void setupPattern(int dateiNummer){  
   int pixelFarbe;
   int prozentsatz=dateiNummer*90/maxDateien;
   // Prozentsatz = 90 so dass es nicht zu dunkel wird …
   // für maxDateien = 15 max 
   // DateiNummer prozentsatz 
   //-----------------------------
   // 0 --------------- 0
   // 10 --------------- 60
   // 15 --------------- 90  

   for(int y=0;y<screenY; y++){
   for(int x=0;x<screenX;x++){
      pixelFarbe=farbeWeiss;

   // if ((random(0,2)+ random(0,(2*prozentsatz/100))) > 2)
     if (random(0,2) > 1)
        pixelFarbe=farbeSchwarz;

        screen[x][y]=(pixelFarbe==farbeSchwarz);

     }
   }
endRecord();
 }

```

---

<div class="post-metadata">

**Author:** ![Aldiery](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Aldiery](https://discourse.processing.org/u/Aldiery)\
**Post date:** [March 31, 2020, 2:48am UTC](https://discourse.processing.org/t/problems-with-svg-libraries/19206/2 "2020-03-31T02:48:50Z")

</div>

I’m not very good at reading code, but I think its that in the `void setup(){}`you are running a loop that is drawing a background over every other svg

---

<div class="post-metadata">

**Author:** ![jeykech](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jeykech](https://discourse.processing.org/u/jeykech)\
**Post date:** [April 1, 2020, 2:01pm UTC](https://discourse.processing.org/t/problems-with-svg-libraries/19206/3 "2020-04-01T14:01:13Z")

</div>

> [@CheckschDa](#):
>
> import processing.svg._; //import processing.pdf._; int screenX=100; int screenY=100; boolean screen = new boolean[screenX][screenY]; final int farbeWeiss=0; final int farbeSchwarz=1; // Wert 0 Wert 1 color c = { color(255,255,255), color(0,0,0)}; int maxDateien=15; //format void setup () { size(210, 297); for(int dateiIndex=1; dateiIndex \<= maxDateien; dateiIndex++){ background(0); noStroke(); setupPattern(dateiIndex); noLoop(); beginRecord(SVG, “zufallPixel\_”+dateiIndex+“.svg”); //noLoop(); //beginRecord(PDF, “zufallPixel\_”+dateiIndex+“.pdf”); } } void draw() { for(int y=0;y\<screenY; y++){ for(int x=0; x\<screenX; x++){ int mycolorindex = farbeWeiss; // wenn Zellwert ist true setze die Farbe Schwarz if (screen[y]) mycolorindex = farbeSchwarz; fill(c[mycolorindex]); rect (x_5,y_5,5,5); } } } void setupPattern(int dateiNummer){ int pixelFarbe; int prozentsatz=dateiNummer_90/maxDateien; // Prozentsatz = 90 so dass es nicht zu dunkel wird … // für maxDateien = 15 max // DateiNummer prozentsatz //----------------------------- // 0 --------------- 0 // 10 --------------- 60 // 15 --------------- 90 for(int y=0;y\<screenY; y++){ for(int x=0;x\<screenX;x++){ pixelFarbe=farbeWeiss; // if ((random(0,2)+ random(0,(2_prozentsatz/100))) \> 2) if (random(0,2) \> 1) pixelFarbe=farbeSchwarz; screen[y]=(pixelFarbe==farbeSchwarz); } } endRecord(); }

why are you calling noLoop() in the setup ?

---

<div class="post-metadata">

**Author:** ![jeykech](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jeykech](https://discourse.processing.org/u/jeykech)\
**Post date:** [April 1, 2020, 2:03pm UTC](https://discourse.processing.org/t/problems-with-svg-libraries/19206/4 "2020-04-01T14:03:58Z")

</div>

```auto
import processing.svg.*;
//import processing.pdf.*;

int screenX=100;
int screenY=100;
boolean [][] screen = new boolean[screenX][screenY];
final int farbeWeiss=0;
final int farbeSchwarz=1;
// Wert 0 Wert 1
color [] c = { color(255,255,255), color(0,0,0)};
int maxDateien=15;

//format
void setup () {
     size(210, 297);

 
}

void draw() {
  for(int dateiIndex=1; dateiIndex <= maxDateien; dateiIndex++){
   background(0);
   noStroke();

   setupPattern(dateiIndex);  

  // noLoop();
   beginRecord(SVG, "zufallPixel_"+dateiIndex+".svg");

     //noLoop();
     //beginRecord(PDF, "zufallPixel_"+dateiIndex+".pdf");
 
 for(int y=0;y<screenY; y++){
 for(int x=0; x<screenX; x++){
     int mycolorindex = farbeWeiss; 
     // wenn Zellwert ist true setze die Farbe Schwarz
     if (screen[x][y])
          mycolorindex = farbeSchwarz;       
     fill(c[mycolorindex]);
     rect (x*5,y*5,5,5); 

   }
 }
 endRecord();
 }
 noLoop();
}

 void setupPattern(int dateiNummer){  
   int pixelFarbe;
   int prozentsatz=dateiNummer*90/maxDateien;
   // Prozentsatz = 90 so dass es nicht zu dunkel wird …
   // für maxDateien = 15 max 
   // DateiNummer prozentsatz 
   //-----------------------------
   // 0 --------------- 0
   // 10 --------------- 60
   // 15 --------------- 90  

   for(int y=0;y<screenY; y++){
   for(int x=0;x<screenX;x++){
      pixelFarbe=farbeWeiss;

   // if ((random(0,2)+ random(0,(2*prozentsatz/100))) > 2)
     if (random(0,2) > 1)
        pixelFarbe=farbeSchwarz;

        screen[x][y]=(pixelFarbe==farbeSchwarz);

     }
   }

 }

```

try this
