# How to export it to an SVG file, can someone help?

**URL:** https://discourse.processing.org/t/how-to-export-it-to-an-svg-file-can-someone-help/35795
**Category:** Coding Questions
**Tags:** homework
**Created:** [March 17, 2022, 10:33am UTC](https://discourse.processing.org/t/how-to-export-it-to-an-svg-file-can-someone-help/35795 "2022-03-17T10:33:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AvdMaker](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@AvdMaker](https://discourse.processing.org/u/AvdMaker)
#### Post date: [March 17, 2022, 10:33am UTC](https://discourse.processing.org/t/how-to-export-it-to-an-svg-file-can-someone-help/35795/1 "2022-03-17T10:33:16Z")

</div>

Hi all,

I am a student CS at a Highschool in the Netherlands and I need some help;[This is what it’s supposed to be but I can’t find the original code anymore](https://www.local-guru.net/blog/2011/4/23/generating-labyrinths-in-processing)

I’ve been trying to export this processing code from ‘processing’ to an SVG file so I can plot it with the axidraw. It just doesn’t work. I don’t exactly know why, and would like some help.  
As of right now I can’t see the code if I press ‘play’ on processing but it does load the program. I need to open it in Inkscape, but I don’t know how and my teacher also doesn’t know how to do it. I hope someone can help.  
This is the code:

//I coppied this code for school work, it is NOT mine it’s Yoruks

// Simple 2D Maze Creator  
// by Yoruk, taken from on old QBasic code made by me  
// Published on the Instructables website, June 2014  
// send comments to yoruk16\_72 at yahoo dot fr

//memory allocations

import processing.svg.\*;

int M;  
int N;  
int X;  
int Y;  
int K;  
int Dir;  
int Ka;

int[][] L ; //the maze  
boolean[][] pDR; //right walls  
boolean[][] pDS; //down walls

boolean CaseTrouvee ;

boolean PasContreUnbord;

int Xdep ;  
int Ydep ;

boolean Possibilite ;

boolean GenerationTerminee;

void setup() {

```
size(500, 500, SVG, "filename.svg"); //window size in pixels

M=30; //maze size : columns
N=30; //rows

pDR = new boolean[M+5][N+5];
pDS = new boolean[M+5][N+5];
L = new int[M+5][N+5];

for (int i = 1; i <= N; i = i+1) {
    for (int j = 1; j <= M; j = j+1) {
        pDR[j][i] = true ; //close every walls
        pDS[j][i] = true;
    }
}

X = 1;
Y = 1 ; //start coordinates. Don't touch !
Xdep = X;
Ydep = Y;
K = 1 ;

L[X][Y] = K;

GenerationTerminee=false;

while (GenerationTerminee==false) {

    print("debut boucle X:");
    print(X);
    print(" Y:");
    print(Y);
    print(" K:");
    println(K);        

    //exec ok

    // ligne 5

    //check if there is a possibility around the actual cell
    Possibilite = false;

    if (X < M ) { 
        if (L[X + 1][Y] == 0) { 
            Possibilite = true;
        }
    }

    if (X > 1 ) {
        if (L[X - 1][Y] == 0 ) { 
            Possibilite = true;
        }
    }  

    if (Y < N ) { 
        if (L[X][Y + 1] == 0) { 
            Possibilite = true;
        }
    } 

    if (Y > 1) {
        if (L[X][Y - 1] == 0) { 
            Possibilite = true;
        }
    } 

    if (Possibilite==true) {

        println("possibilite vraie");

        CaseTrouvee = false;

        while (CaseTrouvee == false) {

            Dir = int(random(4))+1; //1 up 2 right 3 down 4 left  

            print("On tente direction : ");
            println(Dir);

            //check if the cell is visited or if it is near a boundary 
            switch (Dir) { 

            case 1:                         
                if (L[X][Y - 1] == 0 && Y !=1 ) {
                    pDS[X][Y - 1] = false; //open the wall
                    Y = Y - 1;   
                    CaseTrouvee=true;
                }                
                break;

            case 2:
                if (L[X + 1][Y] == 0 && X !=M) {
                    pDR[X][Y] = false; 
                    X = X + 1; 
                    CaseTrouvee=true;
                }
                break;

            case 3:
                if (L[X][Y + 1] == 0 && Y !=N ) {
                    pDS[X][Y] = false; 
                    Y = Y + 1;  
                    CaseTrouvee=true;
                }
                break;

            case 4:
                if (L[X - 1][Y] == 0 && X !=1) {
                    pDR[X - 1][Y] = false; 
                    X = X - 1;
                    CaseTrouvee=true;
                }
                break;
            }

            println("Cellule pas encore trouvee");
        }

        print("cellule ok:");
        println(K);
        K = K + 1 ;//cellule cible trouvée
        L[X][Y] = K;
        Ka = K;
        print ("on est maintenant a x:");
        print(X);
        print (" y:");
        println(Y);
    }    
    else {
        //no possibility :move backwards
        Ka = Ka - 1;
        println("recul");

        for (int i = 1; i < N; i = i+1) {  
            //find previous cell
            for (int j = 1; j < M; j = j+1) {

                if (L[j][i] == Ka) { 
                    X = i;
                    Y = j;
                    println("case precedente trouvee");
                }
            }
        }
    }

    println("hit boucle");

    if (X == Xdep && Y == Ydep) {
        GenerationTerminee=true;
    }
} //calculation done

    background(255);

rectMode(CORNERS) ;

//maze drawing

noFill();

int tX = (width-5) / M;
int tY = (height-5) / N ;//compute the step size

if (tX > tY) { 
    tX = tY;
}

rect (0, 0, M * tX, N * tX) ; //draw boundary

for (int i = 1; i <= N; i = i+1) {  
    for (int j = 1; j <= M; j = j+1) {
        if (pDS[j][i] == true)
        { 
            line (j * tX, i * tX, j * tX - tX, i * tX) ;
        }
        if (pDR[j][i] == true) 
        {
            line (j * tX, i * tX, j * tX, i * tX - tX);
        }
    }
}

noLoop(); // Run once and stop

```

}

//file end

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [March 17, 2022, 11:00am UTC](https://discourse.processing.org/t/how-to-export-it-to-an-svg-file-can-someone-help/35795/2 "2022-03-17T11:00:19Z")

</div>

Hello @AvdMaker,

I followed the first _SVG Export (No Screen Display)_ example here and put your code in the _draw()_ loop:

> **[SVG Export / Libraries](https://processing.org/reference/libraries/svg/index.html)**
>
> Create SVG files.

SVG Output:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d17c1ffe64fa8e99f3261ef293af24f44c4a8e2c.png)

`:)`

---

<div class="post-metadata">

### Author: ![AvdMaker](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@AvdMaker](https://discourse.processing.org/u/AvdMaker)
#### Post date: [March 21, 2022, 8:53am UTC](https://discourse.processing.org/t/how-to-export-it-to-an-svg-file-can-someone-help/35795/3 "2022-03-21T08:53:33Z")

</div>

Hi @glv,

Thank you for helping me! I tried that before but I don’t know where to put everything, so could you please sent me the code, if you’re okay with that.
