标题: [文本处理] 16种颜色值 让它们随机而不冲突 大神能来精减优化一下吗(已解决) [打印本页]
作者: smss 时间: 2019-7-4 15:23 标题: 16种颜色值 让它们随机而不冲突 大神能来精减优化一下吗(已解决)
本帖最后由 smss 于 2019-7-5 07:12 编辑
- @echo off&SetLocal EnableDelayedExpansion
- set Str=0123456789abcdef
- for /l %%a in (1 1 2) do (set /a n = !random! %% 16
- for %%n in (!n!) do set Out=!Str:~%%n,1!)
- for /f "tokens=1* delims=%Out%" %%a in ("%Str%") do (set "Sta=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 15
- for %%n in (!n!) do set Oua=!Sta:~%%n,1!)
- for /f "tokens=1* delims=%Oua%" %%a in ("%Sta%") do (set "Stb=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 14
- for %%n in (!n!) do set Oub=!Stb:~%%n,1!)
- for /f "tokens=1* delims=%Oub%" %%a in ("%Stb%") do (set "Stc=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 13
- for %%n in (!n!) do set Ouc=!Stc:~%%n,1!)
- for /f "tokens=1* delims=%Ouc%" %%a in ("%Stc%") do (set "Std=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 12
- for %%n in (!n!) do set Oud=!Std:~%%n,1!)
- for /f "tokens=1* delims=%Ouf%" %%a in ("%Std%") do (set "Ste=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 11
- for %%n in (!n!) do set Oue=!Ste:~%%n,1!)
- for /f "tokens=1* delims=%Oue%" %%a in ("%Ste%") do (set "Stf=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 10
- for %%n in (!n!) do set Ouf=!Stf:~%%n,1!)
- for /f "tokens=1* delims=%Ouf%" %%a in ("%Stf%") do (set "Stg=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 9
- for %%n in (!n!) do set Oug=!Stg:~%%n,1!)
- for /f "tokens=1* delims=%Oug%" %%a in ("%Stg%") do (set "Sth=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 8
- for %%n in (!n!) do set Ouh=!Sth:~%%n,1!)
- for /f "tokens=1* delims=%Ouh%" %%a in ("%Sth%") do (set "Sti=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 7
- for %%n in (!n!) do set Oui=!Sti:~%%n,1!)
- for /f "tokens=1* delims=%Oui%" %%a in ("%Sti%") do (set "Stj=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 6
- for %%n in (!n!) do set Ouj=!Stj:~%%n,1!)
- for /f "tokens=1* delims=%Ouj%" %%a in ("%Stj%") do (set "Stk=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 5
- for %%n in (!n!) do set Ouk=!Stk:~%%n,1!)
- for /f "tokens=1* delims=%Ouk%" %%a in ("%Stk%") do (set "Stl=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 4
- for %%n in (!n!) do set Oul=!Stl:~%%n,1!)
- for /f "tokens=1* delims=%Oul%" %%a in ("%Stl%") do (set "Stm=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 3
- for %%n in (!n!) do set Oum=!Stm:~%%n,1!)
- for /f "tokens=1* delims=%Oum%" %%a in ("%Stm%") do (set "Stn=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 2
- for %%n in (!n!) do set Oun=!Stn:~%%n,1!)
- for /f "tokens=1* delims=%Oun%" %%a in ("%Stn%") do (set "Sto=%%a%%b")
- for /l %%a in (1 1 2) do (set /a n = !random! %% 1
- for %%n in (!n!) do set Ouo=!Sto:~%%n,1!)
- echo %Out%
- echo %Oua%
- echo %Oub%
- echo %Ouc%
- echo %Oud%
- echo %Oue%
- echo %Ouf%
- echo %Oug%
- echo %Ouh%
- echo %Oui%
- echo %Ouj%
- echo %Ouk%
- echo %Oul%
- echo %Oum%
- echo %Oun%
- echo %Ouo%
- color !Out!!Oua!
- Tools\ctext {!Out!!Oua!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oub!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Ouc!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oud!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oue!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Ouf!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oug!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Ouh!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oui!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Ouj!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Ouk!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oul!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oum!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Oun!} 1.截屏到桌面{\n}
- Tools\ctext {!Out!!Ouo!} 1.截屏到桌面{\n}
- pause
复制代码
我写的不够好 背景为一种随机颜色值 前景文字为16-1后的15种随机颜色值 但是会每用一次便会随机一次
前景文字颜色用第三方工具 ctext 表达式{04} 0是背景 4是文字
作者: xczxczxcz 时间: 2019-7-4 18:08
随便玩一下:结果值自己套用,看是不是你要的。- @Echo Off & cd /d "%~dp0"
- SetLocal EnableDelayedExpansion
-
- set "Color=0123456789ABCDEF"
- set /a n=%random% %% 16
- set "BackColor=!Color:~%n%,1!"
- for /f "tokens=1,2 delims=%BackColor%" %%a in ("%Color%") do set "Color=%%a%%b"
-
- set/a m=15
- :LOOP
- set/a n=%random% %% %m%
- set "ColTmp=!Color:~%n%,1!"
- for /f "tokens=1,2 delims=%ColTmp%" %%a in ("%Color%") do set "Color=%%a%%b"
- set "_COL%m%=%BackColor%%ColTmp%"
- if %m% geq 2 (set/a m-=1 &goto LOOP)
-
- set _COL
- Pause
复制代码
----------PS---------------- $颜色字符 ='0123456789ABCDEF';
- $背景色 =Get-Random -input ([Char[]]$颜色字符);
- $颜色字符 =$颜色字符 -replace $背景色;
-
- $颜色 = While ( ([Char[]]$颜色字符).Count -gt 0 ) {
- $前景色 =Get-Random -input ([Char[]]$颜色字符);
- [string]::Concat($背景色,$前景色);
- $颜色字符 =$颜色字符 -replace $前景色;
- }
- $颜色;
- cmd /c Pause
复制代码
作者: cfwyy77_bat 时间: 2019-7-5 08:43
python代码,只是生成随机颜色,未考虑其它。- import random
- s="0123456789abcdef"
- fg=random.sample(s,15) #先随机的不重复的 15个前景
- bg=(set(s)-set(fg)).pop() # 余下的一个作背景
- res=["{}{}".format(bg,i) for i in fg]
- print(res)
复制代码
随机结果:- ['5b', '56', '5f', '5d', '54', '5a', '53', '5c', '51', '50', '58', '57', '5e', '59', '52']
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |