task1-1
from turtle import * def move(x, y): penup() goto(x, y) pendown() def draw(n, size = 100): for i in range(n): fd(size) left(360/n) def main(): pensize(2) pencolor('red') move(-200, 0) draw(3) move(0, 0) draw(4) move(200, 0) draw(5) hideturtle() done() main()
task1-2
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): pensize(2) pencolor('blue') moveto(-150, 0) circle(50) moveto(0, 0) circle(50, steps = 4) moveto(150, 0) circle(50, steps = 5) moveto(300, 0) circle(50, steps = 6) hideturtle() done() main()
task2-1
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()
task2-2
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 = 20 # 圆初始半径 offset = 20 # 同心圆每次位移量 for i in range(9): moveto(0, -radius) color(gen_color()) circle(radius) radius += offset hideturtle() done() main()
task3-1
from turtle import * def square(size = 50, rgb = 'pink'): 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) left(360/n) hideturtle() done() main()
task3-2
from turtle import * 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()
task4
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()
task5-1
from turtle import * right(45) penup() goto(-100,-100) pendown() begin_fill() pencolor('black') fillcolor('black') circle(100*2**0.5,steps = 4) end_fill() left(45) penup() goto(0,-100) pendown() pensize(2) pencolor('red') begin_fill() fillcolor('red') circle(100,steps = 4) end_fill() hideturtle() done()
task5-2
from turtle import * pensize(2) pencolor('blue') for i in range(5): setheading(90) r = 40+20*i goto(r,0) circle(r,extent = 90) goto(0,0) hideturtle() done()
task6
from turtle import * from random import random setup(800,600) def gen_color(): return tuple((random() for i in range(3))) def rectangle(): color(gen_color()) begin_fill() for i in range(2): forward(5) left(90) forward(20) left(90) end_fill() penup() goto(-10*5,0) pendown() for k in range(20): rectangle() forward(5) hideturtle() done()
标签:turtle,python,hideturtle,range,绘图,import,circle,def From: https://www.cnblogs.com/myt1/p/17466629.html