0

I am making a drawing using Turtle where I draw a line between two points reading from data. If I want to draw another line exactly on top of this line, it shows the same thickness. Is there a way to tell turtle to draw a thicker line everytime it draws on top of an existing line?

3
  • Alternately, is there a way to find out if a certain point is empty or not, in a turtle drawing? Commented Jul 21, 2018 at 19:54
  • I don't believe there is a way to check whether you are drawing over an already existing line. You might want to write some code that tracks the turtles movement, and then use that to determine line size. Commented Jul 21, 2018 at 20:08
  • This question stackoverflow.com/questions/23579631/… asks a similar question but I'm not going to mark this a duplicate because it only offers a vague outline of how to do what you requested. However, it seems like there is no way of doing this using the turtle's existing API and you'd have to come up with a custom solution. Commented Jul 21, 2018 at 21:02

1 Answer 1

0
import turtle

drawn_lines = {}

def draw_line(start, end):
    key = (start, end) if start <= end else (end, start)
    if key in drawn_lines:
        drawn_lines[key] += 1
    else:
        drawn_lines[key] = 1

    thickness = 1 + (drawn_lines[key] - 1) * 2  # Increase thickness by 2 each time
    turtle.pensize(thickness)

    turtle.penup()
    turtle.goto(start)
    turtle.pendown()
    turtle.goto(end)

# Example usage
draw_line((0, 0), (100, 100))
draw_line((0, 0), (100, 100))  # Will be thicker
draw_line((0, 0), (100, 100))  # Even thicker

turtle.done()
Sign up to request clarification or add additional context in comments.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Keep a record of all the lines you've drawn (using start and end coordinates), and if you draw the same line again, you can increase the thickness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.