设为首页 加入收藏

TOP

Python 画个小猪佩奇(一)
2018-07-31 09:12:39 】 浏览:282
Tags:Python

不知道大家小时候有没有学习过logo语言,就是操纵一只小王八,来画各种图案。博主小学微机课就学习了这个,最近发现Python的turtle包就是logo语言,所以画个小猪佩奇和大家分享。


代码来自知乎,但是源码中没有缩进,博主debug之后,将可直接运行的代码发在文中。


#!/usr/bin/python
# -*- coding: utf-8 -*-


import turtle as t


def nose(x,y):#鼻子
    t.pu()
    t.goto(x,y)
    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) #向左转3度
            t.fd(a) #向前走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()


def head(x,y):#头
    t.color((255,155,192),"pink")
    t.pu()
    t.goto(x,y)
    t.seth(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.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) #向左转3度
            t.fd(a) #向前走a的步长
        else:
            a=a-0.08
            t.lt(3)
            t.fd(a)
            t.end_fill()


def ears(x,y): #耳朵
    t.color((255,155,192),"pink")
    t.pu()
    t.goto(x,y)
    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()


def eyes(x,y):#眼睛
    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.e

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python通过getopt模块获取执行命.. 下一篇Java内存区域的划分和异常

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目