试验任务一
实验源码
task1
from turtle import * def move(x, y): '''画笔移动到坐标(x,y)处''' penup() goto(x, y) pendown() def draw(n, size = 100): '''绘制边长为size的正n变形''' 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): '''把画笔移动至坐标(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()
实验截图
实验任务二
task1
实验源码
from turtle import * def moveto(x, y): #把画笔移至坐标(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): '''把画笔移至坐标(x,y)处''' penup() goto(x, y) pendown() def gen_color(): '''生成一个以rgb三元组表示的颜色值并返回''' 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()
实验截图
实验任务三
task1
实验源码
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 = 3 for i in range(n): square(80) left(360/n) hideturtle() done() main()
实验截图
task2
实验源码
from turtle import * setup(800, 600) pencolor('pink') n = 4 for i in range(n): # 绘制一片花瓣 for j in range(2): circle(80, 90) left(90) right(360/n) hideturtle() done()
实验源码二
from turtle import * def square(size = 50, rgb = 'orange'): #绘制正方形 #: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) left(360/n) hideturtle() done() main()
实验源码三
from turtle import * speed(0) setup(800, 600) pencolor('pink') n = 10 for i in range(n): # 绘制一片花瓣 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 = 4 # 螺旋n边形 count = 50 # 循环次数 for i in range(count): fd(size) angle += 360/n + 1 seth(angle) size += 5 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 setheading(angle) size += 5 hideturtle() done()
实验截图
实验任务五
task1
实验源码
from turtle import * penup() goto(-100,-100) pendown() fillcolor('black') begin_fill() for i in range(4): fd(200) left(90) end_fill() penup() goto(-100,0) pendown() setheading(-45) fillcolor('red') begin_fill() for i in range(4): fd(100*2**0.5) left(90) end_fill() hideturtle() done()
实验截图
task2
实验源码
from turtle import * pencolor('blue') pensize(2) radians = 20 offset = 20 for i in range(5): penup() goto(0,0) pendown() fd(radians) setheading(90) circle(radians,90) setheading(270) fd(radians) setheading(0) radians += offset hideturtle() done()
实验截图
实验任务六
实验源码
from turtle import * speed(0) bgcolor('black') pencolor('yellow') fillcolor('yellow') begin_fill() setheading(45) fd(200) setheading(135) circle(200,270) setheading(135) fd(200) end_fill() penup() goto(0,120) pendown() fillcolor('black') begin_fill() circle(20) end_fill() penup() goto(-20,120) pendown() fillcolor('white') begin_fill() circle(5) end_fill() hideturtle() done()
实验截图
标签:turtle,Python,range,实验,import,绘图,def,size From: https://www.cnblogs.com/laix/p/17462879.html