Python 渐变色画福
本文最后更新于 740 天前,其中的信息可能已经有所发展或是发生改变。

去年寒假闲的无聊就用Python画了一个福字,写的很烂,就存个档留念吧!

不得不吐槽,这个代码识别就很迷惑了,居然连Python都不认识

import turtle as t


def penInit():
    s = 0.2  # size
    t.setup(750*5*s, 750*5*s)
    t.width(40)
    t.penup()
    t.goto(-100, 170)
    t.pendown()
    t.colormode(255)
    t.delay(0)


def colorChange(length, color1, color2, reverse):
    sr = length//(abs(color1[0]-color2[0]))
    sg = length//(abs(color1[1]-color2[1]))
    sb = length//(abs(color1[2]-color2[2]))
    cr = (abs(color1[0]-color2[0]))//length
    cg = (abs(color1[1]-color2[1]))//length
    cb = (abs(color1[2]-color2[2]))//length
    sr = sr if sr else 1
    sg = sg if sg else 1
    sb = sb if sb else 1
    cr = cr if cr else 1
    cg = cg if cg else 1
    cb = cb if cb else 1
    cr = -1*cr if reverse else cr
    cg = -1*cg if reverse else cg
    cb = -1*cb if reverse else cb
    return sr, sg, sb, cr, cg, cb


def getColor(base, sr, sg, sb, cr, cg, cb, bit):
    r = base[0]+bit//sr*cr
    g = base[1]+bit//sg*cg
    b = base[2]+bit//sb*cb
    r = r if r > -1 else 0
    r = r if r < 256 else 255
    g = g if g > -1 else 0
    g = g if g < 256 else 255
    b = b if b > -1 else 0
    b = b if b < 256 else 255
    color = (r, g, b)
    return color


def drawLine(angle, length, speed=1, reverse=False):
    t.seth(angle)
    color1 = (234, 85, 32)
    color2 = (229, 169, 107)
    sr, sg, sb, cr, cg, cb = colorChange(length, color1, color2, reverse)
    base = color2 if reverse else color1
    t.speed(speed)
    for bit in range(length):
        color = getColor(base, sr, sg, sb, cr, cg, cb, bit)
        t.pencolor(color)
        t.forward(1)


def penupMove(angle, length):
    t.penup()
    t.seth(angle)
    t.forward(length)
    t.pendown()


def drawFu():
    penInit()
    drawLine(270, 30)
    drawLine(180, 90, reverse=True)
    drawLine(0, 120)
    drawLine(315, 15, reverse=True)
    drawLine(237.5, 235)
    drawLine(180, 25, reverse=True)
    drawLine(0, 25)
    drawLine(57.5, 160, reverse=True)
    drawLine(270, 230)
    drawLine(90, 230, reverse=True)
    drawLine(292, 110)
    drawLine(317, 50, reverse=True)
    drawLine(0, 210)
    drawLine(90, 35, reverse=True)
    drawLine(135, 45)
    drawLine(180, 120, reverse=True)
    drawLine(225, 45)
    drawLine(270, 90, reverse=True)
    drawLine(315, 45)
    drawLine(0, 115, reverse=True)
    drawLine(45, 50)
    drawLine(90, 90, reverse=True)
    drawLine(135, 45)
    drawLine(180, 61, reverse=True)
    drawLine(270, 130)
    penupMove(104, 260)
    drawLine(0, 117)
    drawLine(315, 38, reverse=True)
    drawLine(270, 25)
    drawLine(225, 38, reverse=True)
    drawLine(180, 117)
    drawLine(135, 38, reverse=True)
    drawLine(90, 25)
    drawLine(45, 38, reverse=True)
    penupMove(118, 49)
    drawLine(0, 170)


if __name__ == "__main__":
    drawFu()
    penupMove(280, 440)
    t.write("by JingXin", align="right", font=(
        "Consolas-with-Yahei", 15, "bold italic"))
    t.done()

-=||=-收藏
暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