首页 > 其他分享 >实验6

实验6

时间:2023-06-12 14:37:13浏览次数:32  
标签:20 move pencolor range 实验 def fill

实验任务1 task1_1.py

 1 from turtle import *
 2 def move(x, y):
 3     '''画笔移动到坐标(x,y)处'''
 4     penup()
 5     goto(x, y)
 6     pendown()
 7 
 8 def draw(n, size = 100):
 9     '''绘制边长为size的正n变形'''
10     for i in range(n):
11         fd(size)
12         left(360/n)
13 
14 def main():
15     pensize(2)
16     pencolor('red')
17 
18     move(-200, 0)
19     draw(3)
20 
21     move(0, 0)
22     draw(4)
23 
24     move(200, 0)
25     draw(5)
26 
27     hideturtle()
28     done()
29 
30 
31 main()

 

task1_2.py
 1 from turtle import *
 2 
 3 def moveto(x, y):
 4     '''把画笔移动至坐标(x, y)处'''
 5     penup()
 6     goto(x, y)
 7     pendown()
 8 
 9 def main():
10     pensize(2)
11     pencolor('blue')
12 
13     moveto(-150, 0)
14     circle(50)
15 
16     moveto(0, 0)
17     circle(50, steps = 4)
18 
19     moveto(150, 0)
20     circle(50, steps = 5)
21 
22     moveto(300, 0)
23     circle(50, steps = 6)
24 
25     hideturtle()
26     done()
27 
28 main()

 

 

实验任务2 task2_1.py
 1 '''以(0,0)为圆心,绘制9个同心圆'''
 2 
 3 from turtle import *
 4 
 5 def moveto(x, y):
 6     '''把画笔移至坐标(x,y)处'''
 7     penup()
 8     goto(x, y)
 9     pendown()
10 
11 
12 def main():
13     setup(800, 600)
14 
15     radius = 20 # 圆初始半径
16     offset = 20 # 同心圆每次位移量
17 
18     for i in range(9):
19         moveto(0, -radius)
20         circle(radius)
21         radius += offset
22 
23     hideturtle()
24     done()
25 
26 main()

 

task2_2.py
 1 '''以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成'''
 2 from turtle import *
 3 from random import random
 4 
 5 def moveto(x, y):
 6     '''把画笔移至坐标(x,y)处'''
 7     penup()
 8     goto(x, y)
 9     pendown()
10 
11 def gen_color():
12     '''生成一个以rgb三元组表示的颜色值并返回'''
13     return tuple((random() for i in range(3)))
14 
15 def main():
16     setup(800, 600)
17 
18     radius = 180 # 圆初始半径
19     offset = 20 # 同心圆每次位移量
20 
21     for i in range(8):
22         moveto(0, -radius)
23         color(gen_color())
24 
25         begin_fill()
26         circle(radius)
27         end_fill()
28 
29         radius -= offset
30 
31     hideturtle()
32     done()
33 
34 main()

 

 

实验任务3 task3_1.py
 1 from turtle import*
 2 def squre(size=50,rgb='pink'):
 3     pencolor(rgb)
 4     for i in range(4):
 5         fd(size)
 6         left(90)
 7 def main():
 8     setup(800,600)
 9     speed(0)
10     n=9
11     for i in range(n):
12         squre(80)
13         left(360/n)
14     hideturtle()
15     done()
16 main()

 

task3_2.py
 1 from turtle import*
 2 setup(800,600)
 3 pencolor('pink')
 4 n=10
 5 for i in range(10):
 6     for j in range(2):
 7         circle(80,90)
 8         left(90)
 9     right(360/n)
10 hideturtle()
11 done()

 

实验任务4 task4.py
 1 from turtle import *
 2 
 3 setup(800,600)
 4 bgcolor('black')
 5 pencolor('white')
 6 speed(0)
 7 
 8 angle = 0
 9 size = 2
10 
11 n = 5
12 count = 50
13 for i in range(count):
14     fd(size)
15     angle +=360/n
16     seth(angle)
17     size+=5
18 
19 hideturtle()
20 done()

 

 

实验任务5 task5_1.py
 1 from turtle import *
 2 def move(x,y):
 3     penup()
 4     goto(x,y)
 5     pendown()
 6 move(-100,0)
 7 begin_fill()
 8 for i in range(4):
 9     fd(200)
