首页 > 其他分享 >实验6

实验6

时间:2023-06-11 23:13:41浏览次数:31  
标签:moveto 20 range radius 实验 def left

实验任务1

task1_1

实验源码:

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

截图:

 task1_2

实验源码:

 1 # 运用circle函数,实现正多边形绘制
 2 from turtle import *
 3 
 4 def moveto(x,y):
 5     '''
 6     画笔移动到坐标(x,y)处
 7     '''
 8     penup()
 9     goto(x,y)
10     pendown()
11 
12 def main():
13     pensize(2)
14     pencolor('blue')
15 
16     moveto(-150,0)
17     circle(50)
18 
19     moveto(0,0)
20     circle(50,steps = 4)
21 
22     moveto(150,0)
23     circle(50,steps = 5)
24 
25     moveto(300,0)
26     circle(50,steps = 6)
27 
28     hideturtle()
29     done()
30 
31 main()

截图:

 

实验任务2

task2_1

实验源码:

 1 # 用turtle绘制9个同心圆
 2 from turtle import *
 3 
 4 def moveto(x,y):
 5     penup()
 6     goto(x,y)
 7     pendown()
 8 
 9 def main():
10     setup(800,600)
11 
12     radius = 20 # 圆初始半径
13     offset = 20 # 同心圆每次位移量
14 
15     for i in range(9):
16         moveto(0,-radius)
17         circle(radius)
18         radius += offset
19 
20     hideturtle()
21     done()
22 
23 main()

截图:

 task2_2_1

实验源码:

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

截图:

 

task2_2_2

实验源码:

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

截图:

 

实验任务3

task3_1

实验源码:

 1 # 用矩形绘制花瓣
 2 from turtle import *
 3 
 4 def square(size = 50, rgb = 'pink'):
 5     '''
 6     绘制正方形
 7     :para: size:int 指定边长 (如未指定参数,使用默认值)
 8     :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值)
 9     '''
10     pencolor(rgb)
11     for i in range(4):
12         fd(size)
13         left(90)
14 
15 def main():
16     setup(800, 600)
17     speed(0)
18 
19     n = 3
20     for i in range(n):
21         square(80)
22         left(360/n)
23 
24     hideturtle()
25     done()
26 
27 main()

截图:

 

 1 # 用矩形绘制花瓣
 2 from turtle import *
 3 
 4 def square(size = 50, rgb = 'pink'):
 5     '''
 6     绘制正方形
 7     :para: size:int 指定边长 (如未指定参数,使用默认值)
 8     :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值)
 9     '''
10     pencolor(rgb)
11     for i in range(4):
12         fd(size)
13         left(90)
14 
15 def main():
16     setup(800, 600)
17     speed(0)
18 
19     n = 4
20     for i in range(n):
21         square(80)
22         left(360/n)
23 
24     hideturtle()
25     done()
26 
27 main()

截图:

 

 1 # 用矩形绘制花瓣
 2 from turtle import *
 3 
 4 def square(size = 50, rgb = 'pink'):
 5     '''
 6     绘制正方形
 7     :para: size:int 指定边长 (如未指定参数,使用默认值)
 8     :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值)
 9     '''
10     pencolor(rgb)
11     for i in range(4):
12         fd(size)
13         left(90)
14 
15 def main():
16     setup(800, 600)
17     speed(0)
18 
19     n = 5
20     for i in range(n):
21         square(80)
22         left(360/n)
23 
24     hideturtle()
25     done()
26 
27 main()

 n = 10

 task3_2

实验源码:

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

截图:

 

实验任务4

task4

实验源码:

 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 # 螺旋n边形
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

实验源码:

 1 # 先画外围正方形
 2 from turtle import *
 3 
 4 def moveto(x, y):
 5     penup()
 6     goto(x, y)
 7     pendown()
 8 
 9 color('black')
10 begin_fill()
11 moveto(-100,-100)
12 for i in range(4):
13     fd(200)
14     left(90)
15 end_fill()
16 
17 # 再画内三角形
18 color('red')
19 
20 begin_fill()
21 moveto(0,-100)
22 left(45)
23 for i in range(4):
24     fd(100*2**(1/2))
25     left(90)
26 end_fill()
27 hideturtle()
28 done()

截图:

 task5_2

实验源码:

 1 size = 5
 2 color('blue')
 3 
 4 radius = 40
 5 for i in range(5): # 扇形的个数
 6     fd(radius)
 7     left(90)
 8     circle(radius,90)
 9     left(90)
10     fd(radius)
11     left(90)
12     radius += 20
13 
14 hideturtle()
15 done()

截图:

 实验任务6

实验源码:

 1 from turtle import *
 2 screensize(100,100,'black')
 3 
 4 def moveto(x, y):
 5     penup()
 6     goto(x, y)
 7     pendown()
 8 
 9 # 画脸
10 color('yellow')
11 begin_fill()
12 left(45)
13 fd(100)
14 left(90)
15 circle(100,270)
16 left(90)
17 fd(100)
18 end_fill()
19 
20 # 画眼睛
21 moveto(10,65)
22 dot(15,'black')
23 
24 # 画高光
25 moveto(8,70)
26 dot(8,'white')
27 
28 hideturtle()
29 done()

截图:

 

标签:moveto,20,range,radius,实验,def,left
From: https://www.cnblogs.com/zyaiyj-www-2003/p/17473821.html

相关文章

  • 实验7
    实验任务11classAccount:2#一个模拟账户类3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._card_no=account_number7self._balanc......
  • 实验6
    1.实验任务1task1_1.py1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验六
    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):......