10个Python绘画表白代码【内附源码,再不收藏你只能单身了】

发现一些很好玩的画图小项目,今天分享给大家,教你怎样用Python画一朵玫瑰花、时钟、爱心、太阳花、月饼、进阶自定义爱心、小猪佩奇、星空、超梦幻的蓝色背景樱花等大家快来学习吧。

运行工具:

pycharm 、python

玫瑰花

from turtle import *import timesetup(1000,800,0,0)speed(0)penup()seth(90)fd(340)seth(0)pendown()speed(5)begin_fill()fillcolor('red')circle(50,30)for i in range(10):    fd(1)    left(10)circle(40,40)for i in range(6):    fd(1)    left(3)circle(80,40)for i in range(20):    fd(0.5)    left(5)circle(80,45)for i in range(10):    fd(2)    left(1)circle(80,25)for i in range(20):    fd(1)    left(4)circle(50,50)time.sleep(0.1)circle(120,55)speed(0)seth(-90)fd(70)right(150)fd(20)left(140)circle(140,90)left(30)circle(160,100)left(130)fd(25)penup()right(150)circle(40,80)pendown()left(115)fd(60)penup()left(180)fd(60)pendown()end_fill()right(120)circle(-50,50)circle(-20,90)speed(1)fd(75)speed(0)circle(90,110)penup()left(162)fd(185)left(170)pendown()circle(200,10)circle(100,40)circle(-52,115)left(20)circle(100,20)circle(300,20)speed(1)fd(250)penup()speed(0)left(180)fd(250)circle(-300,7)right(80)circle(200,5)pendown()left(60)begin_fill()fillcolor('green')circle(-80,100)right(90)fd(10)left(20)circle(-63,127)end_fill()penup()left(50)fd(20)left(180)pendown()circle(200,25)penup()right(150)fd(180)right(40)pendown()begin_fill()fillcolor('green')circle(-100,80)right(150)fd(10)left(60)circle(-80,98)end_fill()penup()left(60)fd(13)left(180)pendown()speed(1)circle(-200,23)exitonclick()

实时时钟

# coding=utf-8 import turtlefrom datetime import * # 抬起画笔,向前运动一段距离放下def Skip(step):    turtle.penup()    turtle.forward(step)    turtle.pendown() def mkHand(name, length):    # 注册Turtle形状,建立表针Turtle    turtle.reset()    Skip(-length * 0.1)    # 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。    turtle.begin_poly()    turtle.forward(length * 1.1)    # 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。    turtle.end_poly()    # 返回最后记录的多边形。    handForm = turtle.get_poly()    turtle.register_shape(name, handForm) def Init():    global secHand, minHand, hurHand, printer    # 重置Turtle指向北    turtle.mode("logo")    # 建立三个表针Turtle并初始化    mkHand("secHand", 135)    mkHand("minHand", 125)    mkHand("hurHand", 90)    secHand = turtle.Turtle()    secHand.shape("secHand")    minHand = turtle.Turtle()    minHand.shape("minHand")    hurHand = turtle.Turtle()    hurHand.shape("hurHand")       for hand in secHand, minHand, hurHand:        hand.shapesize(1, 1, 3)        hand.speed(0)       # 建立输出文字Turtle    printer = turtle.Turtle()    # 隐藏画笔的turtle形状    printer.hideturtle()    printer.penup()    def SetupClock(radius):    # 建立表的外框    turtle.reset()    turtle.pensize(7)    for i in range(60):        Skip(radius)        if i % 5 == 0:            turtle.forward(20)            Skip(-radius - 20)                       Skip(radius + 20)            if i == 0:                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))            elif i == 30:                Skip(25)                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))                Skip(-25)            elif (i == 25 or i == 35):                Skip(20)                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))                Skip(-20)            else:                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))            Skip(-radius - 20)        else:            turtle.dot(5)            Skip(-radius)        turtle.right(6)        def Week(t):       week = ["星期一", "星期二", "星期三",            "星期四", "星期五", "星期六", "星期日"]    return week[t.weekday()] def Date(t):    y = t.year    m = t.month    d = t.day    return "%s %d%d" % (y, m, d) def Tick():    # 绘制表针的动态显示    t = datetime.today()    second = t.second + t.microsecond * 0.000001    minute = t.minute + second / 60.0    hour = t.hour + minute / 60.0    secHand.setheading(6 * second)    minHand.setheading(6 * minute)    hurHand.setheading(30 * hour)        turtle.tracer(False)     printer.forward(65)    printer.write(Week(t), align="center",                  font=("Courier", 14, "bold"))    printer.back(130)    printer.write(Date(t), align="center",                  font=("Courier", 14, "bold"))    printer.home()    turtle.tracer(True)     # 100ms后继续调用tick    turtle.ontimer(Tick, 100) def main():    # 打开/关闭龟动画,并为更新图纸设置延迟。    turtle.tracer(False)    Init()    SetupClock(160)    turtle.tracer(True)    Tick()    turtle.mainloop() if __name__ == "__main__":    main()

