[oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列
字体样式
回忆上次内容
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_python](https://file.cfanz.cn/uploads/png/2023/01/31/13/52OG3e6f61.png)
查看细节
- 转化含义
- 转义序列
\033
对应的 字符含义 是Escape
- 从标准输出流 逃逸 出去
- 后面的内容 不是纯文本了
- 而是 控制序列(Control Sequence)
具体控制
Control Sequence Introducer
- 控制序列前导符
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_02](https://file.cfanz.cn/uploads/png/2023/01/29/11/18R8MPI3GX.png)
CSI
之后的是ansi给的关于字体样式的设置细节
- 选择图形渲染 参数
- SGR (Select Graphic Rendition) parameters
具体设置
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_03](https://file.cfanz.cn/uploads/png/2023/02/01/9/1c857dbcN8.png)
1m、0m
\033
是逃逸字符- 1 对应着 增亮或变粗
- 0 对应着 还原
- m 是 固定的格式要求
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_04](https://file.cfanz.cn/uploads/png/2023/02/01/9/V71062fE6W.png)
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_05](https://file.cfanz.cn/uploads/png/2023/02/01/9/LUe3Q1e100.png)
- 我可以 把\033 简化为 \e 么?
- 实践 出 真知
尝试\e
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_06](https://file.cfanz.cn/uploads/png/2023/02/01/9/6403G1caeG.png)
- \033 可以进入 字体控制模式
- \e 目前 在python中 不支持
在shell中
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_python_07](https://file.cfanz.cn/uploads/png/2023/02/01/9/O5dDR707F1.png)
2m
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_08](https://file.cfanz.cn/uploads/png/2023/02/01/9/Cf471ed1OQ.png)
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_python_09](https://file.cfanz.cn/uploads/png/2023/02/01/9/YbdUf79eUO.png)
编写程序
- 文件名 不能是time.py
- 因为 我们要引入的包 叫做time
- time.py 会让 python3 引入自己
import time
for i in range(100):
csi = "\033["
color = str(i % 3)
print(csi + color + "moeasy")
time.sleep(0.2)
代码
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_10](https://file.cfanz.cn/uploads/png/2023/02/01/9/d1feG7fG83.png)
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_11](https://file.cfanz.cn/uploads/png/2023/02/01/9/S13R80cA24.png)
bb
sudo apt install bb
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_12](https://file.cfanz.cn/uploads/png/2023/02/01/9/92eF119368.png)
引入随机
import random
help random
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_python_13](https://file.cfanz.cn/uploads/png/2023/02/01/9/3P29L1XU2d.png)
- random.random() 在 [0,1) 之间
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_14](https://file.cfanz.cn/uploads/png/2023/02/01/9/HBF6bP93NL.png)
- random.random()*2 在 [0,2) 之间
- int(random.random()*2) 得到 整数
随机翻倍
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_15](https://file.cfanz.cn/uploads/png/2023/02/01/9/c0cV27X0aQ.png)
- random.random() 在 (0,1) 之间
- random.random()*2 在 [0,2) 之间
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_16](https://file.cfanz.cn/uploads/png/2023/02/01/9/YdIBScbC64.png)
乱序
import time
import random
while True:
csi= "\033["
color = int(random.random()*3)
num = int(random.random()*2)
print(csi + str(color) + "m" + str(num),end="")
- 亮 \33[1m
- 正常 \33[0m
- 暗 \33[2m
效果
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_python_17](https://file.cfanz.cn/uploads/png/2023/02/01/9/H077V768Xd.png)
纷乱
乱花渐欲迷人眼
浅草才能没马蹄
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义_18](https://file.cfanz.cn/uploads/png/2023/08/10/21/LF1KD1c1aZ.png)
总结
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_19](https://file.cfanz.cn/uploads/png/2023/02/01/9/OFGcf876cT.png)
![图片描述 [oeasy]python0083_[趣味拓展]字体样式_正常_加亮_变暗_控制序列_转义序列_20](https://file.cfanz.cn/uploads/png/2023/02/01/9/1c857dbcN8.png)
- 真的 可以让文字 blink闪烁吗?👁
- 我们下次再说!👋
- 蓝桥->https://www.lanqiao.cn/courses/3584
- github->https://github.com/overmind1980/oeasy-python-tutorial
- gitee->https://gitee.com/overmind1980/oeasypython