首页 > 其他分享 >实验6

实验6

时间:2023-06-11 22:56:18浏览次数:27  
标签:10 20 range radius import 实验 def

1.实验任务1

task1_1.py

 1 from turtle import *
 2 
 3 def move(x,y):
 4     penup()
 5     goto(x,y)
 6     pendown()
 7 
 8 def draw(n,size = 100):
 9     for i in range(n):
10         fd(size)
11         left(360/n)
12 
13 def main():
14     pensize(2)
15     pencolor('red')
16 
17     move(-200,0)
18     draw(3)
19 
20     move(0,0)
21     draw(4)
22 
23     move(200,0)
24     draw(5)
25 
26     hideturtle()
27     done()
28 
29 
30 main()

task1_2.py

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

2.实验任务2

task2_1.py

 1 from turtle import *
 2 
 3 def moveto(x,y):
 4     penup()
 5     goto(x,y)
 6     pendown()
 7 
 8 def main():
 9     setup(800,600)
10 
11     radius = 20
12     offset = 20
13 
14     for i in range(9):
15         moveto(0,-radius)
16         circle(radius)
17         radius+=offset
18 
19     hideturtle()
20     done()
21 
22 main()

task2_2.py

 1 from turtle import *
 2 from random import random
 3 
 4 def moveto(x,y):
 5     penup()
 6     goto(x,y)
 7     pendown()
 8 
 9 def gen_color():
10     return tuple((random() for i in range(3)))
11 
12 def main():
13     setup(800,600)
14 
15     radius = 180
16     offset = 20
17 
18     for i in range(8):
19         moveto(0,-radius)
20         color(gen_color())
21 
22         begin_fill()
23         circle(radius)
24         end_fill()
25 
26         radius -= offset
27 
28     hideturtle()
29     done()
30 
31 main()

3.实验任务3

task3_1.py

 1 from turtle import *
 2 
 3 def square(size = 50,rgb = 'pink'):
 4     pencolor(rgb)
 5     for i in range(4):
 6         fd(size)
 7         left(90)
 8 
 9 def main():
10     setup(800,600)
11     speed(0)
12 
13     n = 10
14     for i in range(n):
15         square(80,'orange')
16         left(360/n)
17 
18     hideturtle()
19     done()
20 
21 main()

task3_2.py

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

4.实验任务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 
20 hideturtle()
21 done()

5.实验任务5

task5_1.py

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

task5_2.py

 1 from turtle import *
 2 
 3 def move(x,y):
 4     penup()
 5     goto(x,y)
 6     pendown()
 7 
 8 move(0,0)
 9 pensize(2)
10 pencolor('blue')
11 radius = 40
12 for i in range(5):
13     fd(radius)
14     left(90)
15     circle(radius,90)
16     left(90)
17     fd(radius)
18     left(90)
19     radius+=20
20 hideturtle()
21 done()

task6.py

 1 from turtle import *
 2 from random import random
 3 
 4 def gen_color():
 5     return tuple((random()for i in range(3)))
 6 
 7 def rect(x,y,color):
 8     fillcolor(color)
 9     begin_fill()
10     for i in range(2):
11         fd(x)
12         left(90)
13         fd(y)
14         left(90)
15     end_fill()
16 
17 setup(800,600)
18 penup()
19 goto(-200,-30)
20 for i in range(20):
21     rect(20,60,gen_color())
22     fd(20)
23 
24 hideturtle()
25 done()

 

标签:10,20,range,radius,import,实验,def
From: https://www.cnblogs.com/wang2003chengxu/p/17473804.html

相关文章

  • 实验六
    task1源代码#1.1fromturtleimport*defmoveto(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''for......
  • 实验七
    任务4#include<stdio.h>intmain(){FILE*fp;fp=fopen("data4.txt","r");intn,c;if(fp==NULL){printf("failtoopenfile\n");return1;}while((c=fgetc(fp))!=EOF) {......
  • 实验6 turtle绘图与python库应用编程体验
    task1-1源代码1fromturtleimport*23defmove(x,y):4'''画笔移动到坐标(x,y)处'''5penup()6goto(x,y)7pendown()89defdraw(n,size=100):10'''绘制边长为size的正n变形'''1......
  • 实验六
    实验任务1task1:1fromturtleimport*23defmove(x,y):4'''画笔移动到坐标(x,y)处'''5penup()6goto(x,y)7pendown()89defdraw(n,size=100):10'''绘制边长为size的正n边形''......
  • 实验7 面向对象编程与内置模块
    实验1task1.py实验源码:classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'''构造新账户'''self._name=nameself._card_no=......
  • 实验6 turtle绘图与Python库应用编程体验
    task1-1.py实验源码: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)......
  • 决策树(实验室会议小记)
    特征选择为什么要进行特征选择?特征过多导致过拟合、有一些特征是噪音。特征选择技术:1、尝试所有组合:也是全局最优2、贪心算法:每次决策都是基于当前情况去寻找最优解。计算过程:把特征加进去→是否更优?→是:加入模型/否:淘汰3、L1正则:目标函数为损失函数;特点:具有稀疏性4、决......
  • 实验6 turtle绘图与python库应用编程体验
    task1_1代码:fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinrange(n):......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1_1.py程序源码:1fromturtleimport*23defmove(x,y):#画笔移动到坐标(x,y)处4penup()5goto(x,y)6pendown()78defdraw(n,size=100):#绘制边长为size的正n变形9foriinrange(n):10forward(size)11......
  • 实验7
    实验1、2、3已实践实验4:代码如下#include<stdio.h>intmain(){charch;intk=0;FILE*fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("failtoopenfile\n");return1;}w......