首页 > 其他分享 >实验6

实验6

时间:2023-06-08 19:44:40浏览次数:37  
标签:10 20 range 实验 90 def left

task1_1

源代码:

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

运行截图:

 

 

 

task1_2

源代码:

 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()

运行截图:

 

 

 

task2_1

源代码:

 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 def main():
12     setup(800,600)
13 
14     radius = 20 #圆初始半径
15     offset = 20 #同心圆每次位移量
16 
17     for i in range(9):
18         moveto(0,-radius)
19         circle(radius)
20         radius += offset
21 
22     hideturtle()
23     done()
24 
25 main()

运行截图:

 

 

 

task2_2

源代码:

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

 

运行截图:

 

 

 

task3_1

源代码:

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

运行截图:

 

 

 

task3_2

源代码:

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

运行截图:

 

 

 

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()

运行截图:

 

 

 

task5_1

源代码:

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

运行截图:

 

 

task5_2

源代码:

 1 from turtle import*
 2 
 3 def move(x,y):
 4     '''画笔移动到坐标(x,y)处'''
 5     penup()
 6     goto(x,y)
 7     pendown()
 8 
 9 pensize(2)
10 pencolor('Blue')
11 n = 5
12 left(-90)
13 
14 for i in range(n):
15     left(90)
16     move(0,0)
17     fd(40+20*i)
18     left(90)
19     circle(40+20*i,90)
20     left(90)
21     fd(40+20*i)
22 
23 hideturtle()
24 done()

运行截图:

 

 

 

task6 选做第一个

源代码:

 1 from turtle import *
 2 from random import random
 3 
 4 def move(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 def rect(a,b,c):
12     color(c)
13     fd(a)
14     left(90)
15     fd(b)
16     left(90)
17     fd(a)
18     left(90)
19     fd(b)
20 
21 setup(800,600)
22 move(-100,0)
23 for i in range(20):
24     c = gen_color()
25     begin_fill()
26     rect(10,30,c)
27     end_fill()
28     left(90)
29     fd(10)
30 
31 hideturtle()
32 done()

运行截图:

 

标签:10,20,range,实验,90,def,left
From: https://www.cnblogs.com/ljxljx317/p/17467182.html

相关文章

  • 实验七
    任务三#include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;charch;intchar_count=0;fp=fopen("data4.txt","r");if(fp==NULL){printf("Couldnotopenfiledata4.txt.\n&q......
  • 实验7
    任务4源代码#include<stdio.h>#include<string.h>intmain(){FILE*fp;inti,num=0;chars[7][80];fp=fopen("data4.txt","r");if(fp==NULL){printf("failtoopenfp\n");......
  • 实验6 turtle绘图与python库应用编程体验
    task1-1fromturtleimport*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)draw......
  • 实验七
    实验任务4程序代码:#include<stdio.h>#include<string.h>#include<stdlib.h>intmain(){FILE*fp;charstr[100];inti,k=0,flag;while((fp=fopen("data4.txt","r"))==NULL)printf("failtoopen&quo......
  • 实验7
    实验任务4实验代码#include<stdio.h>#include<stdlib.h>#include<string.h>constintN=5,M=100;intmain(){charch[M];intn=0; FILE*fp; fp=fopen("data4.txt","r"); while(!feof(fp))......
  • 实验7
    #11#12classAccount:3def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount78defdeposit(self,amount):9'......
  • 实验七
    classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,account):self._balance+=accountdefwithdraw(s......
  • 实验六
    task11fromturtleimport*2defmove(x,y):3penup()4goto(x,y)5pendown()6defdraw(n,size=100):7foriinrange(n):8fd(size)9left(360/n)10defmain():11pensize(2)12pencolor('red......
  • 实验七
    任务一1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._card_no......
  • 《大学物理实验上》期末笔记(三)作图法以及一些实验
    《大学物理实验上》期末笔记(三)作图法以及一些实验数据处理有多种方法,下面仅就作图法、逐差法作简单介绍。作图法就考试来说,结果不是最主要的,过程才重要。评分标准(共15分):图的题目——1分横坐标的物理符号与单位、还有分度选择——各1分,共3分纵坐标的物理符号与单位、还有分......