㈠ python怎么画月牙
用python画月亮的代码是:
_mport turtle as t t.screensize(800,600,"#483d8b")#画布尺寸和颜色t.up() #抬起笔t.goto(-100,64)#把笔移到坐标的位置t.pd()
?#放下笔t.fillcolor('#ffd700') #填充色t.begin_fill() #开始填充(一定要在画你想画的图案之前)t.pencolor('#ffd700')#画笔颜色
_.pensize(3)#画笔尺寸t.circle(18)#圆的半径11.t.end_fill()#结束填充(在画完之后)
?
_.up()t.goto(-110,60)t.pd()15.t.pencolor('#ff0000')16.t.pensize(10)t.fd(20)t.up()t.goto(-120,60)t.pd()t.pencolor('#ff0000')t.pensize(10)t.
_eth(-40) #画笔移动方向24.for i in range(3):t.circle(40, 80)t.circle(-40, 80)t.circle(40, 80/2)t.up()t.goto(-100,34)t.pd()
?
_.pensize(55)t.pencolor('#adff2f')t.seth(-90)t.fd(36)t.seth(7)t.pensize(8)t.pencolor("yellow")t.fillcolor('yellow')t.speed(15)#速度
?
㈡ 用python画鸽子代码
我在逛Quora的时候发现这么一个问题:
What is the most beautiful program you ever coded in Python?
有网友分享了自己用turtle或者pylab画出来的酷炫图形。
前两个是用turtle画的动态图(简书可以传动图吗?),第三个是用pylab画的静态图,原来用pylab也能画出这么多彩的图形。
<code>
from turtle import*
from time import sleep
title("fanatic")
bgcolor("white")
speed(0)
ht()
pu()
goto(-400,0)
pd()
tracer(False)
L=["green","yellow"]
for i in range(5,101,2):
for j in range(i):
for z in range(40):
pencolor(L[z%2])
fd(20)
rt(180-180/i)
tracer(True)
sleep(0.03)
tracer(False)
clear()
'''
㈢ 怎么用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')
两三年没碰海龟了,觉得没啥用,看你赏金又提了就回去学了学
㈣ python代码画樱花是什么
Python代码画樱花具体指的就是在Python相关的一些编程软件和一些相关的配置环境里面就能够利用相关的一些代码。
然后去生成一个后缀为.py的文件,然后就够以这个文件在相关的运行环境里面去运行一些效果就是运行到樱花飘落的这样子的一个效果图,还有一些就是动态图等等。
在相关的一些代码的编辑软件里面,最主要就是要根据一些语法去创立一些能够进行编译的代码,然后就能够把它进行保存,然后去运行出对应的一个效果图。并且像这种樱花飘落的场景的话,主要就是以动态效果图去进行呈现的。
所以说学习好Python这样子的一个编程方向的话是很有利于自己去开发出不同的东西的。
㈤ Python turtle海龟制图 求代码
# coding:utf-8
import turtle as t
# 绘制小猪佩奇
# =======================================
t.pensize(4)
t.hideturtle()
t.colormode(255)
t.color((255, 155, 192), "pink")
t.setup(840, 500)
t.speed(10)
# 鼻子
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
t.begin_fill()
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # 向左转3度
t.fd(a) # 向前走a的步长
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
t.pu()
t.seth(90)
t.fd(25)
t.seth(0)
t.fd(10)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
t.pu()
t.seth(0)
t.fd(20)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
# 头
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(41)
t.seth(0)
t.fd(0)
t.pd()
t.begin_fill()
t.seth(180)
t.circle(300, -30)
t.circle(100, -60)
t.circle(80, -100)
t.circle(150, -20)
t.circle(60, -95)
t.seth(161)
t.circle(-300, 15)
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
a = 0.4
for i in range(60):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # 向左转3度
t.fd(a) # 向前走a的步长
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
# 耳朵
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(-7)
t.seth(0)
t.fd(70)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 54)
t.end_fill()
t.pu()
t.seth(90)
t.fd(-12)
t.seth(0)
t.fd(30)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 56)
t.end_fill()
# 眼睛
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-95)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-25)
t.seth(0)
t.fd(40)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
# 腮
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-95)
t.seth(0)
t.fd(65)
t.pd()
t.begin_fill()
t.circle(30)
t.end_fill()
# 嘴
t.color(239, 69, 19)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(-100)
t.pd()
t.seth(-80)
t.circle(30, 40)
t.circle(40, 80)
# 身体
t.color("red", (255, 99, 71))
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-78)
t.pd()
t.begin_fill()
t.seth(-130)
t.circle(100, 10)
t.circle(300, 30)
t.seth(0)
t.fd(230)
t.seth(90)
t.circle(300, 30)
t.circle(100, 3)
t.color((255, 155, 192), (255, 100, 100))
t.seth(-135)
t.circle(-80, 63)
t.circle(-150, 24)
t.end_fill()
# 手
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()
t.seth(-160)
t.circle(300, 15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20, 90)
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300, 15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20, 90)
# 脚
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(-75)
t.seth(0)
t.fd(-180)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(40)
t.seth(0)
t.fd(90)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
# 尾巴
t.pensize(4)
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(70)
t.seth(0)
t.fd(95)
t.pd()
t.seth(0)
t.circle(70, 20)
t.circle(10, 330)
t.circle(70, 30)
t.done()
㈥ Python语言画图
1)首先Python画图与WING IDE无关,最简单的是使用Tkinter画图
2)画出单词有很多方法,最笨的是用划线方式一笔一笔的画。其次是直接输出文本,但意义不大。另外一种方法是调用图片,你可以在图片上任意画好东西后显示出来。
3)代码示例:(这个例子就画了个简单的字母P)
from Tkinter import *
root=Tk()
root.title('Drawing Example')
canvas=Canvas(root,width=200,height=160,bg='white')
canvas.create_line(10,10,100,70)
canvas.create_line(10,10,40,10)
canvas.create_line(40,10,40,40)
canvas.create_line(10,40,40,40)
canvas.pack()
root.mainloop()
㈦ 求Python代码
fh=open(“文件名TXT”,a)
ijk运行完
fh.write(i)
fh.write(j)
fh.write(k)
fh.close()
就是打开文件,a(表示追加内容),用write函数向文件写入这些数据。
第二天再用时,打开文件,read()函数读取即可。
㈧ python有趣的编程代码
classPoint:
row=0
col=0
def__init__(self,row,col):
self.row=row
self.col=col
def(self):
returnPoint(row=self.row,col=self.col)
#初始框架
importpygame
importrandom
#初始化
pygame.init()
W=800
H=600
ROW=30
COL=40
size=(W,H)
window=pygame.display.set_mode(size)
pygame.display.set_caption('贪吃蛇')
bg_color=(255,255,255)
snake_color=(200,200,200)
head=Point(row=int(ROW/2),col=int(COL/2))
head_color=(0,128,128)
snakes=[
Point(row=head.row,col=head.col+1),
Point(row=head.row,col=head.col+2),
Point(row=head.row,col=head.col+3)
]
#生成食物
defgen_food():
while1:
pos=Point(row=random.randint(0,ROW-1),col=random.randint(0,COL-1))
#
is_coll=False
#是否跟蛇碰上了
ifhead.row==pos.rowandhead.col==pos.col:
is_coll=True
#蛇身子
forsnakeinsnakes:
ifsnake.row==pos.rowandsnake.col==pos.col:
is_coll=True
break
ifnotis_coll:
break
returnpos
#定义坐标
food=gen_food()
food_color=(255,255,0)direct='left'#left,right,up,down
#
defrect(point,color):
cell_width=W/COL
cell_height=H/ROW
left=point.col*cell_width
top=point.row*cell_height
pygame.draw.rect(
window,color,
(left,top,cell_width,cell_height)
)
pass
#游戏循环
quit=True
clock=pygame.time.Clock()
whilequit:
#处理事件
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
quit=False
elifevent.type==pygame.KEYDOWN:
ifevent.key==273orevent.key==119:
ifdirect=='left'ordirect=='right':
direct='up'
elifevent.key==274orevent.key==115:
ifdirect=='left'ordirect=='right':
direct='down'
elifevent.key==276orevent.key==97:
ifdirect=='up'ordirect=='down':
direct='left'
elifevent.key==275orevent.key==100:
ifdirect=='up'ordirect=='down':
direct='right'
#吃东西
eat=(head.row==food.rowandhead.col==food.col)
#重新产生食物
ifeat:
food=gen_food()
#处理身子
#1.把原来的头,插入到snakes的头上
snakes.insert(0,head.())
#2.把snakes的最后一个删掉
ifnoteat:
snakes.pop()
#移动
ifdirect=='left':
head.col-=1
elifdirect=='right':
head.col+=1
elifdirect=='up':
head.row-=1
elifdirect=='down':
head.row+=1
#检测
dead=False
#1.撞墙
ifhead.col<0orhead.row<0orhead.col>=COLorhead.row>=ROW:
dead=True
#2.撞自己
forsnakeinsnakes:
ifhead.col==snake.colandhead.row==snake.row:
dead=True
break
ifdead:
print('死了')
quit=False
#渲染——画出来
#背景
pygame.draw.rect(window,bg_color,(0,0,W,H))
#蛇头
forsnakeinsnakes:
rect(snake,snake_color)
rect(head,head_color)
rect(food,food_color)
#
pygame.display.flip()
#设置帧频(速度)
clock.tick(8)
#收尾工作
这是一个简易版贪吃蛇的代码,虽然结构简单,但是该有的功能都是完整的,可玩性也不错
㈨ 求云模型评价云图的python代码,做出的图就像下面图一样的
你把单做一个的代码贴出来,我可以帮你合到一个图上。
先看结果:
Ex=[0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1]
fig = plt.figure()
for i in Ex:
res=forwardCloud(i,0.04,0.005,1000)
x=[x[0] for x in res]
y=[x[1] for x in res]
plt.scatter(x,y,color='red',s=3)
plt.show()
希望可以帮到你
㈩ 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()