天天看點

python之turtle實作‘開花’和簽名

今天是2018年的5月的最後一天,想用python發現下心情,卻無意中在python自動的turtle庫能做一些有趣的事,下面就那turtle這個庫實作‘開花’和簽名

一、準備環境

1.版本:python3 + pycharm 2.庫:turtle

二、直奔主題

1.代碼如下:

#coding:utf-8

import turtle   #導入python自動的turtle庫

#參數:width, height: 輸入寬和高為整數時, 表示像素; 為小數時, 表示占據電腦螢幕的比例,

#(startx, starty): 這一坐标表示矩形視窗左上角頂點的位置, 如果為空,則視窗位于螢幕中心

turtle.setup(1000, 600, 0, 0)

turtle.colormode(255)

#沒有參數傳入,傳回目前畫筆顔色,傳入參數設定畫筆顔色,可以是字元串如"green", "red",也可以是RGB 3元組

turtle.pencolor("green")

turtle.pensize(5)  #設定畫筆的寬度

for iin range(8):   #循環次數

    turtle.circle(50)  #畫圓,半徑為正(負),表示圓心在畫筆的左邊(右邊)畫圓

    turtle.right(-45)   #順時針移動degree°

turtle.pencolor("red")

    turtle.circle(25)   #畫圓,半徑為正(負),表示圓心在畫筆的左邊(右邊)畫圓

turtle.right(120)    #順時針移動degree°

turtle.circle(-400, 50)   #畫圓,半徑為正(負),表示圓心在畫筆的左邊(右邊)畫圓

turtle.up()

turtle.goto(150,-120)

turtle.color('black')

turtle.write("簡書·keitwo" )

turtle.goto(160,-140)

turtle.write("2018 年 05 月 21 日" )

turtle.goto(240,-160)

turtle.write("." )

turtle.done()

2.結果:
python之turtle實作‘開花’和簽名

運作結果