導航:首頁 > 編程語言 > python代碼畫八卦陣

python代碼畫八卦陣

發布時間:2022-06-30 17:36:49

A. 用python怎麼編寫這兩道題

i=1

while i <= 7:

i=1

while i<=j :

print(" ", i, end = "")

i = i+1

print("")

j=j+1


輸出結果:

B. python可以畫出哪些簡單圖形

一、畫一朵花+簽名
代碼如下:
# -*- coding:utf-8 -*-
#畫一朵花+簽名
import turtle
turtle.color('red','green')
turtle.pensize(5)
turtle.goto(0,0)
turtle.speed(10)
for i in range(15):
turtle.forward(100)
turtle.right(150)
turtle.up()

turtle.goto(150,-120)
turtle.color('black')
turtle.write("xxx" )
turtle.up()

turtle.goto(160,-140)
turtle.color('black')
turtle.write("2018 年 1 月 10 日" )
turtle.up()

turtle.goto(240,-160)
turtle.color('black')
turtle.write("." )
turtle.done()

二、畫五角星臉+簽名
代碼如下:
# -*- coding:utf-8 -*-
#畫五角星臉+簽名
import turtle
turtle.color('red','green')
turtle.pensize(5)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.up()
turtle.goto(150,120)
turtle.down()
turtle.color('red','green')
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.up()
turtle.goto(-80,90)
turtle.down()
turtle.color('red','green')
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.up()
turtle.goto(150,-120)
turtle.color('black')
turtle.write("xxx" )
turtle.up()
turtle.goto(160,-140)
turtle.color('black')
turtle.write("2018 年 1 月 7 日" )
turtle.up()
turtle.goto(240,-160)
turtle.color('black')
turtle.write("." )
turtle.done()

C. python 如何繪制下面這種圖形

matplotlib可以畫,這是幫助鏈接

matplotlib Stem Plot

效果如下

D. Python 八宮格,橫豎斜相鄰數字不連續,1-8填入,要求輸出為八宮格樣式,求高手核心代碼

importitertools
defcheck(cells):
forrinrange(1,3):
forcinrange(2):
ifabs(cells[r][c]-cells[r][c+1])==1:
returnFalse
forcinrange(3):
forrinrange(3):
ifabs(cells[r][c]-cells[r+1][c])==1:
returnFalse
forrinrange(3):
forcinrange(3):
ifc!=0:
ifabs(cells[r][c]-cells[r+1][c-1])==1:
returnFalse
ifc!=2:
ifabs(cells[r][c]-cells[r+1][c+1])==1:
returnFalse
returnTrue
cells=[[-1foriinrange(3)]forjinrange(4)]
forpinitertools.permutations(range(1,9),8):
cells[0][1]=p[0]
cells[1][0]=p[1]
cells[1][1]=p[2]
cells[1][2]=p[3]
cells[2][0]=p[4]
cells[2][1]=p[5]
cells[2][2]=p[6]
cells[3][1]=p[7]
ifcheck(cells):
print(cells)

暴力O(8!)

E. 如何用Python畫各種著名數學圖案

如何用Python畫各種著名數學圖案 | 附圖+代碼

用Python繪制著名的數學圖片或動畫,展示數學中的演算法魅力。
Mandelbrot 集

'''
A fast Mandelbrot set wallpaper renderer

reddit discussion:
'''
importnumpy asnp
fromPILimportImage
fromnumba importjit

MAXITERS=200
RADIUS=100

@jit
defcolor(z, i):
v =np.log2(i +1-np.log2(np.log2(abs(z)))) /5
ifv <1.0:
returnv**4, v**2.5, v
else:
v =max(0, 2-v)
returnv, v**1.5, v**3

@jit
defiterate(c):
z =0j
fori inrange(MAXITERS):
ifz.real*z.real +z.imag*z.imag >RADIUS:
returncolor(z, i)
z =z*z +c
return0, 0,0

defmain(xmin, xmax, ymin, ymax, width, height):
x =np.linspace(xmin, xmax, width)
y =np.linspace(ymax, ymin, height)
z =x[None, :] +y[:, None]*1j
red, green, blue =np.asarray(np.frompyfunc(iterate, 1, 3)(z)).astype(np.float)
img =np.dstack((red, green, blue))
Image.fromarray(np.uint8(img*255)).save('mandelbrot.png')

if__name__=='__main__':
main(-2.1, 0.8, -1.16, 1.16, 1200, 960)

