用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

代码段合集1.0

2022-01-17 作者: 尾翼稳定脱壳穿甲弹举报

[python]代码库

def js():
   while True:
            a=int(input('完毕!按“0”退出程序'))
            if a==0:
               exit() 

print(' ----------------------------------------------------------')
print('|1.参数                              |2.二维码生成器       |')
print('|3.猜数游戏                          |4.绘图总成           |')
print('|5.作者专属标志(绘画)              |6.文字打印机         |')
print('|7.计时器                            |8.密码机             |')
print('|9.生成随机树                        |10.五子棋            |')
print(' ----------------------------------------------------------')

yhxz=float(input('选择以上功能:'))
if yhxz==1:
   import time#导入import.
   t=time.strftime('%Y年%m月%d日%H:%M:%S')  
   print(' ')
   print('本程序系基于2.4版本开发的Fei.N.J.纪念版')
   print('2.4版本编辑时间:       2021年11月26日18:10:34')
   print('Fei.N.J.纪念版编辑时间:2021年12月13日12:13:38')
   print(' ')
   print(' ')
   print('现在的时间是',t)
   print(' ')
   print('作者Q:2643661328')
   print(' ')
   print('彩蛋请看:1234彩蛋目录')
   print(' ')
   print('注:本系统及衍生可能会取代2.5及衍生 ')

   js()
   
if yhxz==1234:
   print('404.(不可轻易运行)')
   
if yhxz==2:
        print(' ')
        print('1.普通黑白         2.镶彩(需要黑白原码)')
        yyds=float(input('选择类型:')) 
        if yyds==1:
          print('输入要保存的文字:')
          babq=input()
          from MyQR import myqr
          myqr.run(babq) 
        if yyds==2:
          print(' ')
          dsgl=input('输入与程序同目录的黑白原图链接(即二维码所包含的内容):')     
          r4gl=input('输入与程序同目录的图片名称(只支持“.jpg”,“.png”,“.bmp”,“.gif”格式;注意名称后要加格式):')
          from MyQR import myqr
          myqr.run(words=(dsgl),
                   picture=(r4gl),
                   colorized=True)
        js()
        
if yhxz==3:
          import random
          secret=random.randint(1,99)
          guess=0
          tries=0
          print(' ')
          print('欢迎进入猜数游戏!')
          print('程序已做好准备')
          while guess!=secret and tries<10:
                guess=int(input('输入你猜的数:'))
                if guess<secret:
                   print(str(guess)+'小了')
                elif guess>secret:
                   print(str(guess)+'大了')
                tries=tries+1
          if guess==secret:
            print('正确')
          while True:
              a=int(input('完毕!按“0”退出程序'))
              if a==0:
                 break 

          else:
            print('挑战失败,正确的数是'+str(secret))
          js()
          
if yhxz==4:
         qwq=int(input('1. 无名 2.'))
         if qwq==1:
          print(' ')
          import turtle#导入turtle.
          t=turtle.Pen()#‘t’表示turtle.
          print('红:red 粉:pink 橙:orange 黄:yellow 棕:brown 绿:green 青:cyan 蓝:blue 紫:purple 白:white 灰:grey 黑:black')
          s1=input('对照上表输入第1画颜色的英文名:')
          s2=input('对照上表输入第2画颜色的英文名:')
          s3=input('对照上表输入第3画颜色的英文名:')
          s4=input('对照上表输入第4画颜色的英文名:')
          sd=int(input('选择速度即开始(1-10越大越快;输入0或10以上的数达到极限速度):'))
          for i in range(71):#不多不少刚好71.
          #以下数值是配套的,如修改最终的形状效果将不同(除颜色代码外).  
              t.speed(sd)
              t.right(60)
              t.pencolor(s1)
              t.forward(100)
              t.left(120)
              t.pencolor(s2)
              t.forward(100)
              t.right(66)
              t.pencolor(s3)
              t.forward(88)
              t.left(77)
              t.pencolor(s4)
              t.circle(104)
         
         if qwq==2:
          import turtle
          t=turtle.Pen()
          t.setup(675,450,700,90)
          t.bgcolor("red")
          t.color("yellow","yellow")
          t.speed(8)
          dian_mia = [(-280,100),(-100,160),(-50,110),(-40,50),(-100,10)]
          dian_sth = [0,55,30,5,-30]
          for i in range(5):
              t.up()
              t.goto(dian_mia[i])
              t.setheading(dian_sth[i])
              t.begin_fill()
              for m in range(5):
                  t.fd(150 if i==0 else 50)
                  t.right(144)
                  t.down()
              t.end_fill()
          t.hideturtle()
          t.done()
         js()
          
