首页 > 其他分享 >实验六

实验六

时间:2023-06-12 10:22:50浏览次数:28  
标签:move pencolor range 实验 left def fill

任务1:

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

运行结果:

任务2:

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.1:

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

运行结果:

任务2.2:

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.1:

from turtle import*
def squre(size=50,rgb='pink'):
    pencolor(rgb)
    for i in range(4):
        fd(size)
        left(90)
def main():
    setup(800,600)
    speed(0)
    n=9
    for i in range(n):
        squre(80)
        left(360/n)
    hideturtle()
    done()
main()

运行结果:

任务3.2:

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:

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

运行结果:

任务5.1:

from turtle import *
def move(x,y):
    penup()
    goto(x,y)
    pendown()
move(-100,0)
begin_fill()
for i in range(4):
    fd(200)
    left(90)
end_fill()
move(0,0)
begin_fill()
pencolor('red')
fillcolor('red')
left(45)
for i in range(4):
    fd(100*2**0.5)
    left(90)
end_fill()
hideturtle()
done()

运行结果:

任务5.2:

from turtle import *
def move(x,y):
    penup()
    goto(x,y)
    pendown()
pensize(2)
pencolor('blue')
speed(0)
r = 40
move(0,-r)
for i in range(5):
    circle(r)
    r+=20
    move(0,-r)
move(-120,0)
begin_fill()
fillcolor('white')
pencolor('white')
for i in range(4):
    fd(120)
    left(90)
end_fill()
move(-120,-120)
begin_fill()
fillcolor('white')
pencolor('white')
for i in range(4):
    fd(120)
    left(90)
end_fill()
move(0,-120)
begin_fill()
fillcolor('white')
pencolor('white')
for i in range(4):
    fd(120)
    left(90)
end_fill()
pencolor('blue')
move(0,0)
fd(120)
move(0,0)
left(90)
fd(120)
hideturtle()
done()

运行结果:

任务6:

from turtle import *

setup(800,600)
speed(0)

def move(x,y):
    penup()
    goto(x,y)
    pendown()

bgcolor('black')

move(0,-100)
pencolor('yellow')
fillcolor('yellow')
begin_fill()
circle(100)
end_fill()

pencolor('black')
move(0,0)
begin_fill()
fillcolor('black')
right(45)
for i in range(4):
    fd(100)
    left(90)

move(0,50)
circle(16)
end_fill()

pencolor('white')
fillcolor('white')
begin_fill()
move(-4*2**0.5,50+4*2**0.5)
circle(4)
end_fill()

hideturtle()
done()

运行结果:

 

标签:move,pencolor,range,实验,left,def,fill
From: https://www.cnblogs.com/e2718281/p/17474183.html

相关文章

  • 实验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......
  • 实验7
    实验任务11classAccount:2#一个模拟账户类3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._card_no=account_number7self._balanc......
  • 实验6
    1.实验任务1task1_1.py1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验六
    task1源代码#1.1fromturtleimport*defmoveto(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''for......
  • 实验七
    任务4#include<stdio.h>intmain(){FILE*fp;fp=fopen("data4.txt","r");intn,c;if(fp==NULL){printf("failtoopenfile\n");return1;}while((c=fgetc(fp))!=EOF) {......
  • 实验6 turtle绘图与python库应用编程体验
    task1-1源代码1fromturtleimport*23defmove(x,y):4'''画笔移动到坐标(x,y)处'''5penup()6goto(x,y)7pendown()89defdraw(n,size=100):10'''绘制边长为size的正n变形'''1......
  • 实验六
    实验任务1task1:1fromturtleimport*23defmove(x,y):4'''画笔移动到坐标(x,y)处'''5penup()6goto(x,y)7pendown()89defdraw(n,size=100):10'''绘制边长为size的正n边形''......
  • 实验7 面向对象编程与内置模块
    实验1task1.py实验源码:classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'''构造新账户'''self._name=nameself._card_no=......
  • 实验6 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')move(-200,0)......