首页 > 其他分享 >实验六

实验六

时间:2023-06-12 15:26:20浏览次数:31  
标签:range 实验 import 90 main def left

task1

 1 from turtle import *
 2 def move(x, y):
 3 
 4     penup()
 5     goto(x, y)
 6     pendown()
 7 def draw(n, size = 100):
 8 
 9     for i in range(n):
10         fd(size)
11         left(360/n)
12 def main():
13     pensize(2)
14     pencolor('red')
15     move(-200, 0)
16     draw(3)
17     move(0, 0)
18     draw(4)
19     move(200, 0)
20     draw(5)
21     hideturtle()
22     done()
23 main()

 

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个同心圆'''
 2 from turtle import *
 3 def moveto(x, y):
 4     penup()
 5     goto(x, y)
 6     pendown()
 7 def main():
 8     setup(800, 600)
 9     radius = 20 # 圆初始半径
10     offset = 20 # 同心圆每次位移量
11     for i in range(9):
12         moveto(0, -radius)
13         circle(radius)
14         radius += offset
15         hideturtle()
16     done()
17 main()

 

 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         begin_fill()
20         circle(radius)
21         end_fill()
22         radius -= offset
23     hideturtle()
24     done()
25 main()

 task3

 1 from turtle import *
 2 def square(size = 50, rgb = 'pink'):
 3     '''绘制正方形
 4     :para: size:int 指定边长 (如未指定参数,使用默认值)
 5     :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值)
 6     '''
 7     pencolor(rgb)
 8     for i in range(4):
 9         fd(size)
10         left(90)
11 def main():
12     setup(800, 600)
13     speed(0)
14     n = 3
15     for i in range(n):
16         square(80)
17         left(360/n)
18     hideturtle()
19     done()
20 main()

 

 1 from turtle import *
 2 setup(800, 600)
 3 pencolor('pink')
 4 n = 4
 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()

 task4

 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 = 4 # 螺旋n边形
 9 count = 50 # 循环次数
10 for i in range(count):
11     fd(size)
12     angle += 360/n + 1
13     seth(angle)
14     size += 5
15 hideturtle()
16 done()

task5

from turtle import *

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

def draw():
    for i in range(4):
            fd(200)
            left(90)

def main():
    move(-100,-100)
    color('black')
    begin_fill()
    draw()
    end_fill()

    move(0,-100)
    color('red')
    begin_fill()
    circle(100,steps = 4)
    end_fill()
    hideturtle()
    done()

main()

 

from turtle import*

def move(x,y):
    '''画笔移动到坐标(x,y)处'''
    penup()
    goto(x,y)
    pendown()

pensize(2)
pencolor('Blue')
n = 5
left(-90)

for i in range(n):
    left(90)
    move(0,0)
    fd(40+20*i)
    left(90)
    circle(40+20*i,90)
    left(90)
    fd(40+20*i)

hideturtle()
done()

 

from turtle import *
from random import random

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

def gen_color():
    return tuple(random() for i in range(3))
def rect(a,b,c):
    color(c)
    fd(a)
    left(90)
    fd(b)
    left(90)
    fd(a)
    left(90)
    fd(b)

setup(800,600)
move(-100,0)
for i in range(20):
    c = gen_color()
    begin_fill()
    rect(10,30,c)
    end_fill()
    left(90)
    fd(10)

hideturtle()
done()

 

 

 

标签:range,实验,import,90,main,def,left
From: https://www.cnblogs.com/dughy/p/17458304.html

相关文章

  • 实验六
    task1-1fromturtleimport*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)d......
  • 实验6
    实验任务1task1_1.py1fromturtleimport*2defmove(x,y):3'''画笔移动到坐标(x,y)处'''4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9'''绘制边长为size的正n变形''&#......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''foriinrange(n):fd(siz......
  • Linux操作系统实训操作五(实验效果)
    Linux操作系统实训操作五(实验效果)原创 宇翔2020 网路小栈 2023-04-1007:00 发表于山东收录于合集#Linux操作系统2个#CentOS4个 1、新建用户jyzy(计应专业)、dmzy(动漫专业)、shzy(书画专业)、hkzy(航空专业),用tail命令查看/etc/passwd文件的后四行内容。(截图)。 ......
  • 实验六
    实验任务1task1.1实验源码1fromturtleimport*2defmove(x,y):3penup()4goto(x,y)5pendown()6defdraw(n,size=100):7foriinrange(n):8fd(size)9left(360/n)10defmain():11pensize(2)12p......
  • php文件上传之白名单00截断实验
    %00截断介绍:0x00,%00,/00在url中%00表示ascll码中的0,而ascii中0作为特殊字符保留,表示字符串结束,所以当url中出现%00时就会认为读取已结束。但是所谓的if拦截仍会读取后面的后缀达到绕过白名单的效果。当前版本环境:PHP版本低于5.4.24,或者PHP版本在5.5.8到5.6.0之间,且GPC......
  • 实验六
    实验任务一task1_1实验源码:1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()7defdraw(n,size=100):#绘制边长为size的正n边形8foriinrange(n):9fd(size)10left(360/n)11defmain():12......
  • Python实验课6
    实验任务一实验源码: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)......
  • 实验六
    实验1task1.1实验源码1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验七
    任务一实验源码1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._c......