我有一個快速的問題,使用龜與Python。我想最終的繪圖看起來像這樣:http://i.stack.imgur.com/IFw5G.jpg基本的龜遞歸
但是我的代碼只做了一部分,我無法弄清楚我的生活。這是一項家庭作業,所以請不要爲我做,請帶領我正確的方向,因爲我無法弄清楚我做錯了什麼。我無法弄清楚什麼是如何讓它重現圖像左側的方塊,因爲它只在右側。
這裏是我的代碼:
from turtle import *
differentColors = ['green', 'blue']
def jester(N, L):
if N <=0:
pass
else:
pencolor(differentColors[N % len(colors)])
forward(L/2)
left(90)
forward(L)
left(90)
forward(L)
left(90)
forward(L)
left(90)
forward(L/2)
forward(L/2)
left(90)
forward(L)
right(150)
jester(N-1, L/2)
jester(4, 100)
謝謝!
請將您的代碼添加爲文本,而不是圖片。有些人無法進入Imgur。 – gparyani 2014-09-05 19:25:50
除了無法訪問imgur的用戶,如果我們不必輸入它,運行代碼將變得更容易... – kindall 2014-09-05 19:27:29
'從龜進口* differentColors = [ '綠色', '藍'] DEF小丑(N,L): \t如果N <= 0: \t \t通 \t否則: \t \t pencolor( differentColors [N%LEN(顏色)]) \t \t正向(L/2) \t \t左(90) \t \t正向(L) \t \t左(90) \t \t正向(L) \t \t左(90) \t \t正向(L) \t \t左(90) \t \t正向(L/2) \t \t正向(L/2) \t \t左(90) \t \t正向(L) \t \t右(150) \t \t小丑(N-1,L/2) \t \t \t \t \t 小丑(4,100)' – Alan 2014-09-05 19:49:36