欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

前言

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

馬上就要迎來新年了 就繪制了幾個中國結(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()

示例二

效果圖

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

代碼展示

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()

示例三

效果圖

這個其實跟第二個差不多 就是沒有上面那行字體

代碼展示

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é)心坐標
        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隊列Queue超詳細講解

    Python隊列Queue超詳細講解

    Queue是python標準庫中的線程安全的隊列(FIFO)實現(xiàn),提供了一個適用于多線程編程的先進先出的數(shù)據(jù)結(jié)構(gòu),即隊列,用來在生產(chǎn)者和消費者線程之間的信息傳遞,本文給大家講解Python隊列Queue的相關(guān)知識,需要的朋友參考下吧
    2023-04-04
  • 完美解決Python matplotlib繪圖時漢字顯示不正常的問題

    完美解決Python matplotlib繪圖時漢字顯示不正常的問題

    今天小編就為大家分享一篇完美解決Python matplotlib繪圖時漢字顯示不正常的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • Django 再談一談json序列化

    Django 再談一談json序列化

    這篇文章主要介紹了Django json序列化,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • 學習python的前途 python掙錢

    學習python的前途 python掙錢

    在本文里我們給大家整理了關(guān)于學習python的前途以及python掙錢的方法整理,有興趣的朋友們閱讀下。
    2019-02-02
  • Python爬取視頻時長場景實踐示例

    Python爬取視頻時長場景實踐示例

    這篇文章主要為大家介紹了Python獲取視頻時長場景實踐示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • Pycharm如何設(shè)置默認請求頭和切換python環(huán)境

    Pycharm如何設(shè)置默認請求頭和切換python環(huán)境

    這篇文章主要介紹了Pycharm如何設(shè)置默認請求頭和切換python環(huán)境問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • 使用Flask-Login模塊實現(xiàn)用戶身份驗證和安全性

    使用Flask-Login模塊實現(xiàn)用戶身份驗證和安全性

    當你想要在你的Flask應用中實現(xiàn)用戶身份驗證和安全性時,F(xiàn)lask-Login這個擴展將會是你的最佳伙伴,它提供了一組簡單而強大的工具來處理,下面我們就來看看具體的操作方法吧
    2023-08-08
  • Python中用字符串調(diào)用函數(shù)或方法示例代碼

    Python中用字符串調(diào)用函數(shù)或方法示例代碼

    字符串作為python中常用的數(shù)據(jù)類型,掌握字符串的常用方法十分必要。下面這篇文章主要給大家介紹了關(guān)于Python中通過字符串調(diào)用函數(shù)或方法的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • pycharm 復制代碼出現(xiàn)空格的解決方式

    pycharm 復制代碼出現(xiàn)空格的解決方式

    這篇文章主要介紹了pycharm 復制代碼出現(xiàn)空格的解決方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • pycharm2020.2 配置使用的方法詳解

    pycharm2020.2 配置使用的方法詳解

    這篇文章主要介紹了pycharm2020.2 配置使用的方法,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-09-09

最新評論