Commit 6fb86a92 by BellCodeEditor

auto save

parent 98f24605
a='hello'
b='world'
print('a'+b)
\ No newline at end of file
# #turtle画图模块
# import()#导入模块
# turtle#画图模块
# print()#输出打印
# forward()#移动
# shape()#形状
# left()#左转
# right()#右转
# fillcolor()#设置填充颜色
# begin_fill()#开始填充颜色
# end_fill()#结束填充颜色
# hideturtle()#隐藏画笔
# pensize()#画笔粗细
# pen.circle()#画圆
# turtle.done()#保存画布
# #random随机模块
# randome()#随机模块
# choice()#序列取随机
# randome()#在0和1之间取17位随机小数
# randint()#取范围随机
# input()#询问模块
# if():#条件分支语句
# elif():
# else()
# #数据类型
# 1·元组数据
# 2·字符串
# 2·1·文本(str)
# 3·字符
# 3·1·整型(int)
# 3·2·浮点型(float)
# #while循环
# break#跳出循环
# continue#结束本次循环
# #for循环
# for i in range()#有限循环
# range()#生成序列、范围
# #列表list
# #列表增加:
# 1·insert()#通过索引在指定项添加数据
# 2·append()#在列表最后添加一个参数
# 3·extend()#将新参数与列表进行融合产生新的列表
# #列表删除:
# 1·pop()#通过索引删除指定项
# 2·remove()#通过指定数据删除从左到右的第一个相同数值
# 3·切片#通过索引范围进行指定取出
# #字符串
# 1·for循环遍历
# 2·字符串的切片、索引
# 3·字符串插入子串
# 4·列表以及字符串的相互转化
# .join()#修改列表分隔符
import turtle
p=turtle.Pen()
for i in range(5):
p.forward(100)
p.left(144)
turtle.done()
# a=0
# a=a+5
# list=[a,b,c,d,e]
# print(list[0:3])
\ No newline at end of file
import tkinter as tk
import random
import threading
import time
def dow():
window = tk.Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
a = random.randrange(0, width)
b = random.randrange(0, height)
window.title('七夕快乐') # 弹窗的名字,都可以修改的
window.geometry("200x50" + "+" + str(a) + "+" + str(b)) # 弹窗大小,不建议修改
tk.Label(window,
text='!', # 标签的文字,随便改
bg='pink', # 背景颜色
font=('楷体', 17), # 字体和字体大小
width=15, height=2 # 标签长宽
).pack() # 固定窗口位置
window.mainloop()
threads = []
for i in range(80): # 需要的弹框数量,别太多了,电脑不好的话怕你死机
t = threading.Thread(target=dow)
threads.append(t)
time.sleep(0.1)
threads[i].start()
\ No newline at end of file
import pygame, math, time, random, os
from sys import exit
WINDOW_W = 940
WINDOW_H = 620
one_time = 0.18 #时间流速
show_n = 0
show_frequency = 0.0015 #烟花绽放频率,数值越大频率越高
color_list = [
[255, 50, 50],
[50, 255, 50],
[50, 50, 255],
[255, 255, 50],
[255, 50, 255],
[50, 255, 255],
[255, 255, 255]
]
# 初始化pygame,为使用硬件做准备
pygame.init()
pygame.mixer.init()
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (150,50)
# 创建一个窗口
screen = pygame.display.set_mode((WINDOW_W, WINDOW_H), pygame.DOUBLEBUF, 32)
pygame.display.set_caption("烟花")
# pygame.time.delay(1000)#等待1秒让mixer完成初始化
#sound_wav = pygame.mixer.music.load("yanhua.mp3")
#pygame.mixer.music.play()
class Yanhua():
is_show = False
x, y = 0, 0
vy = 0
p_list = []
color = [0, 0, 0]
v = 0
def __init__(self, x, y, vy, n=300, color=[0, 255, 0], v=10):
self.x = x
self.y = y
self.vy = vy
self.color = color
self.v = v
# self.is_show = True
for i in range(n):
self.p_list.append([random.random() * 2 * math.pi, 0, v * math.pow(random.random(), 1 / 3)])
def chongzhi(self):
self.is_show = True
self.x = random.randint(WINDOW_W // 2 - 350, WINDOW_W // 2 + 350)
self.y = random.randint(int(WINDOW_H / 2), int(WINDOW_H * 3 / 5))
self.vy = -40 * (random.random() * 0.4 + 0.8) - self.vy * 0.2
self.color = color_list[random.randint(0, len(color_list) - 1)].copy()
n = len(self.p_list)
self.p_list = []
for i in range(n):
self.p_list.append([random.random() * 2 * math.pi, 0, self.v * math.pow(random.random(), 1 / 3)])
def run(self):
global show_n
for p in self.p_list:
p[1] = p[1] + (random.random() * 0.6 + 0.7) * p[2]
p[2] = p[2] * 0.97
if p[2] < 1.2:
self.color[0] *= 0.9999
self.color[1] *= 0.9999
self.color[2] *= 0.9999
if max(self.color) < 10 or self.y>WINDOW_H+p[1]:
show_n -= 1
self.is_show = False
break
self.vy += 10 * one_time
self.y += self.vy * one_time
yh_list = []
yh_list.append(Yanhua(300, 300, -20, n=100, color=[0, 255, 0], v=10))
yh_list.append(Yanhua(300, 300, -20, n=200, color=[0, 0, 255], v=11))
yh_list.append(Yanhua(300, 300, -20, n=200, color=[0, 0, 255], v=12))
yh_list.append(Yanhua(300, 300, -20, n=500, color=[0, 0, 255], v=12))
yh_list.append(Yanhua(300, 300, -20, n=600, color=[0, 0, 255], v=13))
yh_list.append(Yanhua(300, 300, -20, n=700, color=[255, 0, 0], v=15))
yh_list.append(Yanhua(300, 300, -20, n=800, color=[255, 255, 0], v=18))
clock = pygame.time.Clock()
# 游戏主循环
while True:
# if not pygame.mixer.music.get_busy():
# pygame.mixer.music.play()
for event in pygame.event.get():
if event.type == pygame.QUIT:
# 接收到退出时间后退出程序
exit()
# 将背景图画上去
screen.fill((0, 0, 0))
# 放烟花
for i, yh in enumerate(yh_list):
if not yh.is_show:
yh.is_show = False
if random.random() < show_frequency * (len(yh_list) - show_n):
show_n += 1
yh.chongzhi()
continue
yh.run()
for p in yh.p_list:
x, y = yh.x + p[1] * math.cos(p[0]), yh.y + p[1] * math.sin(p[0])
if random.random() < 0.055:
screen.set_at((int(x), int(y)),(255,255,255))
else:
screen.set_at((int(x), int(y)), (int(yh.color[0]), int(yh.color[1]), int(yh.color[2])))
# 刷新画面
pygame.display.update()
# 返回上一个调用的时间(ms)
time_passed = clock.tick(50)
\ No newline at end of file
import pygame
import random
import math
pygame.init()
pygame.mixer.init()
pygame.font.init()
WIN_W = 2200
WIN_H = 1300
t1 = 0.18 # 时间流速
show_n = 0
show_frequency = 0.0015 # 烟花绽放频率,数值越大频率越高
color_list = [255, 0, 0]
yanhua_map = {}
fk_list = []
class Fireworks():
is_show = False
x, y = 0, 0
vy = 0
p_list = []
color = [0, 0, 0]
v = 0
def __init__(self, x, y, vy, n=300, color=[0, 255, 0], v=10):
self.x = x
self.y = y
self.vy = vy
self.color = color
self.v = v
for i in range(n):
self.p_list.append([random.random() * 2 * math.pi, 0, v * math.pow(random.random(), 1 / 3)])
def run(self):
global show_n
for p in self.p_list:
p[1] = p[1] + (random.random() * 0.6 + 0.7) * p[2]
p[2] = p[2] * 0.97
if p[2] < 1.2:
self.color[0] *= 0.9999
self.color[1] *= 0.9999
self.color[2] *= 0.9999
if max(self.color) < 10 or self.y > WIN_H + p[1]:
show_n -= 1
self.is_show = False
break
self.vy += 10 * t1
self.y += self.vy * t1
else:
self.vy += 10 * t1
self.y += self.vy * t1
def random_color(l, r):
return [random.randint(l, r), random.randint(l, r), random.randint(l, r)]
def red_random(l, r):
return [255, random.randint(l, r), random.randint(l, r)]
def init_yanhua(bg_size):
yanhua_list = []
for i in range(5):
x_site = random.randrange(0, WIN_W) # 雪花圆心位置
y_site = WIN_H # 雪花圆心位置
X_shift = 0 # x 轴偏移量
radius = random.randint(6, 10) # 半径和 y 周上升降量
xxxxx = random_color(150, 255)
red = xxxxx[0]
green = xxxxx[1]
blue = xxxxx[2]
yanhua_list.append([x_site, y_site, X_shift, radius, red, green, blue])
return yanhua_list
def init_xue(bg_size):
snow_list = []
for i in range(200):
x_site = random.randrange(0, bg_size[0]) # 雪花圆心位置
y_site = random.randrange(0, bg_size[1]) # 雪花圆心位置
X_shift = random.randint(-1, 1) # x 轴偏移量
radius = random.randint(4, 6) # 半径和 y 周下降量
xxxxx = random_color(150, 255)
# red = xxxxx[0]
# green = xxxxx[1]
# blue = xxxxx[2]
snow_list.append([x_site, y_site, X_shift, radius, 255, 255, 255])
return snow_list
def draw_xue(snow_list: [], screen, bg_size: [], grand_has: set, grand_list: []):
# 雪花列表循环
# todo 空中的雪
for i in range(len(snow_list)):
# 绘制雪花,颜色、位置、大小
pygame.draw.circle(screen, (snow_list[i][4], snow_list[i][5], snow_list[i][6]), snow_list[i][:2],
snow_list[i][3] - 3)
# 移动雪花位置(下一次循环起生效)
snow_list[i][0] += snow_list[i][2]
snow_list[i][1] += snow_list[i][3]
# 如果雪落出屏幕,重设位置
if snow_list[i][1] > bg_size[1]:
# tmp = []
snow_list[i][1] = random.randrange(-50, -10)
snow_list[i][0] = random.randrange(0, bg_size[0])
x = snow_list[i][0]
while (grand_has.__contains__(x * 10000 + y)):
y = y - snow_list[i][3]
grand_has.add(x * 10000 + y)
grand_list.append(
[x, y, snow_list[i][2], snow_list[i][3], snow_list[i][4], snow_list[i][5],
snow_list[i][6]])
def draw_yanhua(yanhua_list: [], screen, bg_size: []):
global fk_list
for i in range(len(yanhua_list)):
# 绘制雪花,颜色、位置、大小
pygame.draw.circle(screen, (yanhua_list[i][4], yanhua_list[i][5], yanhua_list[i][6]), yanhua_list[i][:2],
yanhua_list[i][3] - 3)
# 移动雪花位置(下一次循环起生效)
yanhua_list[i][0] += yanhua_list[i][2]
yanhua_list[i][1] -= yanhua_list[i][3]
# 如果雪花落出屏幕,重设位置
if yanhua_list[i][1] <= 0:
# tmp = []
yanhua_list[i][1] = WIN_H
yanhua_list[i][0] = random.randrange(0, bg_size[0])
if yanhua_list[i][1] <= random.randint(200, 400):
# todo 放烟花
fk = Fireworks(yanhua_list[i][0], yanhua_list[i][1], -20, n=300, color=red_random(1, 150), v=10)
fk_list.append(fk)
yanhua_list[i][1] = WIN_H
yanhua_list[i][0] = random.randrange(0, bg_size[0])
def show_shi(a: list, n, screen):
i = 2 * n - 1
j = 2 * n
if i >= len(a):
i = len(a) - 2
if j >= len(a):
j = len(a) - 1
if i >= 0:
myfont = pygame.font.SysFont(simHei, 30)
textsurface = myfont.render(a[i], False, random_color(150, 255))
screen.blit(textsurface, (WIN_W / 2, 30))
if j >= 0:
myfont = pygame.font.SysFont(simHei, 100)
textsurface = myfont.render(a[j], False, red_random(1, 1))
screen.blit(textsurface, (WIN_W / 2 - 200, 50))
def main():
global show_n
global fk_list
bg_size = (WIN_W, WIN_H)
screen = pygame.display.set_mode(bg_size)
pygame.display.set_caption("新年快乐")
# bg = pygame.image.load(bg_img)
#pygame.mixer.music.load(D:\\CloudMusic\\小时姑娘 - 霞光\\《精灵世纪》片尾曲.mp3)
grand_list = []
font_values = ['新年快乐']
grand_has = set()
clock = pygame.time.Clock()
yanhua_list = init_yanhua(bg_size)
snow_list = init_xue(bg_size)
while True:
# if not pygame.mixer.music.get_busy():
# pygame.mixer.music.play()
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
screen.fill((0, 0, 0))
draw_yanhua(yanhua_list, screen, bg_size)
if len(fk_list) != 0:
print(len(fk_list))
show_shi(font_values, 0, screen)
for fk in fk_list:
fk.run()
for p in fk.p_list:
x, y = fk.x + p[1] * math.cos(p[0]), fk.y + p[1] * math.sin(p[0])
if random.random() < 0.055:
screen.set_at((int(x), int(y)), (255, 255, 255))
else:
screen.set_at((int(x), int(y)), (int(fk.color[0]), int(fk.color[1]), int(fk.color[2])))
tmp = []
for fk in fk_list:
for p in fk.p_list:
x, y = fk.x + p[1] * math.cos(p[0]), fk.y + p[1] * math.sin(p[0])
if y < WIN_H - 1000:
tmp.append(fk)
break
fk_list = tmp
min_height = 100000
for i in range(len(grand_list)):
if grand_list[i][0] < 375:
min_height = min(min_height, grand_list[i][1])
draw_xue(snow_list, screen, bg_size, grand_has, grand_list)
for i in range(len(grand_list)):
pygame.draw.circle(screen, (grand_list[i][4], grand_list[i][5], grand_list[i][6]), grand_list[i][:2],
grand_list[i][3] - 3)
for i in range(len(grand_list)):
pygame.draw.circle(screen, (grand_list[i][4], grand_list[i][5], grand_list[i][6]), grand_list[i][:2],
grand_list[i][3])
pygame.display.update()
time_passed = clock.tick(50)
if __name__ == '__main__':
main()
\ No newline at end of file
a=0
while True:
if a>1:
print('hello ward')
\ No newline at end of file
a=int(input('请输入长'))
b=int(input('请输入宽'))
print('这是面积:',a*b)
print('这是周长:',(a+b)*2)
\ No newline at end of file
# 这是悟空为花果山小猴做臂力测试的程序代码 # 这是悟空为花果山小猴做臂力测试的程序代码
name=input('你叫啥名啊?') #name=input('你叫啥名啊?')
power=int(input('你臂力多少啊?')) #power=int(input('你臂力多少啊?'))
list_hero=['猴三',10,'猴一',21,'猴五',22,'猴队长',29,'猴七',30] #list_hero=['猴三',10,'猴一',21,'猴五',22,'猴队长',29,'猴七',30]
for i in range(len(list_hero)): #for i in range(len(list_hero)):
if i%2==1 and list_hero[i]>=power: #if i%2==1 and list_hero[i]>=power:
list_hero.insert(i-1,name) #list_hero.insert(i-1,name)
list_hero.insert(i,power) #list_hero.insert(i,power)
break #break
print(list_hero) #print(list_hero)
# 请注释掉上面的代码,并在下一行创建一个名为dict_hero的字典 # 请注释掉上面的代码,并在下一行创建一个名为dict_hero的字典
dict_hero= dict_hero={'猴三':10,'猴一':21,'猴五':22,'猴队长':29,'猴七':30}
print(dict_hero) print(dict_hero)
# 直接运行以下代码,说说你的发现: # turtle画图模块
list_hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98] # import#导入模块
dict_hero = {'赵一':30,'丁二':37,'孙五':52,'王猛':89,'周亮':98} # 函数:表达了数字与某种事物之间的联系
print(len(list_hero)) # print('hello'+3)#输出打印
print(len(dict_hero)) # pen=turtle.Pen()#赋值画笔给变量
\ No newline at end of file # pen.forward(100)#移动——.表示从属关系
# goto()#移到坐标
# right(30)#右转、顺时针旋转
# left(30)#左转、逆时针旋转
# pencolor()#设置画笔颜色、设置轮廓颜色
# fillcolor()#填充颜色
# begin_fill()#开始填充
# end_fill()#结束填充
# pensize()#画笔粗细
# penshap()#画笔造型
# circle(半径,夹角)#画弧形
# turtle.done()#保存画布
# hideturtle()#隐藏画笔
# random#随机模块
# random.chioce()#列表随机(0,1,2,3,4,5)
# random()#在0和1之间取16位小数随机
# randint()#取范围随机(0,5)
# input()#询问输入:a=input()#将答案赋值给变量
# #答案全部都是字符串
# if():#条件分支结构
# elif():
# else()
#数据类型
# 字符:int(整型)、float(浮点)
# 字符串:str(文本)
# a=int(input())
# while#条件循环
# while True:
# not:
# if:
# break#跳出循环
# continue#停止本次循环
# for循环
# for i#变量 in range()#可迭代容器:
# 外层执行一次,内层执行一遍
# 列表
# 列表增加:1·insert()#通过索引在指定项增加参数
# 2·extend()#通过与列表进行融合产生新的列表
# 3·append()#在列表末尾添加参数
# 列表删除:1·remove()#从左到右删除第一个特定参数
# 2·pop()#通过所属的索引指定删除
# 3·切片#范围取值
# 3·1:取左不取右,不写全都取
# [x:y]、[:y]、[x:]、[:]
字符串
遍历:
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment