首页 > 其他分享 >实验6

实验6

时间:2023-06-06 23:45:18浏览次数:36  
标签:moveto 源代码 实验 circle main def fill

1.实验任务1

task1_1.py

程序源代码:

from turtle import *
def move(x, y):
    '''画笔移动到坐标(x,y)处'''
    penup()
    goto(x, y)
    pendown()
def draw(n, size = 100):
    '''绘制边长为size的正n变形'''
    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):
    '''画笔移动到坐标(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()

 运行程序截图:

 

2.实验任务2

task2_1.py

程序源代码:

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

程序源代码:

from turtle import *
from random import random
def moveto(x, y):
    '''画笔移动到坐标(x,y)处'''
    penup()
    goto(x, y)
    pendown()
def gen_color():
    return tuple(random() for i in range(3))
def main():
    setup(800, 600)
    radius = 180 # 圆初始半径
    offset = 20 # 同心圆每次位移量
    for i in range(8):
        moveto(0, -radius)
        color(gen_color())
        begin_fill()
        circle(radius)
        end_fill()
        radius += offset
    hideturtle()
    done()
main()

 

运行程序截图:

 

 

3.实验任务3

task3_1.py

程序源代码: 

from turtle import *
def square(size = 50, rgb = 'orange'):
    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()

 

 

 

运行程序截图:

 

 

task3_2.py

程序源代码:

from turtle import *
setup(800, 600)
pencolor('pink')
n = 10
for i in range(10):
    # 绘制一片花瓣
    for j in range(2):
        circle(80, 90)
        left(90)
    right(360/n)
hideturtle()
done()

 

 

 

运行程序截图:

 

 

 

4.实验任务4

task4.py

运行源代码:

from turtle import *
setup(800, 600)
bgcolor('black')
pencolor('white')
speed(0)
angle = 0
size = 2
n = 5 # 螺旋n边形
count = 50 # 循环次数
for i in range(count):
    fd(size)
    angle += 360/n
    seth(angle)
    size += 5
hideturtle()
done()

 

程序运行截图:

 

5.实验任务5

task5_1.py

实验源代码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()

def main():
    moveto(-100,-100)
    color('black')
    begin_fill()
    for i in range(4):
        forward(200)
        left(90)
    end_fill()
    color('red')
    begin_fill()
    moveto(0,-100)
    circle(100,steps=4)
    end_fill()
main()

运行程序截图:

 task5_2.py

程序源代码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()

def main():
    pencolor('blue')
    pensize(2)
    n=40
    for i in range(5):
        moveto(0,0)
        forward(n)
        left(90)
        circle(n,90)
        left(90)
        forward(n)
        left(90)
        n+=20

main()

 

运行程序截图:

 

6.实验任务6

task6_2.py

程序源代码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()

def main():
    bgcolor('black')
    color('yellow')
    begin_fill()
    moveto(0,0)
    left(45)
    forward(100)
    left(90)
    circle(100,270)
    left(90)
    forward(100)
    end_fill()
    moveto(15,60)
    color('black')
    begin_fill()
    circle(10,360)
    end_fill()
    moveto(5,55)
    color('white')
    begin_fill()
    circle(2,360)
    end_fill()
hideturtle()
main()

运行程序截图:

 

标签:moveto,源代码,实验,circle,main,def,fill
From: https://www.cnblogs.com/nettj666/p/17462085.html

相关文章

  • 实验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......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1_1fromturtleimport*defmoveto(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''for......
  • 实验5
    1withopen('data6.csv','r',encoding='gbk')asf:2data1=f.read().split('\n')3deldata1[0]4print('原始数据:')5print(data1)67foriinrange(len(data1)):8data1[i]=float(data1[i]......