首页 > 其他分享 >实验六

实验六

时间:2023-06-09 19:11:16浏览次数:35  
标签:10 range 实验 import circle def fill

任务一

1

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

2

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

任务二

1

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

2

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

任务三

1

 1 from turtle import *
 2 def square(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 = 50
11     for i in range(n):
12         square(80)
13         left(360/n)
14     hideturtle()
15     done()
16 main()

2

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

任务四

 1 from turtle import *
 2 setup(800, 600)
 3 bgcolor('black')
 4 pencolor('white')
 5 speed(0)
 6 angle = 0
 7 size = 2
 8 n = 5
 9 count = 100
10 for i in range(count):
11     fd(size)
12     angle += 360/n
13     seth(angle)
14     size += 5
15 hideturtle()
16 done()

任务五

1

 1 from turtle import *
 2 goto(-100,-100)
 3 color('black')
 4 begin_fill()
 5 for i in range(4):
 6     fd(200)
 7     left(90)
 8 end_fill()
 9 goto(0,-100)
10 color('red')
11 begin_fill()
12 circle(100,steps=4)
13 end_fill()
14hideturtle()
15 done()

 

2

 1 from turtle import *
 2 pensize(2)
 3 pencolor('blue')
 4 for i in range(5):
 5     fd(40+20*i)
 6     left(90)
 7     circle(40+20*i,90)
 8     left(90)
 9     fd(40+20*i)
10     left(90)
11 hideturtle()
12 done()

 

任务六

 1 from turtle import *
 2 bgcolor('black')
 3 color('yellow')
 4 begin_fill()
 5 left(45)
 6 forward(100)
 7 left(90)
 8 circle(100,270)
 9 left(90)
10 forward(100)
11 end_fill()
12 color('black')
13 penup()
14 sety(50)
15 pendown()
16 begin_fill()
17 circle(10)
18 end_fill()
19 color('white')
20 penup()
21 sety(50)
22 pendown()
23 begin_fill()
24 circle(3)
25 end_fill()
26 hideturtle()
27 
28 done()

 

标签:10,range,实验,import,circle,def,fill
From: https://www.cnblogs.com/new22/p/17466725.html

相关文章

  • 实验7
    实验任务1代码:#include<stdlib.h>#include<stdio.h>#defineN7#defineM80typedefstruct{charname[M];charauthor[M];}Book;intmain(){Bookx[N]={{"《雕塑家》","斯科特.麦克劳德"},{"《灯塔》",&......
  • 实验7
    4.task41#include<stdio.h>23intmain(){4charch;5intk=0;6FILE*fp;78fp=fopen("data4.txt","r");9if(fp==NULL){10printf("failtoopenfile\n");11......
  • 实验六 实验6 turtle绘图与python库应用编程体验
    task1_1源代码:fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinrange(n):......
  • 实验七
    task4#include<stdio.h>#include<stdlib.h>intmain(){inti=0;FILE*fp;charch;fp=fopen("data4.txt","r");if(fp==NULL){printf("failtoopen\n");returni;}......
  • 实验7
    task4源码//task4#include<stdio.h>intmain(){inti=0;charch;FILE*fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("读取失败\n");return1;}w......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1:task1_1实验源码:1fromturtleimport*234defmove(x,y):5penup()6goto(x,y)7pendown()8910defdraw(n,size=100):11foriinrange(n):12fd(size)13left(360/n)141516defmain():17......
  • XJTU-ICS Lab 4: Optimization Lab 性能优化实验
    PartA:性能测量  首先别忘了预热cache。先跑一遍poly函数,从而避免在测量时由于coldcache带来的cachemiss而导致测量值偏大。然后跑若干次poly函数,分别测量运行时间并取平均值。voidmeasure_time(poly_func_tpoly,constdoublea[],doublex,longdegree,do......
  • 实验七
    任务4:代码:#include<stdio.h>intmain(){intsize=0;charsum;FILE*fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("fail......
  • SQL SERVER实验-- 数据检索
    实验3 数据检索一、实验目的(1)理解T-SQL语言的使用。(2)熟练掌握数据查询语句。SELECT[ALL|DISTINCT]{*|<表达式>,…,<表达式>}FROM<表名>[,<表名>…][WHERE<条件>][GROUPBY<列名>[,<列名>…][HAVING<谓词>]][ORDERBY<列名>......
  • 51串口proteus仿真实验
    一、实验目的1、了解单片机串口接收与发送方法。2、了解串口助手使用方法。3、了解数码管动态显示方法。4、了解单片机串口中断服务函数用法。二、实验内容1、完成单片机串口往电脑发送数据实验。2、完成电脑串口助手往单片机发送学号,并通过单片机串口完成学号回传,并利用数......