1 from turtle import * 2 3 4 def move(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def draw(n, size=100): 11 for i in range(n): 12 fd(size) 13 left(360/n) 14 15 16 def main(): 17 pensize(2) 18 pencolor('red') 19 20 move(-200, 0) 21 draw(3) 22 23 move(0, 0) 24 draw(4) 25 26 move(200, 0) 27 draw(5) 28 29 hideturtle() 30 done() 31 32 33 main()
1 from turtle import * 2 3 4 def moveto(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def main(): 11 pensize(2) 12 pencolor('blue') 13 14 moveto(-150, 0) 15 circle(50) 16 17 moveto(0, 0) 18 circle(50, steps=4) 19 20 moveto(150, 0) 21 circle(50, steps=5) 22 23 moveto(300, 0) 24 circle(50, steps=6) 25 26 hideturtle() 27 done() 28 29 30 main()
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): setup(800, 600) radius = 20 # 圆初始半径 offset = 20 # 同心圆每次位移量 for i in range(9): moveto(0, -radius) circle(radius) radius += offset hideturtle() done() main()
from turtle import * from random import random def moveto(x, y): penup() goto(x, y) pendown() def gen_color(): return tuple((random() for i in range(3))) def main(): setup(800, 600) radius = 180 # 圆初始半径 offset = 20 # 同心圆每次位移量 for i in range(8): moveto(0, -radius) color(gen_color()) begin_fill() circle(radius) end_fill() radius -= offset hideturtle() done() main()
from turtle import * def square(size=50, rgb='pink'): """ 绘制正方形 :para: size:int 指定边长 (如未指定参数,使用默认值) :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) """ pencolor(rgb) for i in range(4): fd(size) left(90) def main(): setup(800, 600) speed(0) n = 10 for i in range(n): square(80, rgb='orange') left(360/n) hideturtle() done() main()
from turtle import * speed(0) setup(800, 600) pencolor('pink') n = 10 for i in range(10): # 绘制一片花瓣 for j in range(2): circle(80, 90) left(90) right(360/n) hideturtle() done()
from turtle import * setup(800, 600) bgcolor('black') pencolor('white') speed(0) angle = 0 size = 2 n = 5 # 螺旋n边形 count = 50 # 循环次数 for i in range(count): fd(size) angle += 360/n seth(angle) size += 5 hideturtle() done()
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() setup(800, 600) speed(0) moveto(-100, -100) def fill_square(rgb, sl): fillcolor(rgb) begin_fill() for i in range(4): fd(sl) left(90) end_fill() hideturtle() fill_square('black', 200) moveto(0, -100) left(45) fill_square('red', 100*2**0.5) done()
from turtle import * setup(400, 400) pencolor('blue') pensize(2) speed(0) def func(n, r): for i in range(n): fd(r) left(90) circle(r, 90) left(90) fd(r) left(90) r += 20 func(5, 40) hideturtle() done()
from turtle import * from random import random setup(800, 600) speed(0) penup() goto(-200, 0) pendown() def get_color(): return tuple(random() for i in range(3)) def rect(width, length): for i in range(20): rgb = get_color() pencolor(rgb) fillcolor(rgb) begin_fill() fd(width) left(90) fd(length) left(90) fd(width) left(90) fd(length) left(90) end_fill() fd(width) rect(20, 80) hideturtle() done()
from turtle import * setup(600, 600) bgcolor('black') fillcolor('yellow') speed(0) begin_fill() left(45) fd(120) left(90) circle(120, 270) left(90) fd(120) end_fill() def moveto(x, y): penup() goto(x, y) pendown() def fill_circle(r, rgb): fillcolor(rgb) begin_fill() left(180) circle(r) end_fill() moveto(0, 60) fill_circle(10, 'black') moveto(8, 74) fill_circle(4, 'white') hideturtle() done()
标签:turtle,moveto,python,绘图,90,circle,left,def,fill From: https://www.cnblogs.com/aaaaaaaaaa/p/17472980.html