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?
-
Alternately, is there a way to find out if a certain point is empty or not, in a turtle drawing?bakuda– bakuda2018-07-21 19:54:45 +00:00Commented 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.wg4568– wg45682018-07-21 20:08:11 +00:00Commented 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.Zev– Zev2018-07-21 21:02:42 +00:00Commented Jul 21, 2018 at 21:02
Add a comment
|
1 Answer
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()
2 Comments
Community
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.
Kobi0401
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.