question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] Could you help to implement dot in svg_turtle?

See original GitHub issue

What I did

[feature request] Could you help to implement dot in svg_turtle?

#!/usr/bin/env python  
# coding=utf-8 
import sys
from turtle import *  # @UnusedWildImport
import svgwrite
from svg_turtle import SvgTurtle

def write_file(draw_func, filename, size):
    drawing = svgwrite.Drawing(filename, size=size)
    drawing.add(drawing.rect(fill='white', size=('100%', '100%')))
    t = SvgTurtle(drawing)
    Turtle._screen = t.screen
    Turtle._pen = t
    draw_func()
    drawing.save()

def draw():
    a = [[120.71, 50], [50, 120.71], [-50, 120.71], [-120.71, 50], [-50, -20.71], [50, -20.71], [20.71, 50],
            [-20.71, 50]]
    pencolor("red")
    penup()
    for i in range(len(a)):
        goto(a[i])
        down()
        dot(10, "red")
        penup()

def main():
    write_file(draw, 'test.svg', size=('500px', '500px'))

if __name__ == '__main__':
    main()

What happened

When I run this code, got this error:

Traceback (most recent call last):
  File ".\data\test.py", line 32, in <module>
    main()
  File ".\data\test.py", line 29, in main
    write_file(draw, 'test.svg', size=('500px', '500px'))
  File ".\data\test.py", line 14, in write_file
    draw_func()
  File ".\data\test.py", line 25, in draw
    dot(10, "red")
  File "<string>", line 8, in dot
AttributeError: 'SvgTurtle' object has no attribute 'dot'

What I wanted to happen

Draw that dots in svg file

My environment

Describe the versions of everything you were using:

  • Python 3.7.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
donkirkbycommented, May 10, 2020

I added the dot() method to SvgTurtle, and I added a bgcolor option to SvgTurtle.create(). That makes it easier to create the turtle object and save the file. Here’s an updated version of your example:

#!/usr/bin/env python
# coding=utf-8
from turtle import *  # @UnusedWildImport
from svg_turtle import SvgTurtle


def write_file(draw_func, filename, size):
    t = SvgTurtle.create(*size, bgcolor='white')
    Turtle._screen = t.screen
    Turtle._pen = t
    draw_func()
    t.save_as(filename)


def draw():
    a = [[120.71, 50], [50, 120.71], [-50, 120.71], [-120.71, 50], [-50, -20.71], [50, -20.71], [20.71, 50],
         [-20.71, 50]]
    pencolor("red")
    penup()
    for pos in a:
        goto(pos)
        dot(10)


def main():
    write_file(draw, 'test.svg', size=('500px', '500px'))


if __name__ == '__main__':
    main()
0reactions
lifubangcommented, May 10, 2020

Thank you very much. I will test it ASAP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Make a Feature Request | Short.Io Help Center
1. Feature Requests - see the existed feature requests. 2. Planned - the requests that are approved and are going to be implemented....
Read more >
Feature Request Template: How to Manage Suggestions at ...
Streamline and organize user feedback with this free feature request template. Available in Google Docs and Sheets (no email required).
Read more >
donkirkby/svg-turtle: Use the Python turtle to write SVG files
Once it's installed, create an SvgTurtle , telling it how big to make the SVG file. Then give it some turtle commands, and...
Read more >
Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >
How we handle feature requests - Artlogic Support
Following our internal feature request meetings, viable requests are selected and then considered for inclusion in our development schedule. This schedule is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found