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)
我正在用乌龟创作一首诗,叫做伊丽莎白·毕晓普的《地图》。但是我面临一个问题,那就是当我运行代码时,它与海龟窗口中的所有诗歌行重叠。我不能右转超过4-5行诗而不重叠,或者它开始向屏幕顶部移动,一半的诗看不到:
重叠的问题在line
函数中:
Elizabeth.goto(x, y - 25)
在这里,您将笔向下移动25像素,独立于文本中的换行符。相反,计算行数,并将其与行高相乘,以根据书写的文本移动笔。
将这一行替换为以下三行以获得不重叠的结果:
number_of_lines = words.count("n") + 1
line_height = 14 # measured by me
Elizabeth.goto(x, y - line_height * number_of_lines)