海龟绘图turtle库之二级基础编程题


一、画一个太极图

import turtle as t
t.pensize(2)#设置笔画宽度
t.circle(100)#以100为半径的圆
t.circle(50, 180)
t.circle(-50, 180)
t.penup()#抬起画笔
t.goto(0, 40)#移动到绝对位置
t.pendown()#放下画笔
t.circle(10)
t.penup()
t.goto(0, 140)
t.pendown()
t.circle(10)
t.hideturtle()
#隐藏画笔 t.done()

二、画一个同心圆

import turtle as t
def drawcircle(n):
    t.pensize(3)
    t.penup()
    t.goto(0, -n)
    t.pendown()
    t.circle(n)
for i in range(20,80,20):
    drawcircle(i)
    t.hideturtle()
t.done()

三、画一个同心切

import turtle as t
for i in range(20,80,20):
    t.circle(i)

四、画一个五角星

import turtle as t
t.color('red', 'red')
t.begin_fill()
for i in range(5):
    t.fd(200)
    t.rt(144)
    t.hideturtle()
t.end_fill()
t.done()

 六、画一个花瓣

import turtle as t
t.penup()
t.goto(-40,-90)
t.pendown()
t.colormode(255)
t.screensize(800,600,'white')
t.pensize(2)
t.color((255,155,192),(144,218,253))
t.begin_fill()
for i in range(4):
    t.seth(90*(i+1))
    t.rt(45)
    t.circle(150, 90)
    t.seth(-90 + i * 90
    t.circle(150, 90)
t.end_fill()
t.done()

七、画一个菱形(要求根据题意使用适当函数)

import turtle as t
t.rt(30)
for i in range(2):
    t.color('red')
    t.fd(100)
    t.rt(-60*(i+1))
for j in range(2):
    t.fd(100)
    t.rt(-60*(j+1))
    t.hideturtle()
t.done()#使用rt函数

八、画一个多彩圆

import turtle
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']
for i in range(7):
    c = colors[i]
    turtle.color(c, c)
    turtle.begin_fill()
    turtle.lt(360/7)
    turtle.circle(50)
    turtle.end_fill()
turtle.done()

 九、后续未完...

一、佩奇(课外...)

import turtle as t
t.pensize(4) 
t.colormode(255) #取色范围
t.color((255,155,192),"pink")
t.setup(840,500) 
t.speed(3) #时速
t.pu() 
t.goto(-100,100) #绝对位置
t.pd() 
t.seth(-30) 
t.begin_fill() 
a=0.4
for i in range(120):
    if 0<=i<30 or 60<=i<90:
        a=a+0.08
        t.lt(3)
        t.fd(a)
    else:
        a=a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill() 
t.pu() 
t.seth(90) 
t.fd(25)
t.seth(0) 
t.fd(10)
t.pd()
t.pencolor(255,155,192) 
t.seth(10)
t.begin_fill()
t.circle(5) 
t.color(160,82,45) 
t.end_fill()
t.pu()
t.seth(0)
t.fd(20)
t.pd()
t.pencolor(255,155,192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160,82,45)
t.end_fill() #
t.color((255,155,192),"pink")
t.pu()
t.seth(90)
t.fd(41)
t.seth(0)
t.fd(0)
t.pd()
t.begin_fill()
t.seth(180)
t.circle(300,-30) 
t.circle(100,-60)
t.circle(80,-100)
t.circle(150,-20)
t.circle(60,-95)
t.seth(161)
t.circle(-300,15)
t.pu()
        # t.goto(-100,100)
t.goto(-100, 100)
t.pd()
t.seth(-30)
a=0.4
for i in range(60):
    if 0<=i<30 or 60<=i<90:
        a=a+0.08
        t.lt(3) 
        t.fd(a)
    else:
        a=a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill() 
t.color((255,155,192),"pink")
t.pu()
t.seth(90)
t.fd(-7)
t.seth(0)
t.fd(70)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50,50)
t.circle(-10,120)
t.circle(-50,54)
t.end_fill()
t.pu()
t.seth(90)
t.fd(-12)
t.seth(0)
t.fd(30)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50,50)
t.circle(-10,120)
t.circle(-50,56)
t.end_fill() #眼睛
t.color((255,155,192),"white")
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-95)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
t.color((255,155,192),"white")
t.pu()
t.seth(90)
t.fd(-25)
t.seth(0)
t.fd(40)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill() #
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(-95)
t.seth(0)
t.fd(65)
t.pd()
t.begin_fill()
t.circle(30)
t.end_fill() #
t.color(239,69,19)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(-100)
t.pd()
t.seth(-80)
t.circle(30,40)
t.circle(40,80) #身体
t.color("red",(255,99,71))
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-78)
t.pd()
t.begin_fill()
t.seth(-130)
t.circle(100,10)
t.circle(300,30)
t.seth(0)
t.fd(230)
t.seth(90)
t.circle(300,30)
t.circle(100,3)
t.color((255,155,192),(255,100,100))
t.seth(-135)
t.circle(-80,63)
t.circle(-150,24)
t.end_fill() #
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()
t.seth(-160)
t.circle(300,15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20,90)
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300,15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20,90) #
t.pensize(10)
t.color((240,128,128))
t.pu()
t.seth(90)
t.fd(-75)
t.seth(0)
t.fd(-180)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
t.pensize(10)
t.color((240,128,128))
t.pu()#penup提笔
t.seth(90)
t.fd(40)
t.seth(0)
t.fd(90)#=forward
t.pd()#=pendown
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20) #尾巴
t.pensize(4)
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(70)
t.seth(0)
t.fd(95)
t.pd()
t.seth(0)
t.circle(70,20)
t.circle(10,330)
t.circle(70,30)
t.hideturtle()
t.done()

猜你喜欢

转载自www.cnblogs.com/blancheiii/p/10333153.html