我怎麼可以用python中的龜畫出一系列平行線(例如:5)?如何使用Turtle圖形在python中繪製一系列平行線?
def parallel_lines(number):
#Help me write the body of the function
#number is the number of lines for drawing
我怎麼可以用python中的龜畫出一系列平行線(例如:5)?如何使用Turtle圖形在python中繪製一系列平行線?
def parallel_lines(number):
#Help me write the body of the function
#number is the number of lines for drawing
試試這個代碼
from turtle import *
#we make an object from class Turtle
alex=Turtle()
def parallel_lines(number):
#number is number of lines
with_s=alex.window_width()
height_s=alex.window_height()
alex.setheading(90)
alex.pu()
#for fill all screen and equall distance below line needed
alex.setposition(with_s/-2,height_s/-2)
for i in range(1,number+1):
alex.pd()
alex.fd(height_s)
alex.pu()
alex.setposition(with_s/-2+i*(with_s/(number-1)),height_s/-2)
parallel_lines(5)
output
是2線的邊緣和屏幕
非常感謝,但alex = turtle()部分是什麼,你怎麼知道使用setheading(90)和alex.setposition(with_s/-2,height_s/-2)什麼是-2? – user2269635 2013-04-12 04:25:48
@ user2269635我更新了答案,如果你搜索海龜和文檔,它很容易找到設置(90) – 2013-04-12 05:04:55
@ user2269635(with_s/-2,height_s/-2)by-2用於將alex移動到left和down屏幕 – 2013-04-12 05:17:38
什麼初始條件3行?什麼方向?多久?有多遠?你甚至嘗試過嗎? – martineau 2013-04-11 10:20:30
即時通訊真的很新,我想要5條線垂直覆蓋整個屏幕,並且相距很遠。我知道它可能是一個愚蠢的問題。 – user2269635 2013-04-11 10:25:06