最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python繪制三種不同的中國結(jié)

 更新時(shí)間:2023年01月09日 15:01:41   作者:kaKA-小圓  
馬上就要迎來新年了,就繪制了幾個(gè)中國結(jié),嘿嘿!本文為大家整理了三個(gè)繪制中國結(jié)的方法,文中的示例代碼講解詳細(xì),快跟隨小編一起動手嘗試一下吧

前言

今天就來分享幾個(gè)用python繪制的圖案吧

馬上就要迎來新年了 就繪制了幾個(gè)中國結(jié),嘿嘿

話不多說,直接展示一下代碼和效果圖吧

示例一

效果圖

代碼展示

import turtle
turtle.screensize(600,800)
turtle.pensize(10)
turtle.pencolor("red")
turtle.seth(-45)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(92)
turtle.circle(-6,270)
turtle.fd(92)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(102)
turtle.circle(6,180)
turtle.fd(102)
turtle.circle(-6,180)
turtle.fd(88)
turtle.fd(20)
turtle.seth(135)
turtle.fd(20)
turtle.seth(225)
turtle.fd(20)
turtle.seth(315)
turtle.fd(20)
turtle.seth(45)
turtle.fd(20)
turtle.seth(135)
turtle.begin_fill()
turtle.fillcolor("red")
turtle.fd(50)
turtle.seth(45)
turtle.fd(30)
turtle.seth(-45)
turtle.fd(30)
turtle.seth(225)
turtle.fd(30)
turtle.end_fill()
turtle.seth(90)
turtle.fd(40)
turtle.pensize(20)
turtle.fd(10)
turtle.pensize(5)
turtle.seth(105)
turtle.fd(30)
turtle.circle(-8,240)
turtle.circle(20,20)
turtle.fd(5)
turtle.circle(20,60)
turtle.fd(25)
turtle.penup()
turtle.setx(0)
turtle.sety(0)
turtle.goto(2,-127)
turtle.pendown()
turtle.pensize(5)
turtle.begin_fill()
turtle.fillcolor("red")
turtle.seth(0)
turtle.fd(15)
turtle.seth(-90)
turtle.fd(10)
turtle.seth(180)
turtle.fd(15)
turtle.seth(90)
turtle.fd(10)
turtle.seth(0)
turtle.fd(15)
turtle.end_fill()
turtle.pensize(2)
for x in range(6):
     turtle.seth(-90)
     turtle.fd(50)
     turtle.penup()
     turtle.seth(90)
     turtle.fd(50)
     turtle.seth(180)
     turtle.fd(3)
     turtle.pendown()
???????
turtle.done()

示例二

效果圖

如圖所示 在代碼里找到文字所在的地方,自己進(jìn)行一下編輯,是可以加自己想加的話進(jìn)去的

代碼展示

import turtle as t
def goto(x,y):
    t.penup()
    t.goto(x,y)
    t.pendown()
    
def init():
    t.setup(800,800)
    t.pensize(10)
    t.pencolor("red")
    t.speed(14)
    
def jiexin():
    m,n=0,200
    for i in range(11):
        goto(m,n)
        t.seth(-45)
        t.fd(200)
        m-=20/pow(2,0.5)
        n-=20/pow(2,0.5)
        
    m,n=0,200
    for j in range(11):
        goto(m,n)
        t.seth(-135)
        t.fd(200)
        m+=20/pow(2,0.5)
        n-=20/pow(2,0.5)
        
def jiexiaoban():
    m=-20/pow(2,0.5)
    n=200-20/pow(2,0.5)
    for k in range(4):
        goto(m,n)
        t.seth(135)
        t.fd(20)
        t.circle(10,180)
        t.fd(20)
        m-=40/pow(2,0.5)
        n-=40/pow(2,0.5)
        
    m=20/pow(2,0.5)
    n=200-20/pow(2,0.5)
    for k in range(4):
        goto(m,n)
        t.seth(45)
        t.fd(20)
        t.circle(-10,180)
        t.fd(20)
        m+=40/pow(2,0.5)
        n-=40/pow(2,0.5)
 
    m=20/pow(2,0.5)
    n=200-200*pow(2,0.5)+20/pow(2,0.5)
    for k in range(4):
        goto(m,n)
        t.seth(-45)
        t.fd(20)
        t.circle(10,180)
        t.fd(20)
        m+=40/pow(2,0.5)
        n+=40/pow(2,0.5)
        
    m=-20/pow(2,0.5)
    n=200-200*pow(2,0.5)+20/pow(2,0.5)
    for k in range(4):
        goto(m,n)
        t.seth(-135)
        t.fd(20)
        t.circle(-10,180)
        t.fd(20)
        m-=40/pow(2,0.5)
        n+=40/pow(2,0.5)
        
