1. 程式人生 > >Python之turtle畫同心圓和棋盤

Python之turtle畫同心圓和棋盤

畫餅圖

import turtle

t = turtle.Pen()

for i in range(5):
    t.penup()
    t.goto(0, -i*30)
    t.pendown()
    t.circle(i*30+30)

turtle.done()

 

畫棋盤

import turtle

t = turtle.Pen()

widthall = 200
width = 20
num = widthall // 20 * 2 + 1

t.speed(10)

for r in range(num):
    t.penup()
    t.goto(
-widthall, widthall - width * r) t.pendown() t.goto(widthall, widthall - width * r) for c in range(num): t.penup() t.goto(-widthall + width * c, widthall) t.pendown() t.goto(-widthall + width * c, -widthall) turtle.done()

 

謝謝