10     left(90)
11 end_fill()
12 move(0,0)
13 begin_fill()
14 pencolor('red')
15 fillcolor('red')
16 left(45)
17 for i in range(4):
18     fd(100*2**0.5)
19     left(90)
20 end_fill()
21 hideturtle()
22 done()

task5_2.py
 1 from turtle import *
 2 def move(x,y):
 3     penup()
 4     goto(x,y)
 5     pendown()
 6 pensize(2)
 7 pencolor('blue')
 8 speed(0)
 9 r = 40
10 move(0,-r)
11 for i in range(5):
12     circle(r)
13     r+=20
14     move(0,-r)
15 move(-120,0)
16 begin_fill()
17 fillcolor('white')
18 pencolor('white')
19 for i in range(4):
20     fd(120)
21     left(90)
22 end_fill()
23 move(-120,-120)
24 begin_fill()
25 fillcolor('white')
26 pencolor('white')
27 for i in range(4):
28     fd(120)
29     left(90)
30 end_fill()
31 move(0,-120)
32 begin_fill()
33 fillcolor('white')
34 pencolor('white')
35 for i in range(4):
36     fd(120)
37     left(90)
38 end_fill()
39 pencolor('blue')
40 move(0,0)
41 fd(120)
42 move(0,0)
43 left(90)
44 fd(120)
45 hideturtle()
46 done()

 

实验任务6
 1 from turtle import *
 2 
 3 setup(800,600)
 4 speed(0)
 5 
 6 def move(x,y):
 7     penup()
 8     goto(x,y)
 9     pendown()
10 
11 bgcolor('black')
12 
13 move(0,-100)
14 pencolor('yellow')
15 fillcolor('yellow')
16 begin_fill()
17 circle(100)
18 end_fill()
19 
20 pencolor('black')
21 move(0,0)
22 begin_fill()
23 fillcolor('black')
24 right(45)
25 for i in range(4):
26     fd(100)
27     left(90)
28 
29 move(0,50)
30 circle(16)
31 end_fill()
32 
33 pencolor('white')
34 fillcolor('white')
35 begin_fill()
36 move(-4*2**0.5,50+4*2**0.5)
37 circle(4)
38 end_fill()
39 
40 hideturtle()
41 done()

 

标签:20,move,pencolor,range,实验,def,fill
From: https://www.cnblogs.com/zjyuan1013/p/17458540.html

相关文章

  • 实验6 turtle绘图与python库应用编程体验
    实验任务1fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''foriinrange(n):fd(siz......
  • Linux操作系统实训操作五(实验效果)
    Linux操作系统实训操作五(实验效果)原创 宇翔2020 网路小栈 2023-04-1007:00 发表于山东收录于合集#Linux操作系统2个#CentOS4个 1、新建用户jyzy(计应专业)、dmzy(动漫专业)、shzy(书画专业)、hkzy(航空专业),用tail命令查看/etc/passwd文件的后四行内容。(截图)。 ......
  • 实验六
    实验任务1task1.1实验源码1fromturtleimport*2defmove(x,y):3penup()4goto(x,y)5pendown()6defdraw(n,size=100):7foriinrange(n):8fd(size)9left(360/n)10defmain():11pensize(2)12p......
  • php文件上传之白名单00截断实验
    %00截断介绍:0x00,%00,/00在url中%00表示ascll码中的0,而ascii中0作为特殊字符保留,表示字符串结束,所以当url中出现%00时就会认为读取已结束。但是所谓的if拦截仍会读取后面的后缀达到绕过白名单的效果。当前版本环境:PHP版本低于5.4.24,或者PHP版本在5.5.8到5.6.0之间,且GPC......
  • 实验六
    实验任务一task1_1实验源码:1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()7defdraw(n,size=100):#绘制边长为size的正n边形8foriinrange(n):9fd(size)10left(360/n)11defmain():12......
  • Python实验课6
    实验任务一实验源码:fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)......
  • 实验六
    实验1task1.1实验源码1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验七
    任务一实验源码1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._c......
  • 实验六
    任务一实验源码1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验六
    实验任务一实验源码:fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)......