鱼C论坛

 找回密码
 立即注册
查看: 2100|回复: 26

整点好玩的

[复制链接]
发表于 2020-3-24 11:36:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
明天是小美同学的生日,在这个没有派对,没有聚会的日子里,我非常感谢我遇见了Python
虽说算个辅助工具,但应该也不缺花里胡哨的东西吧


发这个帖子就是想看看大佬们怎么在代码世界里面敲出好玩的东西(不知道我这个要求会不会很奇怪

我先来最最幼儿园的
  1. while True:
  2.     print('"小美,祝你生日快乐鸭"')
复制代码
期待大佬们的表现
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-24 11:43:37 | 显示全部楼层
  1. import turtle as T
  2. import random
  3. import time

  4. # 画樱花的躯干(60,t)
  5. def Tree(branch, t):
  6.     time.sleep(0.0005)
  7.     if branch > 3:
  8.         if 8 <= branch <= 12:
  9.             if random.randint(0, 2) == 0:
  10.                 t.color('snow')  # 白
  11.             else:
  12.                 t.color('lightcoral')  # 淡珊瑚色
  13.             t.pensize(branch / 3)
  14.         elif branch < 8:
  15.             if random.randint(0, 1) == 0:
  16.                 t.color('snow')
  17.             else:
  18.                 t.color('lightcoral')  # 淡珊瑚色
  19.             t.pensize(branch / 2)
  20.         else:
  21.             t.color('sienna')  # 赭(zhě)色
  22.             t.pensize(branch / 10)  # 6
  23.         t.forward(branch)
  24.         a = 1.5 * random.random()
  25.         t.right(20 * a)
  26.         b = 1.5 * random.random()
  27.         Tree(branch - 10 * b, t)
  28.         t.left(40 * a)
  29.         Tree(branch - 10 * b, t)
  30.         t.right(20 * a)
  31.         t.up()
  32.         t.backward(branch)
  33.         t.down()

  34. # 掉落的花瓣
  35. def Petal(m, t):
  36.     for i in range(m):
  37.         a = 200 - 400 * random.random()
  38.         b = 10 - 20 * random.random()
  39.         t.up()
  40.         t.forward(b)
  41.         t.left(90)
  42.         t.forward(a)
  43.         t.down()
  44.         t.color('lightcoral')  # 淡珊瑚色
  45.         t.circle(1)
  46.         t.up()
  47.         t.backward(a)
  48.         t.right(90)
  49.         t.backward(b)

  50. # 绘图区域
  51. t = T.Turtle()
  52. # 画布大小
  53. w = T.Screen()
  54. t.hideturtle()  # 隐藏画笔
  55. t.getscreen().tracer(5, 0)
  56. w.screensize(bg='wheat')  # wheat小麦
  57. t.left(90)
  58. t.up()
  59. t.backward(150)
  60. t.down()
  61. t.color('sienna')

  62. # 画樱花的躯干
  63. Tree(60, t)
  64. # 掉落的花瓣
  65. Petal(200, t)
  66. w.exitonclick()
  67. 原文链接:https://blog.csdn.net/weixin_43943977/article/details/102691392
复制代码

去了最后一行
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2020-3-24 12:20:38 | 显示全部楼层

这貌似是我发的代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 12:21:32 | 显示全部楼层
  1. # coding:utf-8
  2. import turtle as t
  3. def infoPrt():
  4.     print('coordinate: ' + str(t.pos()))
  5.     print('angle: ' + str(t.heading()))
  6. t.pensize(3)
  7. t.hideturtle()
  8. t.colormode(255)
  9. t.color("black")
  10. t.setup(700, 650)
  11. t.speed(10)
  12. t.st()
  13. #t.dot()
  14. t.pu()
  15. #t.goto(-150,100)
  16. t.goto(-210,86)
  17. t.pd()
  18. infoPrt()
  19. # 头
  20. print('头')
  21. t.seth(85)
  22. t.circle(-100,50)
  23. #t.seth(78)
  24. #t.circle(-100,25)
  25. infoPrt()
  26. t.seth(25)
  27. t.circle(-170,50)
  28. infoPrt()
  29. # 右耳
  30. print('右耳')
  31. t.seth(40)
  32. #t.circle(-250,52)
  33. t.circle(-250,30)
  34. infoPrt()
  35. # 右耳尖
  36. t.begin_fill()
  37. # 左
  38. t.circle(-250,22)
  39. #t.fillcolor("pink")
  40. # 右
  41. t.seth(227)
  42. t.circle(-270, 15)
  43. prePos = t.pos()
  44. infoPrt()
  45. # 下
  46. t.seth(105)
  47. t.circle(100, 32)
  48. t.end_fill()
  49. t.pu()
  50. t.setpos(prePos)
  51. t.pd()
  52. t.seth(212)
  53. t.circle(-270, 28)
  54. prePos = t.pos()
  55. t.pu()
  56. t.goto(t.xcor()+5,t.ycor()-2)
  57. t.pd()
  58. # 躯干
  59. print('躯干')
  60. t.seth(280)
  61. t.circle(500, 30)
  62. infoPrt()
  63. # 臀部
  64. print('臀部')
  65. t.seth(120)
  66. #t.circle(150, -55)
  67. t.circle(150, -11)
  68. p_tail=t.pos()
  69. t.circle(150, -44)
  70. p_butt=t.pos()
  71. infoPrt()
  72. # 尾巴
  73. t.pu()
  74. t.setpos(p_tail)
  75. t.pd()
  76. t.begin_fill()
  77. t.seth(50)
  78. t.fd(25)
  79. t.seth(-50)
  80. t.fd(30)
  81. p_tail1=t.pos
  82. t.seth(-140)
  83. t.fd(36)
  84. t.end_fill()
  85. t.seth(39)
  86. # 右尾和h1
  87. t.fd(72)
  88. # 右尾和v1
  89. t.seth(125)
  90. t.fd(48)
  91. # 右尾和h2
  92. t.seth(40)
  93. t.fd(53)
  94. # 右尾和v2
  95. t.seth(88)
  96. t.fd(45)
  97. # 右尾和h3
  98. t.seth(35)
  99. t.fd(105)
  100. # 右尾和v3
  101. t.seth(105)
  102. t.circle(850, 8)
  103. #t.fd(105)
  104. t.seth(215)
  105. #t.fd(125)
  106. t.circle(850, 11)
  107. t.seth(280)
  108. t.fd(110)
  109. t.seth(220)
  110. t.fd(50)
  111. t.seth(309)
  112. t.fd(56)
  113. # 底盘
  114. print('底盘')
  115. t.pu()
  116. t.setpos(p_butt)
  117. t.pd()
  118. t.seth(20)
  119. t.circle(120, -45)
  120. infoPrt()
  121. t.seth(330)
  122. t.circle(-150, -30)
  123. infoPrt()
  124. prePos = t.pos()
  125. t.pu()
  126. t.goto(t.xcor()+20,t.ycor())
  127. t.pd()
  128. t.seth(230)
  129. t.circle(-70, 120)
  130. p_bot=t.pos()
  131. # 两脚-right
  132. t.pu()
  133. t.setpos(p_butt)
  134. t.setpos(t.xcor()+5,t.ycor()+5)
  135. t.pd()
  136. t.seth(-86)
  137. t.fd(30)
  138. t.seth(-93)
  139. t.fd(33)
  140. t.seth(-225)
  141. t.circle(-150, 22)
  142. # 两脚-left
  143. t.pu()
  144. t.setpos(p_bot)
  145. t.setpos(t.xcor()+85,t.ycor()-43)
  146. t.pd()
  147. t.seth(-105)
  148. t.fd(50)
  149. t.seth(-225)
  150. t.circle(-150, 22)
  151. # 左躯干
  152. print('躯干')
  153. t.pu()
  154. t.setpos(p_bot)
  155. t.pd()
  156. t.seth(90)
  157. t.circle(450, 13)
  158. p_lfhd = t.pos()
  159. t.circle(450, 5)
  160. t.pu()
  161. t.circle(450, 5)
  162. t.pd()
  163. t.circle(450, 6)
  164. infoPrt()
  165. # 左脸
  166. print('左脸')
  167. t.seth(330)
  168. t.circle(50, -90)
  169. infoPrt()
  170. # 左酒窝
  171. t.seth(30)
  172. t.circle(-15, 120)
  173. t.seth(-70)
  174. t.circle(-30, 90)
  175. # 左手
  176. t.pu()
  177. t.setpos(p_lfhd)
  178. t.pd()
  179. t.seth(160)
  180. t.circle(150, 30)
  181. infoPrt()
  182. t.seth(180)
  183. t.circle(-30, 150)
  184. t.fd(67)
  185. t.pu()
  186. t.setpos(t.xcor()-40,t.ycor()-60)
  187. t.pd()
  188. t.seth(200)
  189. t.circle(-5, 180)
  190. # 右手
  191. t.pu()
  192. t.setpos(p_lfhd)
  193. t.setpos(t.xcor()+180,t.ycor()+5)
  194. t.pd()
  195. t.seth(200)
  196. t.circle(-50, 100)
  197. t.pu()
  198. t.circle(-50, 15)
  199. t.pd()
  200. t.circle(-50, 65)
  201. t.pu()
  202. t.setpos(t.xcor()+10,t.ycor()-45)
  203. t.pd()
  204. #t.seth(270)
  205. #t.circle(-30, -180)
  206. t.seth(80)
  207. t.fd(10)
  208. t.seth(165)
  209. t.circle(10, 60)
  210. t.seth(90)
  211. t.fd(5)
  212. t.seth(165)
  213. t.circle(10, 60)
  214. t.seth(95)
  215. t.fd(5)
  216. t.seth(185)
  217. t.circle(10, 60)
  218. t.seth(105)
  219. t.fd(10)
  220. t.seth(230)
  221. t.fd(20)
  222. t.seth(145)
  223. t.fd(10)
  224. t.seth(285)
  225. t.fd(20)
  226. # 右酒窝
  227. t.pu()
  228. t.setpos(t.xcor()-40,t.ycor()+110)
  229. t.pd()
  230. t.circle(27, 360)
  231. # 嘴
  232. t.pu()
  233. t.setpos(t.xcor()-30,t.ycor()+28)
  234. t.pd()
  235. t.seth(280)
  236. t.circle(-130, 30)
  237. t.seth(270)
  238. t.circle(-6, 160)
  239. t.seth(130)
  240. t.circle(-130, 30)
  241. t.pu()
  242. t.setpos(t.xcor()-5,t.ycor()+5)
  243. t.pd()
  244. t.seth(160)
  245. t.circle(-20, -70)
  246. t.seth(160)
  247. t.circle(-30, -60)
  248. t.pu()
  249. t.setpos(t.xcor(),t.ycor()-28)
  250. t.pd()
  251. t.seth(200)
  252. t.circle(50, 58)
  253. # 左眼
  254. t.pu()
  255. t.setpos(t.xcor()-40,t.ycor()+90)
  256. t.pd()
  257. t.circle(5)
  258. t.pu()
  259. t.setpos(t.xcor()+5,t.ycor()+10)
  260. t.pd()
  261. t.begin_fill()
  262. t.seth(190)
  263. t.circle(15, 130)
  264. t.seth(310)
  265. t.circle(10, 15)
  266. t.seth(0)
  267. t.circle(17, 133)
  268. t.seth(90)
  269. t.circle(10, 15)
  270. t.end_fill()
  271. t.pu()
  272. t.setpos(t.xcor()+2,t.ycor()-15)
  273. t.pd()
  274. t.color("white")
  275. t.begin_fill()
  276. t.circle(5)
  277. t.end_fill()
  278. # 右眼
  279. t.pu()
  280. t.setpos(t.xcor()+85,t.ycor()+15)
  281. t.pd()
  282. t.color("black")
  283. t.circle(5)
  284. t.pu()
  285. t.setpos(t.xcor()+5,t.ycor()+10)
  286. t.pd()
  287. t.begin_fill()
  288. t.seth(190)
  289. t.circle(20, 130)
  290. t.seth(310)
  291. t.circle(10, 15)
  292. t.seth(0)
  293. t.circle(22, 133)
  294. t.seth(90)
  295. t.circle(13, 15)
  296. t.end_fill()
  297. t.pu()
  298. t.setpos(t.xcor()-7,t.ycor()-15)
  299. t.pd()
  300. t.color("white")
  301. t.begin_fill()
  302. t.circle(7)
  303. t.end_fill()
  304. # 左耳
  305. t.color("black")
  306. t.pu()
  307. t.goto(-210,86)
  308. t.setpos(t.xcor()+15,t.ycor()+38)
  309. t.pd()
  310. t.seth(90)
  311. t.circle(-250,30)
  312. t.begin_fill()
  313. # 左
  314. t.circle(-250,18)
  315. # 右
  316. t.seth(270)
  317. t.circle(-270, 12)
  318. prePos = t.pos()
  319. # 下
  320. t.seth(180)
  321. t.circle(100, 30)
  322. t.end_fill()
  323. t.pu()
  324. t.setpos(prePos)
  325. t.pd()
  326. t.seth(270)
  327. t.circle(-270, 18)
  328. t.done()

复制代码


给你画个皮卡丘(没上色)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 12:32:46 | 显示全部楼层
!牛逼
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-24 12:32:48 | 显示全部楼层
乘号 发表于 2020-3-24 12:20
这貌似是我发的代码

别的网站上的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 12:33:25 | 显示全部楼层

看来我们找的是一个网站
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 12:41:56 | 显示全部楼层
最秀的是樱花每次还不一样
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 12:42:31 | 显示全部楼层
绝了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-24 13:08:08 | 显示全部楼层
这死循环一点也不好玩
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 13:10:10 | 显示全部楼层
wuqramy 发表于 2020-3-24 13:08
这死循环一点也不好玩

哦?你有什么好玩的源码嘛?反正我觉得上面两个挺惊艳的,别引战哦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 13:13:20 | 显示全部楼层
本帖最后由 wuqramy 于 2020-3-24 13:21 编辑
xiaomei47580 发表于 2020-3-24 13:10
哦?你有什么好玩的源码嘛?反正我觉得上面两个挺惊艳的,别引战哦


送你一个字典
  1. from urllib import request, parse
  2. from urllib.parse import quote
  3. from lxml import etree
  4. from tkinter import *
  5. import json


  6. # 英文单词查询网址
  7. ebase = 'http://dict.youdao.com/w/eng/'
  8. # 中文单词查询网址
  9. cbase = 'http://dict.youdao.com/w/'
  10. # 翻译网址
  11. trans = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
  12. # 查询时http头
  13. headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"}
  14. # 翻译提交的字典
  15. dic = {"doctype": "json"}


  16. # 判断查询类型
  17. def chaxun():
  18.     if v.get() == 1:
  19.         chaci()
  20.     else:
  21.         fanyi()


  22. # 查词 chaci():
  23. def chaci():
  24.     wd = e1.get()
  25.     if '\u4e00' <= wd <= '\u9fff':
  26.         # 如果是中文查询,转换中文为URL编码格式
  27.         wd = quote(wd)
  28.         url = cbase + wd
  29.         q = request.Request(url=url, headers=headers)
  30.         r = request.urlopen(q, timeout=2)
  31.         html = etree.HTML(r.read().decode('utf-8'))
  32.         result = html.xpath('/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div/ul/p/span/a/text()')
  33.     else:
  34.         url = ebase + wd
  35.         q = request.Request(url=url, headers=headers)
  36.         r = request.urlopen(q, timeout=2)
  37.         html = etree.HTML(r.read().decode('utf-8'))
  38.         result = html.xpath('/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div/ul/li/text()')
  39.     # 清理text,重新显示
  40.     text1.delete(1.0, END)
  41.     # 如果有结果,显示结果
  42.     if len(result) != 0:
  43.         for pt in result:
  44.             text1.insert(INSERT, pt + '\n')
  45.     else:
  46.         # 如果没有结果,提示没有结果
  47.         text1.insert(INSERT, 'There is no explain.')


  48. # 翻译
  49. def fanyi():
  50.     text1.delete(1.0, END)
  51.     wd = e1.get()
  52.     dic['i'] = wd
  53.     data = bytes(parse.urlencode(dic), encoding='utf-8')
  54.     q = request.Request(url=trans, data=data, headers=headers, method='POST')
  55.     r = request.urlopen(q)
  56.     result = json.loads(r.read().decode('utf-8'))
  57.     text1.insert(INSERT, result['translateResult'][0][0]['tgt'])


  58. if __name__ == '__main__':
  59.     # 主函数,定义一个tk对象
  60.     root = Tk()
  61.     root.title('简易英汉双译字典')
  62.     l1 = Label(root, text='请输入要查询的内容:')
  63.     l1.grid(row=0, column=0)
  64.     e1 = Entry(root)
  65.     e1.grid(row=0, column=1, padx=1, pady=5)
  66.     bt1 = Button(root, text='查询', command=chaxun)
  67.     bt1.grid(row=0, column=2, padx=5, pady=5)
  68.     text1 = Text(root, width=59, height=10)
  69.     text1.grid(row=1, columnspan=5, padx=5, pady=7)
  70.     v = IntVar()
  71.     v.set(1)
  72.     Radiobutton(root, text="查词", variable=v, value=1).grid(row=0, column=3)
  73.     Radiobutton(root, text="翻译", variable=v, value=2).grid(row=0, column=4)
  74.     mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 13:19:31 | 显示全部楼层
我是小美,,不是她
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 13:20:29 | 显示全部楼层
xiaomei47580 发表于 2020-3-24 13:19
我是小美,,不是她

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 13:21:19 | 显示全部楼层
哎鸭,没有叫‘LXML’的docs啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 13:22:33 | 显示全部楼层
xiaomei47580 发表于 2020-3-24 13:10
哦?你有什么好玩的源码嘛?反正我觉得上面两个挺惊艳的,别引战哦

他说的是你的while True……
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 13:23:20 | 显示全部楼层
本帖最后由 wuqramy 于 2020-3-24 13:25 编辑
xiaomei47580 发表于 2020-3-24 13:21
哎鸭,没有叫‘LXML’的docs啊


没有就下,在cmd中输入:
  1. pip install lxml
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 13:24:24 | 显示全部楼层
wuqramy 发表于 2020-3-24 13:08
这死循环一点也不好玩

哈哈,我不是说了这是幼儿园级别的嘛,我也才刚学第三天啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-24 13:25:09 | 显示全部楼层
xiaomei47580 发表于 2020-3-24 13:24
哈哈,我不是说了这是幼儿园级别的嘛,我也才刚学第三天啊

(这次换成吐血了)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-24 13:25:33 | 显示全部楼层
wuqramy 发表于 2020-3-24 13:23
下,在cmd中输入:

CDM???
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 10:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表