实验任务1
task1
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()
task2
源代码:
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()
实验任务2
task1
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
源代码:
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()
实验任务3
task1
源代码:
from turtle import * def square(size = 50, rgb = 'orange'): 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()
task2
源代码:
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()
from turtle import * setup(800, 600) bgcolor('black') pencolor('white') speed(0) angle = 0 size = 2 n = 5 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() def main(): moveto(-100,-100) color('black') begin_fill() for i in range(4): forward(200) left(90) end_fill() color('red') begin_fill() moveto(0,-100) circle(100,steps=4) end_fill() main()
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): pencolor('blue') pensize(2) n=40 for i in range(5): moveto(0,0) forward(n) left(90) circle(n,90) left(90) forward(n) left(90) n+=20 main()
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): bgcolor('black') color('yellow') begin_fill() moveto(0,0) left(45) forward(100) left(90) circle(100,270) left(90) forward(100) end_fill() moveto(15,60) color('black') begin_fill() circle(10,360) end_fill() moveto(5,55) color('white') begin_fill() circle(2,360) end_fill() hideturtle() main()
标签:moveto,实验,import,circle,main,def,fill From: https://www.cnblogs.com/ning089/p/17466248.html