1
+ :graphicsFunctions
2
+
3
+ if not defined wid (
4
+ for /f " skip=2 tokens=2" %%a in ('mode') do (if not defined hei (set /a " hei=height=%%a " ) else if not defined wid (set /a " wid=width=%%a " ))
5
+ )
6
+
7
+ for /f %%a in ('echo prompt $E^ | cmd') do set " \e = %%a "
8
+
9
+ (set \n=^^ ^
10
+ %= This creates an escaped Line Feed - DO NOT ALTER =%
11
+ )
12
+
13
+ set " @32bitlimit = 0x7FFFFFFF"
14
+
15
+ for /l %%i in (0,1,5) do set " barBuffer = !barBuffer!!barBuffer! " & set " boxBuffer = !boxBuffer!!boxBuffer! Ä"
16
+ set " sin = (a=((x*31416/180)%% 62832)+(((x*31416/180)%% 62832)>>31&62832), b=(a-15708^ a-47124)>>31,a=(-a&b)+(a&~b)+(31416&b)+(-62832&(47123-a>>31)),a-a*a/1875*a/320000+a*a/1875*a/15625*a/16000*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000) / 10000"
17
+ set " cos = (a=((15708-x*31416/180)%% 62832)+(((15708-x*31416/180)%% 62832)>>31&62832), b=(a-15708^ a-47124)>>31,a=(-a&b)+(a&~b)+(31416&b)+(-62832&(47123-a>>31)),a-a*a/1875*a/320000+a*a/1875*a/15625*a/16000*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000) / 10000"
18
+
19
+ For /l %%i in (1 1 4)Do Set " loop = !Loop! For /l %% # in (1 1 16)Do if not defined Stop "
20
+ set " delay = for /l %% # in (1,x,1000000) do rem"
21
+
22
+ set " pixel = Û"
23
+
24
+ :_concat
25
+ rem %concat% x y "string" outputVar
26
+ set @concat = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-4" %% 1 in (" ^!args^! " ) do (%\n%
27
+ set " %%~4 = ^ !%%~4^!%\e% [%% ~2;%% ~1H%% ~3" %\n%
28
+ )) else set args =
29
+
30
+ :_background
31
+ REM %@background% color1 color2 lineColor2Starts
32
+ set @background = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-4" %% 1 in (" ^!args^! " ) do (%\n%
33
+ set " $background = %\e% [48;5;%% ~1m%\e% [0J%\e% [%% ~3H%\e% [48;5;%% ~2m%\e% [0J" %\n%
34
+ )) else set args =
35
+
36
+ :_fullscreen
37
+ rem %@fullscreen%
38
+ set " @fullScreen = (title batchfs) ^ & Mshta.exe vbscript:Execute(" Set Ss = CreateObject(" " WScript.Shell" " ):Ss.AppActivate " " batchfs" " :Ss.SendKeys " " {F11}" " :close" ) ^& !@getdim! "
39
+
40
+ :_plot
41
+ rem %plot% y;x 2/5;0-255;0-255;0-255
42
+ set @plot = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-2" %% 1 in (" ^!args^! " ) do (%\n%
43
+ set " $plot = ^ !$plot^!%\e% [48;%% 2m%\e% [%% 1H %\e% [0m" %\n%
44
+ )) else set args =
45
+
46
+ :_construct
47
+ rem %%~1:NAME %%~2:end/optional %%~3:ID/optional < rtn> %%~1[n].ATTRIBUTES
48
+ set @construct = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-3" %% 1 in (" ^!args^! " ) do (%\n%
49
+ if /i " %% ~2" neq " purge" (%\n%
50
+ if not defined %% ~1.length set /a " %%~ 1.length = - 1" %\n%
51
+ set /a " %%~1.length += 1" %\n%
52
+ set " %%~1.list = ^ !%%~1.list^! ^ !%%~1.length^! " %\n%
53
+ for %%j in (^^!%% ~1.length^^! ) do (%\n%
54
+ set /a " %%~ 1[%%j].x = ^ ! random^ ! %% wid" %\n%
55
+ set /a " %%~ 1[%%j].y = ^ ! random^ ! %% hei" %\n%
56
+ set /a " %%~ 1[%%j].deg = ^ ! random^ ! %% 360" %\n%
57
+ set /a " %%~ 1[%%j].mag = ^ ! random^ ! %% 2 + 1" %\n%
58
+ set /a " %%~ 1[%%j].i = (^ ! random^ ! %% 2 * 2 - 1) * %%~ 1[%%j ].mag" %\n%
59
+ set /a " %%~ 1[%%j].j = (^ ! random^ ! %% 2 * 2 - 1) * %%~ 1[%%j ].mag" %\n%
60
+ )%\n%
61
+ ) else (%\n%
62
+ if " %% ~3" equ " " (%\n%
63
+ for %%j in (^^!%% ~1.length^^! ) do (%\n%
64
+ for /l %%k in (0,1,%%j ) do (%\n%
65
+ for %%i in (x y i j deg mag) do set " %%~1[%%k].%%i = " %\n%
66
+ )%\n%
67
+ set " %%~1.length = " %\n%
68
+ set " %%~1.list = " %\n%
69
+ )%\n%
70
+ ) else (%\n%
71
+ if " ^!%%~1.list^! " neq " ^!%%~1.list:%% ~3 =^ ! " (%\n%
72
+ set " %%~1.list = ^ !%%~1.list:%% ~3 =^ ! " %\n%
73
+ for %%i in (x y i j deg mag) do set " %%~1[%%~3].%%i = " %\n%
74
+ set /a " %%~1.length -= 1" %\n%
75
+ )%\n%
76
+ )%\n%
77
+ )%\n%
78
+ )) else set args =
79
+
80
+ :_getDistance
81
+ rem %getDistance% x2 x1 y2 y1 < rtnVar>
82
+ set @getDistance = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-5" %% 1 in (" ^!args^! " ) do (%\n%
83
+ set /a " %% 5 = ( ? = ((((((%% 1 - %% 2))>> 31| 1)* ((%% 1 - %% 2)))- ((((%% 3 - %% 4))>> 31| 1)* ((%% 3 - %% 4))))>> 31)+ 1, ?* (2* ((((%% 1 - %% 2))>> 31| 1)* ((%% 1 - %% 2)))- ((((%% 3 - %% 4))>> 31| 1)* ((%% 3 - %% 4)))- (((((%% 1 - %% 2))>> 31| 1)* ((%% 1 - %% 2)))- ((((%% 3 - %% 4))>> 31| 1)* ((%% 3 - %% 4))))) + ^^^ ! ?* (((((%% 1 - %% 2))>> 31| 1)* ((%% 1 - %% 2)))- ((((%% 3 - %% 4))>> 31| 1)* ((%% 3 - %% 4)))- (((((%% 1 - %% 2))>> 31| 1)* ((%% 1 - %% 2)))- ((((%% 3 - %% 4))>> 31| 1)* ((%% 3 - %% 4)))* 2)) )" %\n%
84
+ )) else set args =
85
+
86
+ :_pow
87
+ rem %pow% num pow < rtnVar>
88
+ for /l %%a in (1,1,30) do set " pb = !pb! x*"
89
+ set @pow = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-3" %% 1 in (" ^!args^! " ) do (%\n%
90
+ set /a " x = %%~ 1","$p = %%~ 2* 2- 1" %\n%
91
+ for %%a in (^^! $p^^! ) do set /a " %%~ 3 = ^ ! pb:~ 0,%%a ^ ! " %\n%
92
+ )) else set args =
93
+
94
+ :_circle
95
+ rem %circle% x y ch cw < rtn> $circle
96
+ set @circle = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-4" %% 1 in (" ^!args^! " ) do (%\n%
97
+ set " $circle = %\e% [48;5;15m" %\n%
98
+ for /l %%a in (0,3,360) do (%\n%
99
+ set /a " xa = %%~ 3 * ^ ! cos:x = %%a ^ ! + %%~ 1" , " ya = %%~ 4 * ^ ! sin:x = %%a ^ ! + %%~ 2" %\n%
100
+ set " $circle = ^ !$circle^!%\e% [^ !ya^! ;^ !xa^! H " %\n%
101
+ )%\n%
102
+ set " $circle = ^ !$circle^!%\e% [0m" %\n%
103
+ )) else set args =
104
+
105
+ :_rect
106
+ rem %rect% x y w h < rtn> $rect
107
+ for /l %%i in (0,1,5) do set " qBuffer = !qBuffer!!qBuffer! q"
108
+ set @rect = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-4" %% 1 in (" ^!args^! " ) do (%\n%
109
+ set " $rect = %\e% [%% ~2;%% ~1H%\e% (0%\e% 7l^ !qBuffer:~0 ,%%~3 ^! k%\e% 8%\e% [B" %\n%
110
+ for /l %%i in (1,1,%% ~4) do set " $rect = ^ !$rect^!%\e% 7x%\e%%\e% [%% ~3Cx%\e% 8%\e% [B" %\n%
111
+ set " $rect = ^ !$rect^! m^ !qBuffer:~0 ,%%~3 ^! j%\e%%\e% (B%\e%%\e% [0m" %\n%
112
+ )) else set args =
113
+
114
+ :_line
115
+ rem line x0 y0 x1 y1 color
116
+ set @line = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-5" %% 1 in (" ^!args^! " ) do (%\n%
117
+ if " %% ~5" equ " " ( set " hue = 15" ) else ( set " hue = %% ~5" )%\n%
118
+ set " $line = %\e% [48;5;^ !hue^! m" %\n%
119
+ set /a " xa = %%~ 1" , " ya = %%~ 2" , " xb = %%~ 3" , " yb = %%~ 4" , " dx = %%~ 3 - %%~ 1" , " dy = %%~ 4 - %%~ 2" %\n%
120
+ if ^^! dy^^! lss 0 ( set /a " dy = - dy" , " stepy = - 1" ) else ( set " stepy = 1" )%\n%
121
+ if ^^! dx^^! lss 0 ( set /a " dx = - dx" , " stepx = - 1" ) else ( set " stepx = 1" )%\n%
122
+ set /a " dx <<= 1" , " dy <<= 1" %\n%
123
+ if ^^! dx^^! gtr ^^! dy^^! (%\n%
124
+ set /a " fraction = dy - (dx >> 1)" %\n%
125
+ for /l %%x in (^^! xa^^! ,^^! stepx^^! ,^^! xb^^! ) do (%\n%
126
+ if ^^! fraction^^! geq 0 set /a " ya += stepy" , " fraction -= dx" %\n%
127
+ set /a " fraction += dy" %\n%
128
+ set " $line = ^ !$line^!%\e% [^ !ya^! ;%%x H " %\n%
129
+ )%\n%
130
+ ) else (%\n%
131
+ set /a " fraction = dx - (dy >> 1)" %\n%
132
+ for /l %%y in (^^! ya^^! ,^^! stepy^^! ,^^! yb^^! ) do (%\n%
133
+ if ^^! fraction^^! geq 0 set /a " xa += stepx" , " fraction -= dy" %\n%
134
+ set /a " fraction += dx" %\n%
135
+ set " $line = ^ !$line^!%\e% [%%y ;^ !xa^! H " %\n%
136
+ )%\n%
137
+ )%\n%
138
+ set " $line = ^ !$line^!%\e% [0m" %\n%
139
+ )) else set args =
140
+
141
+ :_bezier
142
+ rem %bezier% x1 y1 x2 y2 x3 y3 x4 y4
143
+ set @bezier = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-8" %% 1 in (" ^!args^! " ) do (%\n%
144
+ set " $bezier = %\e% [48;5;15m" %\n%
145
+ set /a " A = %%~ 1","B = %%~ 2","C = %%~ 3","D = %%~ 4","E = %%~ 5","F = %%~ 6","G = %%~ 7","H = %%~ 8","I = C-A","J = E-C","K = G-E","L = D-B","M = F- D" %\n%
146
+ for /l %% . in (1,1,50) do (%\n%
147
+ set /a " _ = %% .<<1,N = ((A+_*I*10)/1000+A),O = ((C+_*J*10)/1000+C),P = ((B+_*L*10)/1000+B),Q = ((N+_*(O-N)*10)/1000+N),S = ((D+_*M*10)/1000+D),T = ((P+_*(S-P)*10)/1000+P),vx = (Q+_*(((O+_*(((E+_*K*10)/1000+E)-O)*10)/1000+O)-Q)*10)/1000+Q,vy = (T+ _* (((S+ _* (((F+ _* (H- F)* 10)/ 1000+ F)- S)* 10)/ 1000+ S)- T)* 10)/ 1000+ T" %\n%
148
+ set " $bezier = ^ !$bezier^!%\e% [^ !vy^! ;^ !vx^! H " %\n%
149
+ )%\n%
150
+ )) else set args =
151
+
152
+ :_arc
153
+ rem arc x y size DEGREES(0-360) arcRotationDegrees(0-360) lineThinness color
154
+ set @arc = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-7" %% 1 in (" ^!args^! " ) do (%\n%
155
+ set " $arc = %\e% [38;5;15m" %\n%
156
+ for /l %%e in (%% ~4,%% ~6,%% ~5) do (%\n%
157
+ set /a " _x = %%~ 3 * ^ ! cos:x = %%e ^ ! + %%~ 1" , " _y = %%~ 3 * ^ ! sin:x = %%e ^ ! + %%~ 2" %\n%
158
+ set " $arc = ^ !$arc^!%\e% [^ !_y^! ;^ !_x^! H%pixel% " %\n%
159
+ )%\n%
160
+ set " $arc = ^ !$arc^!%\e% [0m" %\n%
161
+ )) else set args =
162
+
163
+ :_getBar
164
+ rem %getBar% currentValue maxValue MaxlengthOfBar vtColorScheme(2 or 5) colorCode colorCode colorCode
165
+ set @Bar = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-7" %% 1 in (" ^!args^! " ) do (%\n%
166
+ set /a " barVal = %%~ 3*%%~ 1/%%~ 2" , " onethird = %%~ 2 / 3" , " twoThird = onethird * 2" %\n%
167
+ if %% ~1 lss ^^! onethird^^! (%\n%
168
+ set " hue = %% ~5" %\n%
169
+ ) else if %% ~1 gtr ^^! oneThird^^! if %% ~1 lss ^^! twoThird^^! (%\n%
170
+ set " hue = %% ~6" %\n%
171
+ ) else if %% ~1 gtr ^^! twoThird^^! (%\n%
172
+ set " hue = %% ~7" %\n%
173
+ )%\n%
174
+ for /f " tokens=1,2" %%i in (" ^!barVal^! ^!hue^! " ) do (%\n%
175
+ set " $bar = %\e% [48;%% ~4;%%~j m^ !barBuffer:~0 ,%%~i ^!%\e% [0m" %\n%
176
+ )%\n%
177
+ )) else set args =
178
+
179
+ :_HSL.RGB
180
+ rem %HSL.RGB% 0-3600 0-10000 0-10000 < rtn> r g b
181
+ set " HSL(n) = k=(n*100+(%% 1 %% 3600)/3) %% 1200, x=k-300, y=900-k, x=y-((y-x)&((x-y)>>31)), x=100-((100-x)&((x-100)>>31)), max=x-((x+100)&((x+100)>>31))"
182
+ set @HSL.RGB = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-3" %% 1 in (" ^!args^! " ) do (%\n%
183
+ set /a " %HSL(n):n = 0%", "r=(%%3-(%%2*((10000-%%3)-(((10000-%%3)-%%3)&((%%3-(10000-%%3))>>31)))/10000)*max/100)*255/10000","%HSL(n):n = 8%", "g=(% %3 - (%% 2* ((10000-%% 3)- (((10000-%% 3)-%% 3)& ((%% 3- (10000-%% 3))>> 31)))/ 10000)* max/ 100)* 255/ 10000" , " %HSL(n):n = 4%", "b=(% %3 - (%% 2* ((10000-%% 3)- (((10000-%% 3)-%% 3)& ((%% 3- (10000-%% 3))>> 31)))/ 10000)* max/ 100)* 255/ 10000" %\n%
184
+ )) else set args =
185
+ set " hsl(n) = "
186
+
187
+ :_getLen
188
+ rem %getlen% "string" < rtn> $length
189
+ set @getlen = for %% # in (1 2) do if %% #==2 ( for %% 1 in (^^! args^^! ) do (%\n%
190
+ set " str = X%% ~1" ^ & set " length = 0" ^ & for /l %%b in (10,-1,0) do set /a " length |= 1 << %%b " ^ & for %%c in (^^! length^^! ) do if " ^!str:~%%c ,1 ^! " equ " " set /a " length &= ~ 1<< %%b " %\n%
191
+ )) else set args =
192
+
193
+ :_tDiff
194
+ rem %tDiff% < rtn> deltaTime, FPS, $TT, $min, $sec, frameCount
195
+ set @tdiff = (%\n%
196
+ for /f " tokens=1-4 delims=:.," %%a in (" ^!time: =0^ ! " ) do set /a " t1 = ((((1%%a - 1000)* 60+ (1%%b - 1000))* 60+ (1%%c - 1000))* 100)+ (1%%d - 1000)" %\n%
197
+ if defined t2 set /a " deltaTime = (t1 - t2)","$TT += deltaTime","fps = 60 * (1000 / (deltaTime + 1)) / 1000","$sec = $TT / 100 %% 60","$min = $TT / 100 / 60 %% 60","frameCount = (frameCount + 1) %% @32bitlimit" %\n%
198
+ set /a " t2 = t1" %\n%
199
+ if " ^!$sec:~1 ^! " equ " " set " $sec = 0^ !$sec^! " %\n%
200
+ title FPS:^^! fps^^! Time: ^^! $min^^! :^^! $sec^^! Frames: ^^! frameCount^^! /^^! $TT^^! %\n%
201
+ )
202
+
203
+ :_sevenSegmentDisplay
204
+ rem %sevenSegmentDisplay% x y value color < rtn> $sevenSegmentDisplay
205
+ set /a " segbool[0] = 0x7E" , " segbool[1] = 0x30" , " segbool[2] = 0x6D" , " segbool[3] = 0x79" , " segbool[4] = 0x33" , " segbool[5] = 0x5B" , " segbool[6] = 0x5F" , " segbool[7] = 0x70" , " segbool[8] = 0x7F" , " segbool[9] = 0x7B"
206
+ set @sevenSegmentDisplay = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-4" %% 1 in (" ^!args^! " ) do (%\n%
207
+ set " $sevenSegmentDisplay = " %\n%
208
+ set /a " qx1 = %%~ 1" , " qx2 = %%~ 1 + 1" , " qx3 = %%~ 1 + 2" , " qx4 = %%~ 1 - 1" , " qy1 = %%~ 2" , " qy2 = %%~ 2 + 1" , " qy3 = %%~ 2 + 2" , " qy4 = %%~ 2 + 3" , " qy5 = %%~ 2 + 4" , " qy6 = %%~ 2 + 5" , " qy7 = %%~ 2 + 6" %\n%
209
+ for %%j in ( " 6 1 1 2 1" " 5 3 2 3 3" " 4 3 5 3 6" " 3 1 7 2 7" " 2 4 5 4 6" " 1 4 2 4 3" " 0 1 4 2 4" ) do (%\n%
210
+ for /f " tokens=1-5" %%v in (" %%~j " ) do (%\n%
211
+ set /a " a = %%~ 4 * ((segbool[%%~ 3] >> %%~v ) & 1)" %\n%
212
+ set " $sevenSegmentDisplay = ^ !$sevenSegmentDisplay^!%\e% [48;5;^ !a^! m%\e% [^ !qy%%x ^! ;^ !qx%%w ^! H %\e% [^ !qy%%z ^! ;^ !qx%%y ^! H " %\n%
213
+ )%\n%
214
+ )%\n%
215
+ )) else set args =
216
+
217
+ :_msgBox
218
+ rem %msgBox% 'title'text'x;y;textColor;boxColor;boxLength
219
+ set @msgBox = for %% # in (1 2) do if %% #==2 ( for /f " tokens=1-7 delims=;" %% 1 in (" ^!args:~1 ^! " ) do (%\n%
220
+ if " %% ~5" neq " " ( set " t.color = %% ~5" ) else ( set " t.color = 15" )%\n%
221
+ if " %% ~6" neq " " ( set " box.color = %% ~6" ) else ( set " box.color = 15" )%\n%
222
+ if " %% ~7" neq " " ( set " msgBox.length = %% ~7" ) else ( set " msgBox.length = 60" )%\n%
223
+ set " str = X%% ~2" %\n%
224
+ set " str = ^ !str:? =^ ! " ^ & set " length = 0" ^ & for /l %%b in (10,-1,0) do set /a " length |= 1 << %%b " ^ & for %%c in (^^! length^^! ) do if " ^!str:~%%c ,1 ^! " equ " " set /a " length &= ~ 1<< %%b " %\n%
225
+ set /a " msgBox.height = length / msgBox.length + 4" , " msgBox.width = msgBox.length - 2" %\n%
226
+ for /f " tokens=1-3" %%a in (" ^!msgBox.width^! ^!msgBox.length^! ^!msgBox.height^! " ) do (%\n%
227
+ set " $msgBox = %\e% [38;5;^ !box.color^! m%\e% [%% ~4;%% ~3HÚ^ !boxBuffer:~0 ,%%~a ^! ¿%\e% [%%~b D%\e% [B³%\e% [%%~aC ³%\e% [%%~b D%\e% [BÃ^ !boxBuffer:~0 ,%%~a ^! ´%\e% [%%~b D%\e% [B" %\n%
228
+ for /l %%i in (0,1,%%~c ) do set " $msgBox = ^ !$msgBox^! ³%\e% [%%~aC ³%\e% [%%~b D%\e% [B" %\n%
229
+ set " $msgBox = ^ !$msgBox^! À^ !boxBuffer:~0 ,%%~a ^! Ù%\e% [0m" %\n%
230
+ )%\n%
231
+ set " str = ^ !str: =?^ ! " %\n%
232
+ set /a " textx = %%~ 3 + 2" , " texty = %%~ 4 + 1" , " msgBox.width -= 2" %\n%
233
+ set " $msgBox = ^ !$msgBox^!%\e% [38;5;^ !t.color^! m%\e% [^ !texty^! ;^ !textx^! H%% ~1%\e% [^ !texty^! ;^ !textx^! H%\e% [3B" %\n%
234
+ for /f " tokens=1,2" %%a in (" ^!msgBox.width^! ^!msgBox.length^! " ) do (%\n%
235
+ for /l %%i in (1,%%~a ,^^! length^^! ) do (%\n%
236
+ set " $msgBox = ^ !$msgBox^! ^ !str:~%%~i ,%%~a ^!%\e% [%%~aD %\e% [B" %\n%
237
+ )%\n%
238
+ )%\n%
239
+ set " $msgBox = ^ !$msgBox^!%\e% [0m%\e% [E" %\n%
240
+ for %%i in (textx texty str box.color msgbox.height msgbox.width msgbox.length) do set " %%i = " %\n%
241
+ )) else set args =
0 commit comments