整点好玩的
{:10_282:}明天是小美同学的生日,在这个没有派对,没有聚会的日子里,我非常感谢我遇见了Python虽说算个辅助工具,但应该也不缺花里胡哨的东西吧{:10_282:}
发这个帖子就是想看看大佬们怎么在代码世界里面敲出好玩的东西(不知道我这个要求会不会很奇怪{:10_256:})
我先来最最幼儿园的
while True:
print('"小美,祝你生日快乐鸭"')
{:10_297:}期待大佬们的表现 import turtle as T
import random
import time
# 画樱花的躯干(60,t)
def Tree(branch, t):
time.sleep(0.0005)
if branch > 3:
if 8 <= branch <= 12:
if random.randint(0, 2) == 0:
t.color('snow')# 白
else:
t.color('lightcoral')# 淡珊瑚色
t.pensize(branch / 3)
elif branch < 8:
if random.randint(0, 1) == 0:
t.color('snow')
else:
t.color('lightcoral')# 淡珊瑚色
t.pensize(branch / 2)
else:
t.color('sienna')# 赭(zhě)色
t.pensize(branch / 10)# 6
t.forward(branch)
a = 1.5 * random.random()
t.right(20 * a)
b = 1.5 * random.random()
Tree(branch - 10 * b, t)
t.left(40 * a)
Tree(branch - 10 * b, t)
t.right(20 * a)
t.up()
t.backward(branch)
t.down()
# 掉落的花瓣
def Petal(m, t):
for i in range(m):
a = 200 - 400 * random.random()
b = 10 - 20 * random.random()
t.up()
t.forward(b)
t.left(90)
t.forward(a)
t.down()
t.color('lightcoral')# 淡珊瑚色
t.circle(1)
t.up()
t.backward(a)
t.right(90)
t.backward(b)
# 绘图区域
t = T.Turtle()
# 画布大小
w = T.Screen()
t.hideturtle()# 隐藏画笔
t.getscreen().tracer(5, 0)
w.screensize(bg='wheat')# wheat小麦
t.left(90)
t.up()
t.backward(150)
t.down()
t.color('sienna')
# 画樱花的躯干
Tree(60, t)
# 掉落的花瓣
Petal(200, t)
w.exitonclick()
原文链接:https://blog.csdn.net/weixin_43943977/article/details/102691392
去了最后一行 六小鸭 发表于 2020-3-24 11:43
去了最后一行
这貌似是我发的代码 # coding:utf-8
import turtle as t
def infoPrt():
print('coordinate: ' + str(t.pos()))
print('angle: ' + str(t.heading()))
t.pensize(3)
t.hideturtle()
t.colormode(255)
t.color("black")
t.setup(700, 650)
t.speed(10)
t.st()
#t.dot()
t.pu()
#t.goto(-150,100)
t.goto(-210,86)
t.pd()
infoPrt()
# 头
print('头')
t.seth(85)
t.circle(-100,50)
#t.seth(78)
#t.circle(-100,25)
infoPrt()
t.seth(25)
t.circle(-170,50)
infoPrt()
# 右耳
print('右耳')
t.seth(40)
#t.circle(-250,52)
t.circle(-250,30)
infoPrt()
# 右耳尖
t.begin_fill()
# 左
t.circle(-250,22)
#t.fillcolor("pink")
# 右
t.seth(227)
t.circle(-270, 15)
prePos = t.pos()
infoPrt()
# 下
t.seth(105)
t.circle(100, 32)
t.end_fill()
t.pu()
t.setpos(prePos)
t.pd()
t.seth(212)
t.circle(-270, 28)
prePos = t.pos()
t.pu()
t.goto(t.xcor()+5,t.ycor()-2)
t.pd()
# 躯干
print('躯干')
t.seth(280)
t.circle(500, 30)
infoPrt()
# 臀部
print('臀部')
t.seth(120)
#t.circle(150, -55)
t.circle(150, -11)
p_tail=t.pos()
t.circle(150, -44)
p_butt=t.pos()
infoPrt()
# 尾巴
t.pu()
t.setpos(p_tail)
t.pd()
t.begin_fill()
t.seth(50)
t.fd(25)
t.seth(-50)
t.fd(30)
p_tail1=t.pos
t.seth(-140)
t.fd(36)
t.end_fill()
t.seth(39)
# 右尾和h1
t.fd(72)
# 右尾和v1
t.seth(125)
t.fd(48)
# 右尾和h2
t.seth(40)
t.fd(53)
# 右尾和v2
t.seth(88)
t.fd(45)
# 右尾和h3
t.seth(35)
t.fd(105)
# 右尾和v3
t.seth(105)
t.circle(850, 8)
#t.fd(105)
t.seth(215)
#t.fd(125)
t.circle(850, 11)
t.seth(280)
t.fd(110)
t.seth(220)
t.fd(50)
t.seth(309)
t.fd(56)
# 底盘
print('底盘')
t.pu()
t.setpos(p_butt)
t.pd()
t.seth(20)
t.circle(120, -45)
infoPrt()
t.seth(330)
t.circle(-150, -30)
infoPrt()
prePos = t.pos()
t.pu()
t.goto(t.xcor()+20,t.ycor())
t.pd()
t.seth(230)
t.circle(-70, 120)
p_bot=t.pos()
# 两脚-right
t.pu()
t.setpos(p_butt)
t.setpos(t.xcor()+5,t.ycor()+5)
t.pd()
t.seth(-86)
t.fd(30)
t.seth(-93)
t.fd(33)
t.seth(-225)
t.circle(-150, 22)
# 两脚-left
t.pu()
t.setpos(p_bot)
t.setpos(t.xcor()+85,t.ycor()-43)
t.pd()
t.seth(-105)
t.fd(50)
t.seth(-225)
t.circle(-150, 22)
# 左躯干
print('躯干')
t.pu()
t.setpos(p_bot)
t.pd()
t.seth(90)
t.circle(450, 13)
p_lfhd = t.pos()
t.circle(450, 5)
t.pu()
t.circle(450, 5)
t.pd()
t.circle(450, 6)
infoPrt()
# 左脸
print('左脸')
t.seth(330)
t.circle(50, -90)
infoPrt()
# 左酒窝
t.seth(30)
t.circle(-15, 120)
t.seth(-70)
t.circle(-30, 90)
# 左手
t.pu()
t.setpos(p_lfhd)
t.pd()
t.seth(160)
t.circle(150, 30)
infoPrt()
t.seth(180)
t.circle(-30, 150)
t.fd(67)
t.pu()
t.setpos(t.xcor()-40,t.ycor()-60)
t.pd()
t.seth(200)
t.circle(-5, 180)
# 右手
t.pu()
t.setpos(p_lfhd)
t.setpos(t.xcor()+180,t.ycor()+5)
t.pd()
t.seth(200)
t.circle(-50, 100)
t.pu()
t.circle(-50, 15)
t.pd()
t.circle(-50, 65)
t.pu()
t.setpos(t.xcor()+10,t.ycor()-45)
t.pd()
#t.seth(270)
#t.circle(-30, -180)
t.seth(80)
t.fd(10)
t.seth(165)
t.circle(10, 60)
t.seth(90)
t.fd(5)
t.seth(165)
t.circle(10, 60)
t.seth(95)
t.fd(5)
t.seth(185)
t.circle(10, 60)
t.seth(105)
t.fd(10)
t.seth(230)
t.fd(20)
t.seth(145)
t.fd(10)
t.seth(285)
t.fd(20)
# 右酒窝
t.pu()
t.setpos(t.xcor()-40,t.ycor()+110)
t.pd()
t.circle(27, 360)
# 嘴
t.pu()
t.setpos(t.xcor()-30,t.ycor()+28)
t.pd()
t.seth(280)
t.circle(-130, 30)
t.seth(270)
t.circle(-6, 160)
t.seth(130)
t.circle(-130, 30)
t.pu()
t.setpos(t.xcor()-5,t.ycor()+5)
t.pd()
t.seth(160)
t.circle(-20, -70)
t.seth(160)
t.circle(-30, -60)
t.pu()
t.setpos(t.xcor(),t.ycor()-28)
t.pd()
t.seth(200)
t.circle(50, 58)
# 左眼
t.pu()
t.setpos(t.xcor()-40,t.ycor()+90)
t.pd()
t.circle(5)
t.pu()
t.setpos(t.xcor()+5,t.ycor()+10)
t.pd()
t.begin_fill()
t.seth(190)
t.circle(15, 130)
t.seth(310)
t.circle(10, 15)
t.seth(0)
t.circle(17, 133)
t.seth(90)
t.circle(10, 15)
t.end_fill()
t.pu()
t.setpos(t.xcor()+2,t.ycor()-15)
t.pd()
t.color("white")
t.begin_fill()
t.circle(5)
t.end_fill()
# 右眼
t.pu()
t.setpos(t.xcor()+85,t.ycor()+15)
t.pd()
t.color("black")
t.circle(5)
t.pu()
t.setpos(t.xcor()+5,t.ycor()+10)
t.pd()
t.begin_fill()
t.seth(190)
t.circle(20, 130)
t.seth(310)
t.circle(10, 15)
t.seth(0)
t.circle(22, 133)
t.seth(90)
t.circle(13, 15)
t.end_fill()
t.pu()
t.setpos(t.xcor()-7,t.ycor()-15)
t.pd()
t.color("white")
t.begin_fill()
t.circle(7)
t.end_fill()
# 左耳
t.color("black")
t.pu()
t.goto(-210,86)
t.setpos(t.xcor()+15,t.ycor()+38)
t.pd()
t.seth(90)
t.circle(-250,30)
t.begin_fill()
# 左
t.circle(-250,18)
# 右
t.seth(270)
t.circle(-270, 12)
prePos = t.pos()
# 下
t.seth(180)
t.circle(100, 30)
t.end_fill()
t.pu()
t.setpos(prePos)
t.pd()
t.seth(270)
t.circle(-270, 18)
t.done()
给你画个皮卡丘(没上色) !牛逼 乘号 发表于 2020-3-24 12:20
这貌似是我发的代码
别的网站上的 六小鸭 发表于 2020-3-24 12:32
别的网站上的
看来我们找的是一个网站{:10_266:} 最秀的是樱花每次还不一样 {:10_275:}绝了 这死循环一点也不好玩 wuqramy 发表于 2020-3-24 13:08
这死循环一点也不好玩
哦?你有什么好玩的源码嘛?{:10_256:}反正我觉得上面两个挺惊艳的,别引战哦{:10_330:} 本帖最后由 wuqramy 于 2020-3-24 13:21 编辑
xiaomei47580 发表于 2020-3-24 13:10
哦?你有什么好玩的源码嘛?反正我觉得上面两个挺惊艳的,别引战哦
送你一个字典
from urllib import request, parse
from urllib.parse import quote
from lxml import etree
from tkinter import *
import json
# 英文单词查询网址
ebase = 'http://dict.youdao.com/w/eng/'
# 中文单词查询网址
cbase = 'http://dict.youdao.com/w/'
# 翻译网址
trans = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
# 查询时http头
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"}
# 翻译提交的字典
dic = {"doctype": "json"}
# 判断查询类型
def chaxun():
if v.get() == 1:
chaci()
else:
fanyi()
# 查词 chaci():
def chaci():
wd = e1.get()
if '\u4e00' <= wd <= '\u9fff':
# 如果是中文查询,转换中文为URL编码格式
wd = quote(wd)
url = cbase + wd
q = request.Request(url=url, headers=headers)
r = request.urlopen(q, timeout=2)
html = etree.HTML(r.read().decode('utf-8'))
result = html.xpath('/html/body/div/div/div/div/div/div/div/ul/p/span/a/text()')
else:
url = ebase + wd
q = request.Request(url=url, headers=headers)
r = request.urlopen(q, timeout=2)
html = etree.HTML(r.read().decode('utf-8'))
result = html.xpath('/html/body/div/div/div/div/div/div/div/ul/li/text()')
# 清理text,重新显示
text1.delete(1.0, END)
# 如果有结果,显示结果
if len(result) != 0:
for pt in result:
text1.insert(INSERT, pt + '\n')
else:
# 如果没有结果,提示没有结果
text1.insert(INSERT, 'There is no explain.')
# 翻译
def fanyi():
text1.delete(1.0, END)
wd = e1.get()
dic['i'] = wd
data = bytes(parse.urlencode(dic), encoding='utf-8')
q = request.Request(url=trans, data=data, headers=headers, method='POST')
r = request.urlopen(q)
result = json.loads(r.read().decode('utf-8'))
text1.insert(INSERT, result['translateResult']['tgt'])
if __name__ == '__main__':
# 主函数,定义一个tk对象
root = Tk()
root.title('简易英汉双译字典')
l1 = Label(root, text='请输入要查询的内容:')
l1.grid(row=0, column=0)
e1 = Entry(root)
e1.grid(row=0, column=1, padx=1, pady=5)
bt1 = Button(root, text='查询', command=chaxun)
bt1.grid(row=0, column=2, padx=5, pady=5)
text1 = Text(root, width=59, height=10)
text1.grid(row=1, columnspan=5, padx=5, pady=7)
v = IntVar()
v.set(1)
Radiobutton(root, text="查词", variable=v, value=1).grid(row=0, column=3)
Radiobutton(root, text="翻译", variable=v, value=2).grid(row=0, column=4)
mainloop()
我是小美,,不是她{:10_303:} xiaomei47580 发表于 2020-3-24 13:19
我是小美,,不是她
{:10_306:} 哎鸭,没有叫‘LXML’的docs啊 xiaomei47580 发表于 2020-3-24 13:10
哦?你有什么好玩的源码嘛?反正我觉得上面两个挺惊艳的,别引战哦
他说的是你的while True……{:10_248:} 本帖最后由 wuqramy 于 2020-3-24 13:25 编辑
xiaomei47580 发表于 2020-3-24 13:21
哎鸭,没有叫‘LXML’的docs啊
没有就下,在cmd中输入:
pip install lxml wuqramy 发表于 2020-3-24 13:08
这死循环一点也不好玩
哈哈,我不是说了这是幼儿园级别的嘛,我也才刚学第三天啊 xiaomei47580 发表于 2020-3-24 13:24
哈哈,我不是说了这是幼儿园级别的嘛,我也才刚学第三天啊
{:10_247:}(这次换成吐血了) wuqramy 发表于 2020-3-24 13:23
下,在cmd中输入:
CDM???
页:
[1]
2