首页 > 其他分享 >实验六

实验六

时间:2023-06-06 23:46:39浏览次数:36  
标签:moveto range radius 实验 main def

实验任务1-1

实验源码

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

运行测试截图

实验任务1-2

实验源码

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

运行测试截图

实验任务2-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-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     setup(800, 600)
11     radius = 180
12     offset = 20
13     for i in range(8):
14         moveto(0, -radius)
15         color(gen_color())
16         begin_fill()
17         circle(radius)
18         end_fill()
19         radius -= offset
20     hideturtle()
21     done()
22 main()

运行测试截图

实验任务3-1

实验源码

 

from turtle import *

def square(size = 50, rgb = 'yellow'):
    pencolor(rgb)
    for i in range(4):
        fd(size)
        left(90)

def main():
    setup(800,600)
    speed(0)

    n = 10
    for i in range(n):
        square(80)
        left(360/n)

    hideturtle()
    done()
main()

运行测试截图

 实验任务3-2

实验源码

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

运行测试截图

实验任务4

实验源码

 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 = 50
10 for i in range(count):
11     fd(size)
12     angle += 360/n
13     seth(angle)
14     size+=5
15 hideturtle()
16 done()

运行测试截图

实验任务5-1

实验源码

 1 from turtle import *
 2 penup()
 3 goto(-100,-100)
 4 pendown()
 5 color('black')
 6 begin_fill()
 7 for i in range(4):
 8     fd(200)
 9     left(90)
10 end_fill()
11 penup()
12 goto(-100,0)
13 pendown()
14 seth(45)
15 color('red')
16 begin_fill()
17 for i in range(4):
18     fd(100*(2**0.5))
19     right(90)
20 end_fill()
21 done()

运行测试截图

实验任务5-2

实验源码

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

运行测试截图

实验任务6

实验源码

 1 from turtle import *
 2 def move(x,y):
 3     penup()
 4     goto(x,y)
 5     pendown()
 6 bgcolor('black')
 7 color('yellow')
 8 move(0,-100)
 9 begin_fill()
10 circle(100)
11 end_fill()
12 color('black')
13 speed(0)
14 move(87,-51)
15 seth(60)
16 begin_fill()
17 circle(100,80)
18 home()
19 end_fill()
20 move(-30,60)
21 dot(30,'black')
22 move(-38,60)
23 dot(5,'white')
24 
25 hideturtle()
26 done()

运行测试截图

 

标签:moveto,range,radius,实验,main,def
From: https://www.cnblogs.com/yongzhulazhen/p/17458351.html

相关文章

  • 实验五 文件应用编程
    task6.py1withopen('data6.csv','r',encoding='gbk')asf:2data1=f.read().split('\n')3deldata1[0]4foriinrange(len(data1)):5data1[i]=eval(data1[i])6data1[i]=float(data1[i])7......
  • 实验6
    1.实验任务1task1_1.py程序源代码:fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinran......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1_.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(-20......
  • 实验5
    task6源码:importcsvwithopen('data6.csv','r',encoding='gbk')asf:data_o=f.readlines()foriinrange(len(data_o)):data_o[i]=data_o[i].strip('\n')#原始数据deldata_o[0]#处理后数据data_1=[]ford_......
  • 实验五 文件应用编程
    实验五 文件应用编程 实验任务六程序源代码:1withopen('data6.csv','r',encoding='gbk')asf:2old_data=f.read().split('\n')3delold_data[0]4processed_data=[]5foriinrange(len(old_data)):6ifeval(old......
  • 实验5 文件应用编程
    实验任务1:统计文件行数(不统计空白行)task1_1.py'''统计文件data1.txt行数(不包括空白行)data1.txt中的空白行包括由空格、Tab键(\t)、换行(\n)构成的空白行'''withopen('data1.txt','r',encoding='utf-8')asf:data=f.readlines()n=0fo......
  • 野火STM32第35章 SDIO读写测试 实验过程犯的错误:卡在while(SD_GetStatus() != SD_TRAN
    看完书,我自己重新写了一遍代码。写代码过程中,对DMA以下标绿的部分很不以为意。1voidSD_DMA_TxConfig(uint32_t*DMA_Tx_Buf,uint32_tBufferSize)2{3DMA_InitTypeDefDMA_InitStruct;45/*ClockEnable-----InGPIOConfig*/67/*Flag......
  • 实验7 面向对象编程与内置模块
    task1.pycode:classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):self._balance+=a......
  • 实验5 文件应用编程
    task6源代码:withopen('data6.csv','r',encoding='gbk')asf:data1=f.read().split('\n')deldata1[0]foriinrange(len(data1)):data1[i]=eval(data1[i])data1[i]=float(data1[i])print('原始数据:&#......
  • 实验5 文件应用编程
    实验任务61withopen('data6.csv','r',encoding='gbk')asf:2data1=f.read().split('\n')3deldata1[0]4foriinrange(len(data1)):5data1[i]=eval(data1[i])6data1[i]=float(data1[i])7pri......