Python Turtle or any other library for 2D drawing

Viewed 366

I am using python3.7 and its math and turtle module I have to draw a 2D sketch with arcs. For example

  1. Draw a main circle with radius 1.5m
  2. Draw another arc with radius of 1.7m and 2.8m from 5 degree to 75 degrees and join their end point
  3. Now draw another circle at 5 degrees and at 2m from main circle with a radius of 0.4m.
  4. Draw radial lines at interval of 10 degrees and write their respective angle at those radial lines.

Main circle can have radius as large as 10m. And all these values i can calculate with simple math lib of python. But to draw i thought i can use turtle module. But it draw in pixel with very limited values. Is there any way to scale these values to pixel in turtle module, or any other graphic library for this work. Expected output is something like this.enter image description here

2 Answers

Use setworldcoordinates() to define your custom coordinate system:

from turtle import Screen, Turtle

# I want a method to treat my 400 X 400 pixel window as
# a 20m X 20m canvas so that I can use my actual dimension

screen = Screen()
screen.setup(400, 400)
screen.setworldcoordinates(-10, -10, 10, 10)

turtle = Turtle()

# Draw a main circle with radius 1.5m

turtle.penup()
turtle.sety(-1.5)
turtle.pendown()
turtle.circle(1.5)

screen.exitonclick()
Related