def waiyuan():
    goto(90*pow(2,0.5),200-110*pow(2,0.5))
    t.seth(-45)
    t.circle(20,270)
    
    goto(-90*pow(2,0.5),200-110*pow(2,0.5))
    t.seth(-135)
    t.circle(-20,270)
    
    goto(80*pow(2,0.5),200-120*pow(2,0.5))
    t.seth(-45)
    t.circle(40,270)
    
    goto(-80*pow(2,0.5),200-120*pow(2,0.5))
    t.seth(-135)
    t.circle(-40,270)
 
def shengzi():
    goto(0,200)
    t.pensize(20)
    t.seth(90)
    t.fd(60)
    goto(0,320)
    t.pensize(12)
    t.seth(180)
    t.circle(30,360)
         
def hanzi():
    goto(-150,325)
    t.write("Python",font=("Arial",40,"normal"))
    
def main():
    init()
    jiexin()
    jiexiaoban()
    waiyuan()
    shengzi()
    hanzi()
    t.hideturtle()
    t.done()
main()

示例三

效果圖

這個(gè)其實(shí)跟第二個(gè)差不多 就是沒有上面那行字體

代碼展示

import turtle as t
from math import sqrt


class chineseKnot:

    def __init__(self) -> None:
        # 畫筆初始化
        self.t = t
        self.t.pensize(10)
        self.t.setup(700, 700)
        self.t.pencolor("red")
        self.t.speed(14)
        # 結(jié)心坐標(biāo)
        self.x = 0
        self.y = 200


    def drawKnot(self) -> None:
        self.drawBody()
        self.drawEdge()
        self.drawAdorn()
        self.t.hideturtle()
        self.t.done()


    def drawBody(self) -> None:
        for i in range(11):
            self.__goto(self.x - i * 10 * sqrt(2), self.y - i * 10 * sqrt(2))
            self.t.seth(-45)
            self.t.fd(200)
            self.__goto(self.x + i * 10 * sqrt(2), self.y - i * 10 * sqrt(2))
            self.t.seth(-135)
            self.t.fd(200)

    def drawEdge(self) -> None:
        for i in range(4):
            # 左上角
            self.__goto(-10 * sqrt(2) - i * 20 * sqrt(2),
                        200 - 10 * sqrt(2) - i * 20 * sqrt(2))
            self.t.seth(135)
            self.t.fd(20)
            self.t.circle(10, 180)
            self.t.fd(20)

            # 右上角
            self.__goto(10 * sqrt(2) + i * 20 * sqrt(2),
                        200 - 10 * sqrt(2) - i * 20 * sqrt(2))
            self.t.seth(45)
            self.t.fd(20)
            self.t.circle(-10, 180)
            self.t.fd(20)

            # 左下角
            self.__goto(-10 * sqrt(2) - i * 20 * sqrt(2),
                        200 - 190 * sqrt(2) + i * 20 * sqrt(2))
            self.t.seth(-135)
            self.t.fd(20)
            self.t.circle(-10, 180)
            self.t.fd(20)

            # 右下角
            self.__goto(10 * sqrt(2) + i * 20 * sqrt(2),
                        200 - 190 * sqrt(2) + i * 20 * sqrt(2))
            self.t.seth(-45)
            self.t.fd(20)
            self.t.circle(10, 180)
            self.t.fd(20)

        # 左側(cè)
        self.t.seth(-45)
        self.__goto(90 * sqrt(2), 200 - 110 * sqrt(2))
        self.t.circle(20, 270)
        self.__goto(-90 * sqrt(2), 200 - 110 * sqrt(2))
        self.t.circle(-20, 270)

        # 右側(cè)
        self.__goto(80 * sqrt(2), 200 - 120 * sqrt(2))
        self.t.circle(40, 270)
        self.__goto(-80 * sqrt(2), 200 - 120 * sqrt(2))
        self.t.circle(-40, 270)

    def drawAdorn(self):
        # 上側(cè)
        self.__goto(self.x, self.y)
        self.t.pensize(14)
        self.t.seth(90)
        self.t.fd(60)
        self.__goto(0, 320)
        self.t.seth(180)
        self.t.circle(30, 360)


    def __goto(self, x: int, y: int) -> None:
        self.t.penup()
        self.t.goto(x, y)
        self.t.pendown()


