填充颜​​色不适用于我的功能(Python乌龟图形)

时间:2019-11-09 23:21:17

标签: python turtle-graphics

void createcheckifExistDirectories() { List<String> directoriesToCheckLIST = new List<String>(); for (int i = 0; i < 30; i++) { directoriesToCheckLIST.Add("folder" + i); } for (int i = 0; i < directoriesToCheckLIST.Count; i++) { String folderpath = directoriesToCheckLIST[i]; Task<bool> task = ftpCreateDirectory("ftp://somehost.com", folderpath, "user", "password"); if (task.IsFaulted == false) { //Folder exist } else { /*Folder not exist*/ } Thread.Sleep(2000); //Not so fast } } public async Task<bool> ftpCreateDirectory(String host, String folderpath, String user_name, String password) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); bool returnvalue = false; try { bool dirExists = DoesFtpDirectoryExist(host, folderpath, user_name, password); if (dirExists == false) { Thread.Sleep(2000); var request = (FtpWebRequest)WebRequest.Create(host + "/" + folderpath); //"ftp://f16-preview.runhosting.com/PanoramaTEST2/UploadedToChristian" request.Credentials = new NetworkCredential(user_name, password); request.Method = WebRequestMethods.Ftp.MakeDirectory; request.ConnectionGroupName = host.Replace(".", "").Replace(":", "").Replace("/", "").Replace("-", "").Replace("_", "") + user_name; request.ServicePoint.ConnectionLimit = 4; using (var responseWeb = await request.GetResponseAsync()) { var response = (FtpWebResponse)responseWeb; if (response.StatusDescription.Contains("257")) //257 Directory successfully created { returnvalue = true; } } } else { returnvalue = true; } } catch (WebException ex) { String status = ((FtpWebResponse)ex.Response).StatusDescription; } return returnvalue; } public bool DoesFtpDirectoryExist(String host, String folderpath, String user_name, String password) { try { var request = (FtpWebRequest)WebRequest.Create(host + "/" + folderpath); request.Credentials = new NetworkCredential(user_name, password); request.Method = WebRequestMethods.Ftp.ListDirectory; request.ConnectionGroupName = host.Replace(".", "").Replace(":", "").Replace("/", "").Replace("-", "").Replace("_", "") + user_name; request.ServicePoint.ConnectionLimit = 4; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); return true; } catch (WebException ex) { String status = ((FtpWebResponse)ex.Response).StatusDescription; MessageBox.Show(status.ToString()); return false; } }在此功能中根本无法工作-我不知道为什么。它可用于我的所有其他功能:

fillcolor()

1 个答案:

答案 0 :(得分:0)

问题是您的循环中有begin_fill()end_fill() ,这意味着他们正在尝试填充短线段。您需要 around 循环来填充整个形状:

from turtle import Turtle, Screen
from random import randint

def rocks(t):
    t.fillcolor('gray')

    for _ in range(5):
        t.penup()
        t.goto(randint(-300, 0), randint(-200, 0))

        t.begin_fill()
        for _ in range(15):
            t.pendown()
            t.forward(5)
            t.right(2)
            t.forward(5)
            t.right(22)
        t.end_fill()

screen = Screen()

turtle = Turtle()
turtle.speed('fastest')

rocks(turtle)

turtle.hideturtle()
screen.exitonclick()

enter image description here