大家好!給你們帶來了幾個實用黑客特效例項,可以在朋友面前展示一下自己。
基礎例項:
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)