F. python如何給八邊形填色

-設定填充色:fillecolor(r, g, b)
-開始填充:begin_fill()
-結束填充:end_fill()
畫一組隨機分布,隨機大小和不同色調的心形。先初始化一個填充顏色。然後,在畫每個圖形繪制之前使用begin_fill()以及繪制之後使用end_fill()。這樣就能得到一個填充效果。

import turtle as t

import random as r

def pink():

color = (1, r.random(), 1)

return color

def randomrange(min, max):

return min + (max- min)*r.random()

def moveto(x, y):

t.penup()

t.goto(x, y)

t.pendown()

def heart(r, a):

factor = 180

t.seth(a)

t.circle(-r, factor)

t.fd(2 * r)

t.right(90)

t.fd(2 * r)

t.circle(-r, factor)

t.setup(800, 800, 200, 200)

t.speed(9)

t.pensize(1)

t.penup()

for i in range(20):

t.goto(randomrange(-300, 300), randomrange(-300, 300))

t.begin_fill()

t.fillcolor(pink())

heart(randomrange(10, 50), randomrange(0, 90))

t.end_fill()

moveto(400, -400)

t.done()

G. 怎麼用python的turtle庫畫出這個圖案,要代碼

import turtle as t


def quad(color):

t.begin_fill()

t.color(color)

t.forward(100)

t.left(36)

t.forward(100)

t.left(36*4)

t.forward(100)

t.left(36)

t.forward(100)

t.end_fill()

t.left(36*3)



for i in range(10):

if i%2:

quad('#99c8de')

else:

quad('#e5b9c4')

兩三年沒碰海龜了,覺得沒啥用,看你賞金又提了就回去學了學

H. python 語言怎麼畫八卦圖

fromturtleimport*

defyin(radius,color1,color2):
width(3)
color("black",color1)
begin_fill()
circle(radius/2.,180)
circle(radius,180)
left(180)
circle(-radius/2.,180)
end_fill()
left(90)
up()
forward(radius*0.35)
right(90)
down()
color(color1,color2)
begin_fill()
circle(radius*0.15)
end_fill()
left(90)
up()
backward(radius*0.35)
down()
left(90)

defmain():
reset()
yin(200,"black","white")
yin(200,"white","black")
ht()
return"Done!"

if__name__=='__main__':
main()
mainloop()

#這是太極圖,自行添加八卦符號吧

I. python turtle 八角形的製作

fromturtleimport*

fillcolor('pink')
begin_fill()
foriinrange(8):
forward(100)
right(45)
end_fill()

exitonclick()

假設每一條邊長長為100

畫八邊形需要在前進100後向右轉45度,重復(也就是循環)8次即可

J. Python如何運用turtle繪制陰陽太極圖

本文詳細分析如何使用Python turtle繪制陰陽太極圖,先來分解這個圖形,圖片中有四種顏色,每條曲線上的箭頭表示烏龜移動的方向,首先從中心畫一個半圓(紅線),以紅線所示圓的直徑作半徑畫一個校園,半徑為紅線所示圓半徑的0.15倍(藍線),之所以選擇0.15倍,是因為這樣嵌入紅圓內的小圓直徑和紅圓直徑接近黃金分割。

相關推薦:《Python視頻教程》

完整代碼:

效果圖如下:

閱讀全文

與python代碼畫八卦陣相關的資料

熱點內容
華為伺服器如何進陣列卡配置 瀏覽:433
apache伺服器ip地址訪問 瀏覽:716
如何買到安卓手機預裝軟體 瀏覽:535
冤罪百度雲不要壓縮 瀏覽:83
蘇州雲存儲伺服器 瀏覽:173
解壓收納原聲 瀏覽:384
java注冊驗證 瀏覽:372
火花app怎麼上推薦 瀏覽:980
什麼app能游戲投屏到電視上 瀏覽:455
伺服器託管到雲端是什麼意思 瀏覽:835
app保存草稿怎麼用 瀏覽:808
安卓如何進入proumb 瀏覽:144
主機虛擬雲伺服器 瀏覽:619
刪除分區加密的空間會不會恢復 瀏覽:706
京東app客戶上門怎麼看搜索量 瀏覽:741
怎麼在農行app購買黃金 瀏覽:46
c型開發板和單片機 瀏覽:146
虛擬機建立用戶的模板文件夾 瀏覽:904
無錫代碼編程培訓班 瀏覽:632
eps圖形數據加密 瀏覽:933