import turtle
Elizabeth = turtle.Turtle()
Elizabeth.shape('turtle')
Elizabeth.penup()
def line(words, horiz_pos = -50):
x,y = Elizabeth.pos()
Elizabeth.goto(max(horiz_pos, -190), y)
Elizabeth.write(words)
x,y = Elizabeth.pos()
Elizabeth.goto(x, y - 25)
def by(author):
x,y = Elizabeth.pos()
Elizabeth.goto(x + 70, max( -190, y -30))
Elizabeth.write(author)
x,y = Elizabeth.pos()
Elizabeth.goto(0, y)
Elizabeth.goto(-50, 190)
line("""Land lies in water; it is shadowed green.
Shadows, or are they shallows, at its edges
showing the line of long sea- weeded ledges
where weeds hang to the simple blue from green.
Or does the land lean down to lift the sea from under,
drawing it unperturbed around itself ?
Along the fine tan sandy shelf
is the land tugging at the sea from under?
""", -190)
line("")
line("""The shadow of Newfoundland lies flat at and still.
Labrador’s yellow, where the moony Eskimo
has oiled it. We can stroke these lovely bays,
under a glass as if they were expected to blossom,
or as if to provide a clean cage for invisible fish.
The names of seashore towns run out to sea,
the names of cities cross the neighboring mountains
— the printer here experiencing the same excitement
as when emotion too far exceeds its cause.
These peninsulas take the water between thumb and finger
like women feeling for the smoothness of yard- goods.""", -190)
I am using turtle to create a poem called THE MAP BY ELIZAEBETH BISHOP. But I am facing a problem, which is that when I run the code it overlaps all the lines of poetry in the turtle window. I cant right more than 4-5 lines of poetry without it overlapping or it starts moving towards the top of the screen and half the poem cannot be seen:
The issue of the overlap is in the line
function:
Elizabeth.goto(x, y - 25)
Here, you move the pen downwards by 25 pixels, independent of the linebreaks within the text. Instead, calculate the amount of lines and multiply them with the lineheight to move the pen according to the written text.
Replace this line with the following three lines to get a non-overlapping result:
number_of_lines = words.count("\n") + 1
line_height = 14 # measured by me
Elizabeth.goto(x, y - line_height * number_of_lines)