首页 > 其他分享 >实验6

实验6

时间:2023-06-07 20:22:13浏览次数:47  
标签:sector fd range radius strip 实验 def

task1_1

源码:

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

源码:

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

截图:

 task2_1

源码

"""以(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

源码:

"""以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成"""
from turtle import *
from random import random


def moveto(x, y):
    """把画笔移至坐标(x,y)处"""
    penup()
    goto(x, y)
    pendown()


def gen_color():
    """生成一个以rgb三元组表示的颜色值并返回"""
    return tuple((random() for _ 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()

截图:

task3_1

源码:

from turtle import *
def square(size = 50, rgb = 'pink'):
    """绘制正方形
    :para: size:int 指定边长 (如未指定参数,使用默认值)
    :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值)
    """
    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,rgb = 'orange')
        left(360/n)
    hideturtle()
    done()
main()

截图:

 task3_2

源码:

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

截图:

 task4:

源码:

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

截图:

task5_1

源码:

from turtle import *
square = Turtle()
square.color('black')
square.penup()
square.goto(-100,-100)

square.pendown()
square.begin_fill()
for _ in range(4):
    square.fd(200)
    square.left(90)
square.end_fill()


s2 = Turtle()
s2.color('red')
s2.penup()
s2.goto(0,-100)

s2.pendown()
s2.left(45)
s2.begin_fill()
for _ in range(4):
    s2.fd(100*(2**0.5))
    s2.left(90)
s2.end_fill()
done()

截图:

 task5_2

源码:

from turtle import *
sector = Turtle()
# 初始化绘图参数
sector.penup()
sector.goto(0, 0)
sector.color('blue')
sector.pensize(2)
sector.speed(0)
# 设置扇形数值
radius = 40
delta_d = 20
sector.pendown()
for _ in range(5):
    sector.fd(radius)
    sector.left(90)
    sector.circle(radius, extent=90)
    sector.seth(270)
    sector.fd(radius)
    sector.seth(0)

    radius += delta_d

done()

截图:

 

task6

源码:

from turtle import *
from random import random
strip = Turtle()
setup(800, 600)
strip.speed(0)
# 获取颜色


def colors():
    return tuple(random() for _ in range(3))


strip.pendown()
for i in range(10):
    strip.color(colors())
    strip.begin_fill()
    for _ in range(2):
        strip.fd(20)
        strip.left(90)
        strip.fd(60)
        strip.left(90)
    strip.fd(20)
    strip.end_fill()

strip.penup()
strip.goto(0, 0)
strip.pendown()

for i in range(10):
    strip.color(colors())
    strip.begin_fill()
    strip.seth(180)
    for _ in range(2):
        strip.fd(20)
        strip.right(90)
        strip.fd(60)
        strip.right(90)
    strip.fd(20)
    strip.end_fill()
strip.hideturtle()
done()

截图:

 实验总结:

 

 

标签:sector,fd,range,radius,strip,实验,def
From: https://www.cnblogs.com/minkongchan/p/17464462.html

相关文章

  • 实验六 turtle绘图与Python库应用编程体验
    试验任务一实验源码 task1fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinrange(n):......
  • 实验七 面向对象编程与内置模块
    实验任务一实验源码 classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'''构造新账户'''self._name=nameself._card_no=accoun......
  • 实验6
    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')move(-200,0)......
  • 恒电流间歇滴定法(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&#......