if yhxz==5:
 import turtle
 t=turtle.Pen()
 t.pensize(20)#粗细
 t.left(135)#1
 t.forward(280)
 t.up()
 t.right(135)
 t.forward(396)
 t.right(135)
 t.down()
 t.forward(538)#2
 t.left(135)
 t.forward(365)#3
 t.left(135)
 t.forward(150)#4
 t.right(110)
 t.forward(240)#5
 t.up()
 t.left(180)
 t.forward(240)#6
 t.left(110)
 t.forward(80)#7
 t.left(70)
 t.down()
 t.forward(160)#8


 
if yhxz==6:
   print(' ')
   print('1.单项无限刷屏(可能造成系统崩溃) 2.单项自定义刷屏(数据过大可能造成系统崩溃)')
   s5=int(input('选择以上功能:'))
   if s5==1:
           s6=input('输入你要无限刷屏的内容:')
           var=1
           while var==1:
                       print(s6)
   if s5==2:
           s7=input('输入你要无限刷屏的内容:')
           s8=int(input('输入你要数量(纯数字):'))
           print(s7*s8)
      
   js()
   
if yhxz==7:
 print(' ')
 import tkinter
 import threading
 import time
 
 from1 = tkinter.Tk()
 from1.title('计时器')
 from1.minsize(400, 400)
 
 isloop = False  
 var = tkinter.StringVar()
 stopid = None  
 
 def gettime():
    global isloop
    global stopid
    global star
    global fo
 
    elap = time.time() - star  
 
    if isinstance(stopid, float):
        a = stopid
        elap = elap + a
    minutes = int(elap / 60)  
    seconds = int(elap - minutes * 60.0) 
    hseconds = int((elap - minutes * 60.0 - seconds) * 1000)  
    var.set('%02d:%02d:%03d' % (minutes, seconds, hseconds))
 
    if isloop == False:
        but1['text'] = '继续'
        stopid = elap   
        fo.write('%02d:%02d:%03d' % (minutes, seconds, hseconds) +"\n")
        fo.close() 
        return
 
    from1.after(1, gettime) 
 
 def newtask():
    global isloop
    global star
    global fo
    if but1['text'] == '开始' or but1['text'] == '继续': 
        if but1['text'] == '开始':
            fo = open("record.txt", "w") 
        else:
            fo = open("record.txt", "a")  
        but1['text'] = '暂停'
        isloop = True
        star = time.time() 
        t = threading.Thread(target=gettime)
        t.start()
    else:
        isloop = False
 
 def clearing():
    global isloop
    global stopid
    isloop = False 
    stopid = None  
    var.set('00:00:000')
    but1['text'] = '开始'
 
 but1 = tkinter.Button(from1, text='开始', command=newtask)
 but1.place(x=95, y=280, width=80, height=50)  
 but2 = tkinter.Button(from1, text='清零', command=clearing)
 but2.place(x=225, y=280, width=80, height=50)
 
var.set('00:00:000')  
 lab1 = tkinter.Label(from1, textvariable=var, font=("Arial Bold", 30), foreground="red")
 lab1.place(x=110, y=150)
 
 # from1.overrideredirect(1)
 from1.attributes("-toolwindow", 1)  
 from1.mainloop()
 js()

if yhxz==8:
   print('1.加密         2.(运行错误)解密')
   mmj=float(input('选择类型:'))
   if mmj==1:
      while True:
          words = input('请输入要加密的内容:')
          ans = int(input('请输入偏移量:'))
          if (words == 'break') or(ans == 'break'):
              break
          code = []
          for w in words:
             num = ord(w)
             code.append(num)
             num = num + ans
   
          print(code)
   
          f = open('1.txt', 'w')
          res = str(code)
          f.write(res)
          f.close()
          print('加密结果已写入文件!')
          js()
   if mmj==2:
       while True:
           code = input('请输入要解密的内容:')
           code = eval(code)
  
           ans = int(input('请输入偏移量:'))
  
           words = ''
           for num in code:
               w = chr(num)
               num = num - ans
               words = words + w
           print('解密的结果为:' + words)
           js()

