首页 > 其他分享 >实验六

实验六

时间:2023-06-12 13:11:06浏览次数:35  
标签:10 20 range 实验 def left

实验1

task1.1

实验源码

 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 main()
View Code

实验截图

task1.2

实验源码

 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 main()
View Code

实验截图

实验2

task2.1

实验源码

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

实验截图

task2.2

实验源码

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

实验截图

实验3

task3.1

实验源码

 1 from turtle import*
 2 
 3 def square(size = 50, rgb = 'pink'):#'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 main()
View Code

实验截图

task3.2

实验源码

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

实验截图

实验4

实验源码

 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 hideturtle()
20 done()
View Code

实验截图

实验5

task5.1

实验源码

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

实验截图

task5.2

实验源码

 1 from turtle import*
 2 
 3 def moveto(x,y):
 4     penup()
 5     goto(x,y)
 6     pendown()
 7 
 8 pencolor('blue')
 9 pensize(2)
10 speed = 0
11 
12 def main():
13     setup(800,600)
14 
15     radius = 40
16     offset = 20
17 
18     for i in range(5):
19         moveto(0,0)
20         fd(radius)
21         left(90)
22         circle(radius,90)
23         left(90)
24         fd(radius)
25         left(90)
26         radius += 20
27 
28     hideturtle()
29     done()
30 
31 main()
View Code

实验截图

实验6

task6.1

实验源码

 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 draw_ract(x,y,width,height):
13     moveto(x,y)
14     setheading(0)
15     for i in range(2):
16         forward(width)
17         left(90)
18         forward(height)
19         left(90)
20 
21 for t in range(20):
22     x0 = -100
23     rgb = gen_color()
24     pencolor(rgb)
25     fillcolor(rgb)
26     begin_fill()
27     draw_ract(x0+10*t , 10,10,100)
28     end_fill()
29 
30 hideturtle()
31 done()
View Code

实验截图

task6.2

实验源码

 1 from turtle import*
 2 
 3 setup(800,600)
 4 fillcolor('yellow')
 5 bgcolor('black')
 6 speed(0)
 7 
 8 begin_fill()
 9 left(45)
10 fd(150)
11 left(90)
12 circle(150,270)
13 left(90)
14 fd(150)
15 end_fill()
16 
17 def moveto(x,y):
18     penup()
19     goto(x,y)
20     pendown()
21 
22 moveto(4,70)
23 fillcolor('black')
24 begin_fill()
25 circle(10)
26 end_fill()
27 
28 moveto(-4,70)
29 fillcolor('white')
30 begin_fill()
31 circle(3)
32 end_fill()
33 
34 hideturtle()
35 done()
View Code

实验截图

 

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

相关文章

  • 实验七
    任务一实验源码1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._c......
  • 实验六
    任务一实验源码1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验六
    实验任务一实验源码: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)......
  • 实验七
    task4#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intmain(){charch;FILE*fp;inti=0;fp=fopen("data4.txt","r");ch=fgetc(fp);while(ch!=EOF){if(ch!=''&......
  • 实验6
    task1fromturtleimport*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(3......
  • 实验六
    实验任务一实验源码: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)......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1-11fromturtleimport*2defmove(x,y):3penup()4goto(x,y)5pendown()6defdraw(n,size=100):7foriinrange(n):8fd(size)9left(360/n)10defmain():11pensize(2)12pencolor(......
  • 实验六
    任务1: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)draw(3)m......
  • 实验7 面向对象编程与内置模块
    实验任务1:实验源码:1classAccount:2"""一个模拟银行账户的简单类"""34def__init__(self,name,account_number,initial_amount=10):5"""构造新账户"""6self._name=name7......
  • 实验6
    实验任务1task1_1实验源码:1fromturtleimport*23defmoveto(x,y):4'''5画笔移动到坐标(x,y)处6'''7penup()8goto(x,y)9pendown()1011defdraw(n,size=100):12'''13......