表白爱心

import turtleimport mathturtle.pen()t=turtlet.up()t.goto(0,150)t.down()t.color('red')t.begin_fill()t.fillcolor('red')t.speed(1)t.left(45)t.forward(150)t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(250+math.sqrt(2)*100)t.right (90)t.speed(2)t.forward(250+100*math.sqrt(2))t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(150)t.end_fill()t.goto(-10,0)t.pencolor('white')#Lt.pensize(10)t.goto(-50,0)t.goto(-50,80)t.up ()#It.goto(-100,0)t.down()t.goto(-160,0)t.goto(-130,0)t.goto(-130,80)t.goto(-160,80)t.goto(-100,80)t.up()#Ot.goto(10,25)t.down()t.right(45)t.circle(25,extent=180)t.goto(60,55)t.circle(25,extent=180)t.goto(10,25)t.up()t.goto(75,80)t.down()t.goto(100,0)t.goto(125,80)t.up()t.goto(180,80)t.down()t.goto(140,80)t.goto(140,0)t.goto(180,0)t.up()t.goto(180,40)t.down()t.goto(140,40)#Ut.up()t.goto(-40,-30)t.down()t.goto(-40,-80)t.circle(40,extent=180)t.goto(40,-30)t.hideturtle()

小猪佩奇

# coding:utf-8import timeimport turtle as tt.pensize(4)t.colormode(255)t.color((255,155,192),"pink")t.setup(840,500)t.speed(10)t.pu()t.goto(-100,100)t.pd()t.seth(-30)t.begin_fill()a=0.4for 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.pd()t.seth(-30)a=0.4for 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()t.seth(90)t.fd(40)t.seth(0)t.fd(90)t.pd()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(60,20)t.circle(10,230)t.circle(60,30)

多角形太阳花

# coding=utf-8import turtleimport time # 同时设置pencolor=color1, fillcolor=color2turtle.color("red", "yellow") turtle.begin_fill()for _ in range(50):    turtle.forward(200)    turtle.left(170)turtle.end_fill() turtle.mainloop()

进阶自定义表白爱心

模拟3D星空

超梦幻的蓝色背景樱花

花儿

表白爱心树

其他

其他源码领取可关注我的公众号:白又白学Python

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,830评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,992评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,875评论 0 331
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,837评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,734评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,091评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,550评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,217评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,368评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,298评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,350评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,027评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,623评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,706评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,940评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,349评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,936评论 2 341

推荐阅读更多精彩内容

  • 表白情话最暖心一段话: 1、我很想要过这样一个温暖的冬天,有一场踩起来嘎吱嘎吱的大雪,有路灯下昏黄得模糊的暖光,有...
    岩颜_b9ae阅读 10,083评论 0 1
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,518评论 28 53
  • 首先介绍下自己的背景: 我11年左右入市到现在,也差不多有4年时间,看过一些关于股票投资的书籍,对于巴菲特等股神的...
    瞎投资阅读 5,634评论 3 8
  • ![Flask](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAW...
    极客学院Wiki阅读 7,226评论 0 3
  • 不知不觉易趣客已经在路上走了快一年了,感觉也该让更多朋友认识知道易趣客,所以就谢了这篇简介,已做创业记事。 易趣客...
    Physher阅读 3,401评论 1 2