Advertisement
IcarusLives

smoothStep

May 23rd, 2018
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.07 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. call :macros
  4.  
  5. mode 100,100
  6.  
  7. :GAME_ENGINE
  8.     for /l %%# in () do (
  9.    
  10.  
  11.             set "xx=0"
  12.             for /l %%a in (100,-1,1) do (
  13.                 %smoothStep% 1 100 %%a yy
  14.                 set /a "xx+=1", "cc=xx * yy"
  15.                 %plot_HSL_RGB% !xx! !yy! 330 10000 !cc!
  16.             )
  17.            
  18.  
  19.             <nul set /p "=%esc%[2J!screen!" & set "screen="
  20.     )
  21.     pause
  22. exit
  23.  
  24.    
  25.    
  26.    
  27.    
  28.    
  29.    
  30.    
  31.    
  32.    
  33.    
  34.    
  35.    
  36.    
  37.  
  38.  
  39. :macros
  40. set ^"LF=^
  41.  
  42. ^" Above empty line is required - do not remove
  43. set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  44. for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
  45. <nul set /p "=!esc![?25l"
  46.  
  47. rem %RGBplot% x y 0-255 0-255 0-255 CHAR
  48. set RGBplot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
  49.   set "screen=^!screen^!!esc![%%2;%%1H!esc![38;2;%%3;%%4;%%5!esc![0m"%\n%
  50. )) else set args=
  51.  
  52. rem plot_HSL_RGB x y 0-360 0-10000 0-10000
  53. set plot_HSL_RGB=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
  54.     set /a "H=%%3", "S=%%4", "L=%%5"%\n%
  55.     if %%3 geq 360 set /a "H=360"%\n%
  56.     if %%3 leq 0   set /a "H=0"%\n%
  57.     set /a "va=2*L-10000"%\n%
  58.     for /f "tokens=1" %%a in ("^!va^!") do if %%a lss 0 set /a "va=-va"%\n%
  59.     set /a "C=(10000-va)*S/10000"%\n%
  60.     set /a "h1=H*10000/60"%\n%
  61.     set /a "mm=(h1 %% 20000) - 10000"%\n%
  62.     for /f "tokens=1" %%a in ("^!mm^!")  do if %%a lss 0 set /a "mm=-mm"%\n%
  63.     set /a "X=C *(10000 - mm)/10000"%\n%
  64.     set /a "m=L - C/2"%\n%
  65.     for /f "tokens=1" %%a in ("^!H^!") do (%\n%
  66.         if %%a lss 60  ( set /a "R=C+m", "G=X+m", "B=0+m" ) else (%\n%
  67.         if %%a lss 120 ( set /a "R=X+m", "G=C+m", "B=0+m" ) else (%\n%
  68.         if %%a lss 180 ( set /a "R=0+m", "G=C+m", "B=X+m" ) else (%\n%
  69.         if %%a lss 240 ( set /a "R=0+m", "G=X+m", "B=C+m" ) else (%\n%
  70.         if %%a lss 300 ( set /a "R=X+m", "G=0+m", "B=C+m" ) else (%\n%
  71.         if %%a lss 360 ( set /a "R=C+m", "G=0+m", "B=X+m" ))))))%\n%
  72.     )%\n%
  73.     set /a "R=R*255/10000", "G=G*255/10000", "B=B*255/10000", "HSLX=%%1", "HSLY=%%2"%\n%
  74.     for /f "tokens=1-5" %%a in ("^!HSLX^! ^!HSLY^! ^!R^! ^!G^! ^!B^!") do ^!RGBplot^! %%a %%b %%c %%d %%e%\n%
  75. )) else set args=
  76.  
  77. rem clamp x min max RETURNVAR
  78. set clamp=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%
  79.     set /a "xx=%%~1", "yy=%%2", "zz=%%3"%\n%
  80.     for /f "tokens=1-3" %%x in ("^!xx^! ^!yy^! ^!zz^!") do (%\n%
  81.                if %%x lss %%y ( set /a "xx=%%y"%\n%
  82.         ) else if %%x gtr %%z ( set /a "xx=%%z" )%\n%
  83.     )%\n%
  84.     for /f "tokens=1" %%x in ("^!xx^!") do (%\n%
  85.         if "%%4" neq "" ( set /a "%%4=%%x" ) else ( echo=%%x)%\n%
  86.     )%\n%
  87. )) else set args=
  88.  
  89. rem smoothStep min max X RETURNVAR
  90. set smoothStep=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%
  91.     %= Scale, bias and saturate x to 0..100 range =%%\n%
  92.     set /a "clamped=((%%3) - %%1) * 100 ^/ (%%2 - %%1) + 1"%\n%
  93.     for /f "tokens=1" %%c in ("^!clamped^!") do ^!clamp^! %%c 0 100 CLAMPED_x %\n%
  94.     %= Evaluate polynomial =%%\n%
  95.     set /a "ss=^(3*100 - 2 * CLAMPED_x^) * CLAMPED_x^/100 * CLAMPED_x^/100"%\n%
  96.     for /f "tokens=1" %%x in ("^!ss^!") do (%\n%
  97.         if "%%4" neq "" ( set "%%4=%%x" ) else ( echo=%%x)%\n%
  98.     )%\n%
  99. )) else set args=
  100. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement