# Processing 3.5.4 Python mode save result as SVG

**URL:** <https://discourse.processing.org/t/processing-3-5-4-python-mode-save-result-as-svg/34850>\
**Category:** Processing.py\
**Created:** [January 26, 2022, 2:34pm UTC](https://discourse.processing.org/t/processing-3-5-4-python-mode-save-result-as-svg/34850 "2022-01-26T14:34:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edipii](https://avatars.discourse-cdn.com/v4/letter/e/5fc32e/32.png) [@edipii](https://discourse.processing.org/u/edipii)\
**Post date:** [January 26, 2022, 2:34pm UTC](https://discourse.processing.org/t/processing-3-5-4-python-mode-save-result-as-svg/34850/1 "2022-01-26T14:34:42Z")

</div>

Hi, I have some code, and the result I need save to SVG, but after all, I get PNG image, but SVG not, maybe someone can tell me, where is the problem

```auto
add_library('svg')
save_frame = False
w, h = 800, 800

length_depr = .5
max_depth = 11
min_length = 30

def draw_line(p, v, l, d, md):
    if save_frame:
        beginRecord(svg_output)
    if (d > md):
        return
    
    if (l < min_length):
        l = min_length
    
    
    start_point = p
    end_point = (p[0] + v[0] * l, p[1] + v[1] * l)
    
    #line(start_point[0], start_point[1], end_point[0], end_point[1])
    strokeWeight(4 - d/3)
    lr = -40
    hr = 40
    curve(start_point[0] + random(lr, hr), start_point[1] + random(lr, hr), start_point[0], start_point[1], end_point[0], end_point[1], end_point[0] + random(lr, hr), end_point[1] + random(lr, hr))
    
    v_one = v.copy()
    v_one.rotate(random(.1, .35) * PI)
    draw_line(end_point, v_one, l * length_depr, d + 1, md)
    
    v_two = v.copy()
    v_two.rotate(random(1.65, 1.85) * PI)
    draw_line(end_point, v_two, l * length_depr, d + 1, md)
    if save_frame:
        endRecord()
        exit()
    
    
              
def setup():
    global svg_output
    size(w, h)
    pixelDensity(2)
    
    background(255) #background color
    stroke(0)
    strokeWeight(1)
    noFill()
    
    
    stroke(0) #stroke color
    strokeWeight(1)
    noFill()
    tint(255,127)
    v = PVector(0.0, -1.0)
    draw_line((w/2, h), v, h/3, 0, 10)

    
    save("result/ex.png")
    svg_output = createGraphics(w, h, SVG, "result/file.svg")
    
def keyPressed():
    global save_frame
    if key == 'e':
        save_frame = True

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [January 26, 2022, 6:54pm UTC](https://discourse.processing.org/t/processing-3-5-4-python-mode-save-result-as-svg/34850/2 "2022-01-26T18:54:50Z")

</div>

Welcome @edipii

I think you’re overcomplicating things here. There’s no animation, so no need for a `keyPressed()` function to capture a specific instance in time. It’s probably easiest just to add `SVG` and filename arguments to the `size()` line (instead of using the record approach). For example –

```python
add_library('svg')

def draw_line():
    line(0, 0, 100, 100)

def setup():
    size(800,800, SVG, 'a.svg')

def draw():
    strokeWeight(5)
    draw_line()
    exit()

```

---

<div class="post-metadata">

**Author:** ![edipii](https://avatars.discourse-cdn.com/v4/letter/e/5fc32e/32.png) [@edipii](https://discourse.processing.org/u/edipii)\
**Post date:** [January 26, 2022, 8:35pm UTC](https://discourse.processing.org/t/processing-3-5-4-python-mode-save-result-as-svg/34850/3 "2022-01-26T20:35:38Z")

</div>

Thank you, it’s worked for me

Many thanks from me

> [@tabreturn](#):
>
> ```auto
> def draw():
> strokeWeight(5)
> draw_line()
> exit()
> 
> ```
