首页 > 其他分享 >实验6

实验6

时间:2023-06-08 13:56:52浏览次数:37  
标签:moveto 实验 import circle main def fill

实验任务1

task1

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

task2

源代码:

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

实验任务2

task1

from turtle import *
def moveto(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

源代码:

from turtle import *
from random import random
def moveto(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

task1

源代码:

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

task2

源代码:

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

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

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

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

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,实验,import,circle,main,def,fill
From: https://www.cnblogs.com/ning089/p/17466248.html

相关文章

  • 实验6
    实验6task1_1.pyfromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''foriinrange(n):......
  • SDN实验指导书目录
    Mininet入门与实战1.1Mininet源码安装与验证1.2Mininet拓扑构建与命令使用1.3Mininet调用API扩展自定义拓扑1.4Mininet可视化构建网络拓扑1.5Mininet流表应用实战1——手动添加流表1.6Mininet流表应用实战2——控制器下发流表协议分析1.7Mininet多数据中心网络拓扑流量......
  • 1.7Mininet多数据中心网络拓扑流量带宽实验
    Mininet多数据中心网络拓扑流量带宽实验实验目的1、掌握多数据中心网络拓扑的构建。2、熟悉网络性能测试工具Iperf,根据实验测试SDN网络的性能。实验环境Mininet多数据中心网络拓扑流量带宽实验的拓扑如下图所示。设备名称软件环境硬件环境主机Ubuntu14.04桌面......
  • 实验6
    5:1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()789move(-100,0)10begin_fill()11foriinrange(4):12fd(200)13left(90)14end_fill()1516move(0,0)17begin_fill()18pencolor(......
  • 实验二 最速下降法程序设计
    一、实验目的通过最速下降法的程序设计,为今后的约束优化方法的学习和编程奠定基础;掌握负梯度方向的定义和最速下降法的迭代公式;通过此次实验,进一步巩固最速下降法的基本原理和思想。二、实验内容(1)求解无约束优化问题:(2)终止准则取;(3)完成最速下降法(负梯度法)的MATLAB编程、调试;(4)......
  • 实验6
    task1_1源码:fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinrange(n):......
  • 实验六 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、确定测试目的和参数:在进行恒电流间歇滴定测试之......