如何在Python写一首诗?
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)
我正在使用Turtle创作一首由Elizaebeth Bishop的诗,称为地图。但是我正面临一个问题,那就是当我运行代码时,它与乌龟窗口中的所有诗歌都重叠。我无法在没有重叠的情况下正确的4-5行诗歌,或者它开始向屏幕顶部移动,而一半的诗歌看不见:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重叠的问题在于
line
函数:在这里,您将笔向下移动25像素,而与文本中的线路无关。
取而代之的是,计算线的量,然后用线路将它们乘以根据书面文字移动笔。
用以下三行替换此行,以获得不重叠的结果:
The issue of the overlap is in the
line
function: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: