大家好!给你们带来了几个实用黑客特效实例,可以在朋友面前展示一下自己。
基础实例:
import os
for root, dirs, files in os.walk('/'):
for directory indirs:
print(os.path.join(root, directory))
2.0:
import os
from colorama import init, Fore, Back, style
# 初始化 colorama 模块
init()
for root, dirs, files in os.walk('/'):
for directory in dirs:
print(Fore.GREEN + os.path.join(root, directory))
3.0:
import os
import random
import time
from colorama import init, Fore, Back, style
# 初始化 colorama 模块
init()
defprint_hacker_ style(text):
for char in text:
if char == " ":
print(char, end='', flush=True)
time.sleep(0.01)
else:
print(Fore.GREEN + str(random.randint(0, 1)), end='', flush=True)
time.sleep(0.01)
print( style.RESET_ALL)
for root, dirs, files in os.walk('/'):
for directory in dirs:
path = os.path.join(root, directory)
print_hacker_ style(path)
黑客帝国效果:
import os
import random
import time
import shutil
from colorama import init, Fore
# 初始化 colorama 模块
init()
# 获取终端窗口的大小
defget_terminal_size():
columns, rows = shutil.get_terminal_size()
return rows, columns
# 清屏并定位光标位置
defreset_screen_position(rows, columns):
print('\033[{};{}H'.format(rows, 1), end='', flush=True)
# 清屏
defclear_screen():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
# 输出随机字符
defprint_random_char():
chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#', '^', '&', '%']
colors = [Fore.GREEN, Fore.WHITE, Fore.CYAN, Fore.LIGHTGREEN_EX]
random_char = random.choice(chars)
random_color = random.choice(colors)
print(random_color + random_char, end='', flush=True)
# 主程序
defrun_program():
clear_screen()
whileTrue:
rows, columns = get_terminal_size()
reset_screen_position(rows, columns)
for i in range(rows * columns):
print_random_char()
time.sleep(0.1)
run_program()
装逼神器:
import time
from colorama import init, Fore, style
from faker import Faker
init() # 初始化 colorama
defprint_effect(text):
for char in text:
print(Fore.GREEN + char, end="", flush=True)
time.sleep(0.05)
print( style.RESET_ALL) # 恢复终端颜色
# 创建 faker 对象
fake = Faker()
# 生成和打印随机信息
whileTrue:
# 随机生成信息
name = fake.name()
address = fake.address()
phone_number = fake.phone_number()
# 将信息合并成一个字符串,并在开头和结尾使用 "-" 进行框起来
info = f"姓名: {name}\n 地址: {address}\n 电话: {phone_number} "
# 使用特效打印信息
print_effect(info)
# 使用 "$$" 进行分隔
print(Fore.YELLOW + "$$" + style.RESET_ALL)