if yhxz==9:
 print(' ') 
 # -*- coding: utf-8 -*-
 
 import tkinter
 import sys, random, math
 
 class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
 
    def __str__(self):
        return "<Point>: (%f, %f)" % (self.x, self.y)
 
 class Branch(object):
    def __init__(self, bottom, top, branches, level = 0):
        self.bottom = bottom
        self.top = top
        self.level = level
        self.branches = branches
        self.children = []
 
    def __str__(self):
        s = "Top: %s, Bottom: %s, Children Count: %d" % \
            (self.top, self.bottom, len(self.children))
        return s
 
    def nextGen(self, n = -1, rnd = 1):
        if n <= 0: n = self.branches
        if rnd == 1:
            n = random.randint(n / 2, n * 2)
            if n <= 0: n = 1
        dx = self.top.x - self.bottom.x
        dy = self.top.y - self.bottom.y
        r = 0.20 + random.random() * 0.2
        if self.top.x == self.bottom.x:
            # 如果是一条竖线
            x = self.top.x
            y = dy * r + self.bottom.y
        elif self.top.y == self.bottom.y:
            # 如果是一条横线
            x = dx * r + self.bottom.x
            y = self.top.y
        else:
            x = dx * r
            y = x * dy / dx
            x += self.bottom.x
            y += self.bottom.y
        oldTop = self.top
        self.top = Point(x, y)
        a = math.pi / (2 * n)
        for i in range(n):
            a2 = -a * (n - 1) / 2 + a * i - math.pi
            a2 *= 0.9 + random.random() * 0.2
            self.children.append(self.mkNewBranch(self.top, oldTop, a2))
 
    def mkNewBranch(self, bottom, top, a):
        dx1 = top.x - bottom.x
        dy1 = top.y - bottom.y
        r = 0.9 + random.random() * 0.2
        c = math.sqrt(dx1 ** 2 + dy1 ** 2) * r
        if dx1 == 0:
            a2 = math.pi / 2
        else:
            a2 = math.atan(dy1 / dx1)
            if (a2 < 0 and bottom.y > top.y) \
                or (a2 > 0 and bottom.y < top.y) \
                :
                a2 += math.pi
        b = a2 - a
        dx2 = c * math.cos(b)
        dy2 = c * math.sin(b)
        newTop = Point(dx2 + bottom.x, dy2 + bottom.y)
        return Branch(bottom, newTop, self.branches, self.level + 1)
 
 class Tree(object):
    def __init__(self, root, canvas, bottom, top, branches = 3, depth = 3):
        self.root = root
        self.canvas = canvas
        self.bottom = bottom
        self.top = top
        self.branches = branches
        self.depth = depth
        self.new()
 
    def gen(self, n = 1):
        for i in range(n):
            self.getLeaves()
            for node in self.leaves:
                node.nextGen()
        self.show()
 
    def new(self):
        self.leavesCount = 0
        self.branch = Branch(self.bottom, self.top, self.branches)
        self.gen(self.depth)
        print ("leaves count: %d" % self.leavesCount)
 
    def chgDepth(self, d):
        self.depth += d
        if self.depth < 0: self.depth = 0
        if self.depth > 10: self.depth = 10
        self.new()
 
    def chgBranch(self, d):
        self.branches += d
        if self.branches < 1: self.branches = 1
        if self.branches > 10: self.branches = 10
        self.new()
 
    def getLeaves(self):
        self.leaves = []
        self.map(self.findLeaf)
 
    def findLeaf(self, node):
        if len(node.children) == 0:
            self.leaves.append(node)
 
    def show(self):
        for i in self.canvas.find_all():
            self.canvas.delete(i)
        self.map(self.drawNode)
        self.canvas.tag_raise("leaf")
 
    def exit(self, evt):
        sys.exit(0)
 
    def map(self, func = lambda node: node):
        # 遍历树
        children = [self.branch]
        while len(children) != 0:
            newChildren = []
            for node in children:
                func(node)
                newChildren.extend(node.children)
            children = newChildren
 
    def drawNode(self, node):
        self.line2(
 #       self.canvas.create_line(
                node.bottom.x,
                node.bottom.y,
                node.top.x,
                node.top.y,
                fill = "#100",
                width = 1.5 ** (self.depth - node.level),
                tags = "branch level_%d" % node.level,
            )
 
        if len(node.children) == 0:
            # 画叶子
            self.leavesCount += 1
            self.canvas.create_oval(
                    node.top.x - 3,
                    node.top.y - 3,
                    node.top.x + 3,
                    node.top.y + 3,
                    fill = "#090",
                    tag = "leaf",
                )
 
        self.canvas.update()
 
    def line2(self, x0, y0, x1, y1, width = 1, fill = "#000", minDist = 10, tags = ""):
        dots = midDots(x0, y0, x1, y1, minDist)
        dots2 = []
        for i in range(len(dots) - 1):
            dots2.extend([dots[i].x,
                dots[i].y,
                dots[i + 1].x,
                dots[i + 1].y])
        self.canvas.create_line(
                dots2,
                fill = fill,
                width = width,
                smooth = True,
                tags = tags,
            )
 
 def midDots(x0, y0, x1, y1, d):
    dots = []
    dx, dy, r = x1 - x0, y1 - y0, 0
    if dx != 0:
        r = float(dy) / dx
    c = math.sqrt(dx ** 2 + dy ** 2)
    n = int(c / d) + 1
    for i in range(n):
        if dx != 0:
            x = dx * i / n
            y = x * r
        else:
            x = dx
            y = dy * i / n
        if i > 0:
            x += d * (0.5 - random.random()) * 0.25
            y += d * (0.5 - random.random()) * 0.25
        x += x0
        y += y0
        dots.append(Point(x, y))
    dots.append(Point(x1, y1))
    return dots
 
 if __name__ == "__main__":
    root = tkinter.Tk()
    root.title("Tree")
    gw, gh = 800, 600
    canvas = tkinter.Canvas(root,
            width = gw,
            height = gh,
        )
    canvas.pack()
    tree = Tree(root, canvas, Point(gw / 2, gh - 20), Point(gw / 2, gh * 0.2), \
        branches = 2, depth = 8)
    root.bind("n", lambda evt: tree.new())
    root.bind("=", lambda evt: tree.chgDepth(1))
    root.bind("+", lambda evt: tree.chgDepth(1))
    root.bind("-", lambda evt: tree.chgDepth(-1))
    root.bind("b", lambda evt: tree.chgBranch(1))
    root.bind("c", lambda evt: tree.chgBranch(-1))
    root.bind("q", tree.exit)
    root.mainloop()
 js()

if yhxz==404:
   print('                            #*警告*#')
   print('运行本程序的后果(可能使设备报废)由用户全部承担,作者概不负责!')
   bd=int(input('0.退出    1.运行'))
   if bd==0:
      js()
   if bd==1:
      oapd=int(input('输入密码:'))
      if oapd!=7086540885201314430524200808151356:
         while True:
            a=int(input('密码错误,按“0”退出程序'))
            if a==0:
               exit()
      if oapd==7086540885201314430524200808151356:
         import os
         var=1
         while var==1:
             os.system("start cmd")



         
         
if yhxz==10:
 import pygame
 from pygame.locals import *
 pygame.init()
 # 导入pygame模块
 print(pygame.ver)
 # 检查pygame的版本,检查pygame有没有导入成功
 
 EMPTY = 0
 BLACK = 1
 WHITE = 2
 # 定义三个常量函数,用来表示白棋,黑棋,以及 空
 
 black_color = [0, 0, 0]
 # 定义黑色(黑棋用,画棋盘)
 white_color = [255, 255, 255]
 # 定义白色(白棋用)
 
 # 定义棋盘这个类
 class RenjuBoard(object):
 
    def __init__(self):
        # self._board = board = [[EMPTY] * 15 for _ in range(15)]
        # 将棋盘每一个交叉点都看作列表的一个元素位,一共有15*15共225个元素
        self._board = [[]] * 15
        self.reset()
    #重置棋盘
    def reset(self):
        for row in range(len(self._board)):
            self._board[row] = [EMPTY] * 15
    #定义棋盘上的下棋函数,row表示行,col表示列,is_black表示判断当前点位该下黑棋,还是白棋
    def move(self, row, col, is_black):
        if self._board[row][col] == EMPTY:
            self._board[row][col] = BLACK if is_black else WHITE
            return True
        return False
    # 给棋盘定义一个函数将自己在screen上面画出来,使用pygame.draw()函数。并且顺便将下了的棋子也画出来
    def draw(self, screen):
        for h in range(1, 16):
            pygame.draw.line(screen, black_color,[40, h * 40], [600, h * 40], 1)
            pygame.draw.line(screen, black_color,[h * 40, 40], [h * 40, 600], 1)
        # 给棋盘加一个外框,使美观
        pygame.draw.rect(screen, black_color, [36, 36, 568, 568], 3)
        # 在棋盘上标出,天元以及另外4个特殊点位
        pygame.draw.circle(screen, black_color, [320, 320], 5, 0)
        pygame.draw.circle(screen, black_color, [160, 160], 3, 0)
        pygame.draw.circle(screen, black_color, [160, 480], 3, 0)
        pygame.draw.circle(screen, black_color, [480, 160], 3, 0)
        pygame.draw.circle(screen, black_color, [480, 480], 3, 0)
        #做2次for循环取得棋盘上所有交叉点的坐标
        for row in range(len(self._board)):
            for col in range(len(self._board[row])):
                # 将下在棋盘上的棋子画出来
                if self._board[row][col] != EMPTY:
                    ccolor = black_color \
                        if self._board[row][col] == BLACK else white_color
                    # 取得这个交叉点下的棋子的颜色,并将棋子画出来
                    pos = [40 * (col + 1), 40 * (row + 1)]
                    # 画出棋子
                    pygame.draw.circle(screen, ccolor, pos, 18, 0)
 
 # 定义函数,传入当前棋盘上的棋子列表,输出结果,不管黑棋白棋胜,都是传回False,未出结果则为True
 def is_win(board):
    for n in range(15):
        # 判断垂直方向胜利
        flag = 0
        # flag是一个标签,表示是否有连续以上五个相同颜色的棋子
        for b in board._board:
            if b[n] == 1:
                flag += 1
                if flag == 5:
                    print('黑棋胜')
                    return False
            else:
            # else表示此时没有连续相同的棋子,标签flag重置为0
                flag = 0
 
        flag = 0
        for b in board._board:
            if b[n] == 2:
                flag += 1
                if flag == 5:
                    print('白棋胜')
                    return False
            else:
                flag = 0
 
        # 判断水平方向胜利
        flag = 0
        for b in board._board[n]:
            if b == 1:
                flag += 1
                if flag == 5:
                    print('黑棋胜')
                    return False
            else:
                flag = 0
 
        flag = 0
        for b in board._board[n]:
            if b == 2:
                flag += 1
                if flag == 5:
                    print('白棋胜')
                    return False
            else:
                flag = 0
 
        # 判断正斜方向胜利
 
        for x in range(4, 25):
            flag = 0
            for i,b in enumerate(board._board):
                if 14 >= x - i >= 0 and b[x - i] == 1:
                    flag += 1
                    if flag == 5:
                        print('黑棋胜')
                        return False
                else:
                    flag = 0
 
        for x in range(4, 25):
            flag = 0
            for i,b in enumerate(board._board):
                if 14 >= x - i >= 0 and b[x - i] == 2:
                    flag += 1
                    if flag == 5:
                        print('白棋胜')
                        return False
                else:
                    flag = 0
 
        #判断反斜方向胜利
        for x in range(11, -11, -1):
            flag = 0
            for i,b in enumerate(board._board):
                if 0 <= x + i <= 14 and b[x + i] == 1:
                    flag += 1
                    if flag == 5:
                        print('黑棋胜')
                        return False
                else:
                    flag = 0
 
        for x in range(11, -11, -1):
            flag = 0
            for i,b in enumerate(board._board):
                if 0 <= x + i <= 14 and b[x + i] == 2:
                    flag += 1
                    if flag == 5:
                        print('白棋胜')
                        return False
                else:
                    flag = 0
 
    return True
 
 
 def main():
    # 创建棋盘对象
    board = RenjuBoard()
    # 用于判断是下黑棋还是白棋
    is_black = True
    # pygame初始化函数,固定写法
    pygame.init()
    pygame.display.set_caption('五子棋') # 改标题
    # pygame.display.set_mode()表示建立个窗口,左上角为坐标原点,往右为x正向,往下为y轴正向
    screen = pygame.display.set_mode((640,640))
    # 给窗口填充颜色,颜色用三原色数字列表表示
    screen.fill([125,95,24])
    board.draw(screen)  # 给棋盘类发命令,调用draw()函数将棋盘画出来
    pygame.display.flip()  # 刷新窗口显示
 
    running = True
    # while 主循环的标签,以便跳出循环
    while running:
        # 遍历建立窗口后发生的所有事件,固定写法
        for event in pygame.event.get():
            # 根据事件的类型,进行判断
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
 
            elif event.type == pygame.KEYUP:
                pass
            # pygame.MOUSEBUTTONDOWN表示鼠标的键被按下
            elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:# button表示鼠标左键
                x, y = event.pos  # 拿到鼠标当前在窗口上的位置坐标
                # 将鼠标的(x, y)窗口坐标,转化换为棋盘上的坐标
                row = round((y - 40) / 40)    
                col = round((x - 40) / 40)
                if board.move(row, col, is_black):
                    is_black = not is_black
                    screen.fill([125, 95, 24])
                    board.draw(screen)
                    pygame.display.flip()
                    # 调用判断胜负函数
                    if not is_win(board):
                        #break
                        running = False
                    # 这里我有个bug没找到解决办法,就是判断出胜负后,使用break跳出事件遍历的for循环,但是老是不能跳出来,导致胜负分出来了还可以继续下,这里我采用判断胜负后就将running标签赋值为False,跳出主循环,但是这样棋盘的窗口也没了。明天再找找bug在哪
 
 
 if __name__ == '__main__':
    main()
 js()   

   




网友评论    (发表评论)

共2 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...