导航:首页 > 编程语言 > 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代码画八卦阵相关的资料

热点内容
苹果手机怎么会显示多个App 浏览:237
不去互联网程序员 浏览:550
电脑qq邮箱解压的图片保存在哪里 浏览:544
嵌入命令行 浏览:91
档案为什么被加密 浏览:486
十天学会单片机13 浏览:875
荣耀怎么设置让app一直运行 浏览:993
共享文件夹能在哪里找到 浏览:435
旅游订旅店用什么app 浏览:240
一个女程序员的声音 浏览:496
魔术app怎么用 浏览:340
单片机有4个8位的io口 浏览:897
win10rar解压缩软件 浏览:169
plc教程pdf 浏览:668
pythonshell清屏命令 浏览:281
检测到加密狗注册服务器失败 浏览:205
解压后手机如何安装 浏览:521
极客学院app为什么下架 浏览:14
图片批量压缩绿色版 浏览:656
东北程序员帅哥 浏览:709