if __name__ == '__main__':
    knot = chineseKnot()
    knot.drawKnot()

到此這篇關(guān)于基于Python繪制三種不同的中國結(jié)的文章就介紹到這了,更多相關(guān)Python繪制中國結(jié)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python中動態(tài)創(chuàng)建類實(shí)例的方法

    Python中動態(tài)創(chuàng)建類實(shí)例的方法

    在Java中我們可以通過反射來根據(jù)類名創(chuàng)建類實(shí)例,那么在Python我們怎么實(shí)現(xiàn)類似功能呢?其實(shí)在Python有一個(gè)builtin函數(shù)import,我們可以使用這個(gè)函數(shù)來在運(yùn)行時(shí)動態(tài)加載一些模塊
    2017-03-03
  • 使用Python快速打開一個(gè)百萬行級別的超大Excel文件的方法

    使用Python快速打開一個(gè)百萬行級別的超大Excel文件的方法

    這篇文章主要介紹了使用Python快速打開一個(gè)百萬行級別的超大Excel文件的方法,本文通過實(shí)例代碼給大家介紹的非常想詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • Python if語句知識點(diǎn)用法總結(jié)

    Python if語句知識點(diǎn)用法總結(jié)

    本篇文章給python初學(xué)者總結(jié)了關(guān)于Python之if語句的相關(guān)用法以及知識點(diǎn)總結(jié),跟著學(xué)習(xí)下吧。
    2018-06-06
  • django echarts餅圖數(shù)據(jù)動態(tài)加載的實(shí)例

    django echarts餅圖數(shù)據(jù)動態(tài)加載的實(shí)例

    今天小編就為大家分享一篇django echarts餅圖數(shù)據(jù)動態(tài)加載的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Python 使用 environs 庫定義環(huán)境變量的方法

    Python 使用 environs 庫定義環(huán)境變量的方法

    這篇文章主要介紹了Python 使用 environs 庫來更好地定義環(huán)境變量,本節(jié)我們以 Python 項(xiàng)目為例,說說環(huán)境變量的設(shè)置。通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Python3.9 beta2版本發(fā)布了,看看這7個(gè)新的PEP都是什么

    Python3.9 beta2版本發(fā)布了,看看這7個(gè)新的PEP都是什么

    這篇文章主要介紹了Python3.9 beta2版本發(fā)布了,看看這7個(gè)新的PEP都是什么,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2020-06-06
  • Python爬蟲之requests庫基本介紹

    Python爬蟲之requests庫基本介紹

    大家好,本篇文章主要講的是Python爬蟲之requests庫基本介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • Python 2與Python 3版本和編碼的對比

    Python 2與Python 3版本和編碼的對比

    這篇文章主要介紹了Python 2與Python 3版本和編碼的對比,文中介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • Python調(diào)用.NET庫的方法步驟

    Python調(diào)用.NET庫的方法步驟

    這篇文章主要介紹了Python調(diào)用.NET庫的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Python?實(shí)現(xiàn)驅(qū)動AI機(jī)器人

    Python?實(shí)現(xiàn)驅(qū)動AI機(jī)器人

    這篇文章主要介紹了Python?實(shí)現(xiàn)驅(qū)動AI機(jī)器人,下文圍繞利用Python?實(shí)現(xiàn)驅(qū)動AI機(jī)器人的相關(guān)資料展開內(nèi)容,需要的小伙伴可以參考一下
    2022-02-02

最新評論

平山县| 海南省| 盐源县| 大同市| 松江区| 宁蒗| 东至县| 长沙县| 兰州市| 南川市| 鄢陵县| 牙克石市| 无锡市| 康定县| 桂阳县| 射阳县| 黑龙江省| 杂多县| 西充县| 滦南县| 兖州市| 县级市| 焦作市| 固阳县| 安庆市| 渝北区| 衡阳县| 大足县| 东港市| 鄂托克前旗| 济南市| 甘肃省| 合阳县| 石棉县| 乳山市| 庆安县| 新巴尔虎左旗| 林甸县| 云霄县| 古丈县| 吉林市|