I've been attempting to create the perlin noise algorithm. perlin noise algorithm
I really was hoping I could use this algorithm for some possible terrain generation for some sort of a game. I find the idea of perlin noise to be very interesting.
Upon my research I've learned that a piece of the algorithm consists of a smoothstep algorithm, which is given a value from a "clamp" function.
Here is my attempt at this code. I've only really gotten up to the smoothStep part, and implementing it into perlin noise is really challenging for me.
Only tested on Win10. Uses mshta javascript for floating point numbers
Code: Select all
@echo off & setlocal enableDelayedExpansion
call :init
:main
cls
for /l %%a in (0,9,99) do (
set /a "r=%%a"
REM for /l %%a in (1,1,10) do (
REM set /a "r=!random! %% %edge1% + %edge0%"
call :clamp x "(!r! - %edge0%)/(%edge1% - %edge0%)" 0.000 1.000
::smoothstep(x) = 3x^2 - 2x^3
call :float_JS "smoothstep=!x! * !x! * ( 3 - 2 * !x!)"
echo !smoothstep!
REM call :genDisp !smoothstep:~2,1!
)
pause & exit
:genDisp
set "o="
if not "!smoothstep:~2,1!" equ "" (
for /l %%0 in (1,1,%1) do set "o=!o! "
echo !o!#
)
goto :eof
:prep_smoothStep
set /a "edge0=%1", "edge1=%2"
goto :eof
:clamp
call :float_JS "r=%~2"
if %r:~0,5% lss %3 ( set "%1=%3" ) else if %r:~0,5% gtr %4 ( set "%1=%4" ) else set "%1=%r:~0,5%"
set "r="
goto :eof
:float_JS
( for /f "tokens=1,2 delims==" %%a in ("%~1") do (
for /f %%N in ('%beginJS% %%b %endJS%') do set "%%a=%%N"
))
goto :eof
:init
set "beginJS=mshta "javascript:close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(eval("
set "endJS=)));""
call :prep_smoothStep 1 99
goto :eof
OUTPUT:
Code: Select all
1
1
0.079431566
0.17345575
0.291348414
0.422281216
0.559872
0.693400064
0.813521152
0.910891008
0.976165376
1
Press any key to continue . . .
With all honesty, I believe I've done everything right so far, but something feels off to me. Opinions?