首页 > 其他分享 >实验6

实验6

时间:2023-06-07 17:02:35浏览次数:38  
标签:range 实验 import 90 circle left fill

task1_1.py

实验源码:

from turtle import *
def move(x, y):
    penup()
    goto(x, y)
    pendown()
def draw(n, size = 100):
    for i in range(n):
        fd(size)
        left(360/n)
def main():
    pensize(2)
    pencolor('red')
    move(-200, 0)
    draw(3)
    move(0, 0)
    draw(4)
    move(200, 0)
    draw(5)
    hideturtle()
    done()
main()

运行结果:

task1_2.py

实验源码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def main():
    pensize(2)
    pencolor('blue')
    moveto(-150, 0)
    circle(50)
    moveto(0, 0)
    circle(50, steps = 4)
    moveto(150, 0)
    circle(50, steps = 5)
    moveto(300, 0)
    circle(50, steps = 6)
    hideturtle()
    done()
main()

运行结果:

task2_1.py

实验源码:

'''以(0,0)为圆心,绘制9个同心圆'''
from turtle import *
def moveto(x, y):
    '''把画笔移至坐标(x,y)处'''
    penup()
    goto(x, y)
    pendown()
def main():
    setup(800, 600)
    radius = 20 # 圆初始半径
    offset = 20 # 同心圆每次位移量
    for i in range(9):
        moveto(0, -radius)
        circle(radius)
        radius += offset

    hideturtle()
    done()
main()

运行结果:

task2_2.py

实验源码:

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

运行结果:

task3_1.py

实验源码:

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

运行结果:

task3_2.py

实验源码:

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

运行结果:

task4.py

实验源码:

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

运行结果:

task5_1.py

实验源码:

 1 from turtle import *
 2 setup(800, 600)
 3 penup()
 4 goto(0,0)
 5 pendown()
 6 pensize(3)
 7 pencolor("black")
 8 fillcolor("black")
 9 begin_fill()
10 for i in range(4):
11     forward(200)
12     left(90)
13 end_fill()
14 penup()
15 goto(100,0)
16 pendown()
17 pencolor("red")
18 fillcolor("red")
19 begin_fill()
20 left(45)
21 forward(141)
22 left(90)
23 forward(141)
24 left(90)
25 forward(141)
26 left(90)
27 forward(141)
28 end_fill()
29 hideturtle()
30 done()

运行截图:

 task5_2.py

实验源码:

 1 from turtle import *
 2 setup(800, 600)
 3 penup()
 4 goto(0,0)
 5 pendown()
 6 pensize(2)
 7 pencolor("blue")
 8 for i in range(0,5):
 9     forward(40+i*20)
10     left(90)
11     circle(40+i*20,90)
12     left(90)
13     forward(40+i*20)
14     left(90)
15 hideturtle()
16 done()

运行结果:

task6.py

实验源码:

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

运行结果:

 

标签:range,实验,import,90,circle,left,fill
From: https://www.cnblogs.com/lsh111111/p/17458634.html

相关文章

  • 恒电流间歇滴定法(GITT)测试锂离子电池的实验流程
    恒电流间歇滴定法(GITT)测试锂离子电池的实验流程锂电池作为现代电子设备中最常用的电源之一,其性能和安全性对于设备的正常运行至关重要。恒电流间歇滴定测试是一种常用的测试方法,用于评估锂电池的容量、循环寿命和内阻等关键参数。1、确定测试目的和参数:在进行恒电流间歇滴定测试之......
  • 实验7 面向对象编程与内置模块
    实验任务1classAccount:#一个模拟账户类def__init__(self,name,account_number,initial_amount=10):'''构造新账户'''self._name=nameself._card_no=account_numberself._balance=initial_amount......
  • 实验7 面向对象编程与内置模块
    实验任务1源代码1classAccount:2def__init__(self,name,account_number,initial_amount=10):3self._name=name4self._card_no=account_number5self._balance=initial_amount67defdeposit(self,amount):8sel......
  • 《大学物理实验上》期末笔记(二)有效数字特典
    《大学物理实验上》期末笔记(二)有效数字特典最头疼的一集有效数字测量值存在误差是不可避免的,因而测量值包含了准确数字和欠准数字。我们将准确数字和欠准数字总称为有效数字。在大学物理实验中,通常只取一位欠准数字,因此有效数字由若干位准确数字和一位欠准数字组成。有效数......
  • 【锐格】数据结构-实验-二叉树
    7075#include<iostream>#include<cstdio>usingnamespacestd;typedefstructTNode{chardata;structTNode*lchild,*rchild;}BiNode,*BiTree;BiTreeT;voidcreateTree(BiTree&T){charch;cin>>ch;if(ch==&#......
  • 【锐格】数据结构-实验-图
    7039#include<iostream>#include<cstdio>usingnamespacestd;constintMAX_NUM=100;intw;intmark[MAX_NUM];typedefintEdgeData;typedefstructNode{intdest;EdgeDataweight;//边权structNode*next;//nextroute}EdgeNode;......
  • 实验六 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&#......
  • 实验6
    实验任务1task1源代码: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)......
  • 实验五 文件应用编程
    task6withopen('data6.csv','r',encoding='gbk')asf:data=f.readlines()data.remove('原始数据\n')data0=[]foriindata:ifi[-1]=='\n':i=i[:-1]data0.append(float(i))print('原始......
  • 实验7 面向对象编程与内置模块
    task1classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,account):self._balance+=accountdefwit......