首页 > 其他分享 >实验六

实验六

时间:2023-06-11 22:22:16浏览次数:28  
标签:moveto range 实验 import 源代码 def left

task1

源代码

#1.1
from turtle import * def moveto(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') moveto(-200,0) draw(3) moveto(0,0) draw(4) moveto(200,0) draw(5) hideturtle() done() main()

  运行结果截图

源代码:

#1.2
# 运用circle函数,实现正多边形绘制
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

源代码

#2.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()

  运行结果截图

源代码:

#2.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 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()

  运行结果截图

task3

源代码

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

  运行结果截图

源代码

#3.2
from turtle import *

setup(800,600)
pencolor('pink')

n = 10
for i in range(n+1):
    #绘制一片花瓣
    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

源代码

#5.1
# 先画外围正方形
from turtle import *

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

color('black')
begin_fill()
moveto(-100,-100)
for i in range(4):
    fd(200)
    left(90)
end_fill()

# 再画内三角形
color('red')

begin_fill()
moveto(0,-100)
left(45)
for i in range(4):
    fd(100*2**(1/2))
    left(90)
end_fill()
hideturtle()
done()

  运行结果截图

源代码

#5.2
from turtle import *

setup(400, 400)
pencolor('blue')
pensize(2)
speed(0)


def func(n, r):
    for i in range(n):
        fd(r)
        left(90)
        circle(r, 90)
        left(90)
        fd(r)
        left(90)
        r += 20


func(5, 40)
hideturtle()
done()

  运行结果截图

task6

源代码

#选做2
from turtle import *
screensize(100,100,'black')

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

# 画脸
color('yellow')
begin_fill()
left(45)
fd(100)
left(90)
circle(100,270)
left(90)
fd(100)
end_fill()

# 画眼睛
moveto(10,65)
dot(15,'black')

# 画高光
moveto(8,70)
dot(8,'white')

hideturtle()
done()

  运行结果截图

 

标签:moveto,range,实验,import,源代码,def,left
From: https://www.cnblogs.com/wybpyx/p/17473745.html

相关文章

  • 实验七
    任务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)......
  • 决策树(实验室会议小记)
    特征选择为什么要进行特征选择?特征过多导致过拟合、有一些特征是噪音。特征选择技术:1、尝试所有组合:也是全局最优2、贪心算法:每次决策都是基于当前情况去寻找最优解。计算过程:把特征加进去→是否更优?→是:加入模型/否:淘汰3、L1正则:目标函数为损失函数;特点:具有稀疏性4、决......
  • 实验6 turtle绘图与python库应用编程体验
    task1_1代码:fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinrange(n):......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1_1.py程序源码:1fromturtleimport*23defmove(x,y):#画笔移动到坐标(x,y)处4penup()5goto(x,y)6pendown()78defdraw(n,size=100):#绘制边长为size的正n变形9foriinrange(n):10forward(size)11......
  • 实验7
    实验1、2、3已实践实验4:代码如下#include<stdio.h>intmain(){charch;intk=0;FILE*fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("failtoopenfile\n");return1;}w......
  • 实验六 turtle绘图与python库应用编程体验
    1fromturtleimport*234defmove(x,y):5penup()6goto(x,y)7pendown()8910defdraw(n,size=100):11foriinrange(n):12fd(size)13left(360/n)141516defmain():17pensize(2)18pen......