Hi to all,
The new work of penpen on ieee 754 float point is based on macro function.
I have rewritten the plasma code for work on this news.
You can pass a parameter for choice a gradiend 0..5 (6 gradients defined)
gradient 0 = rainbow
Plasma.cmd
Code: Select all
@echo off& setlocal EnableDelayedExpansion&Goto :Init_System
:: developed on windows 7 32bit. Version 0.5b
:: Use Lucida console 5 or raster 8x8 or small for best view
:Main
:: load all macros, and exit if it has failed for whatever reasons
call loadfloat.bat
if errorLevel 1 exit /b 1
set sizex=48
set sizey=32
if !sizex! gtr !sizey! (set /a size=sizex) else set /a size=sizey
set /a size=size*2+8 & mode !size!,!size! & set /a size=(size-8)/2
if "%1"=="" (set grad=!random!) else set grad=%1
call :create_palette !grad!
(
set $str2float=
set $floatAdd=
set $float2str=
set $floatSub=
set $floatMul=
set $intToHex=
set /a e=Lenp/2
%$str2float% "!e!" fe
Echo Wait, precalc sin...
for /L %%x in (-%size%,1,%size%) do set/p"=_"<nul
echo(^|
for /L %%x in (-%size%,1,%size%) do ( if not exist %tmp%\Plasma_sin[%%x].$$$.tmp (
%$str2float% "%%x" "fx"
:: newy=fy/8 1/4=0x3E800000 1/8=0x3E000000
rem call :floattestMul2 "1" "0.25" newy
%$floatMul% "!fx!" "0x3E800000" newx
%$float2str% "!newx!" "newx"
rem call :sin "!newx!" sinx
rem ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem :: calculate SIN(x) ~ x * ( 1 - x^2 * (1/6 - x^2 * (1/120 - x^2 * (1/5040 - x^2 * (1/362880 - x^2 * 1/39916800 )))))
set x=!newx!
if "!x:~0,1!"=="-" (
set r=-1
set x=!x:~1!
) else (
set r=1
)
%$str2float% "!x!" "fx"
:: PI=3.14159265....=0x40490FDB
set break=
for /L %%I in (1,1,10) do if not defined break (
%$floatSub% "!fx!" "0x40490FDB" tx
if !tx! gtr 0 (set /A fx=tx, r=-r) else set break=true
)
set break=
%$floatMul% "!fx!" "!fx!" fxx
%$floatMul% "!fxx!" "0x32D7322B" fsint
%$floatSub% "0x3638EF1D" "!fsint!" fsint
%$floatMul% "!fxx!" "!fsint!" fsint
%$floatSub% "0x39500D01" "!fsint!" fsint
%$floatMul% "!fxx!" "!fsint!" fsint
%$floatSub% "0x3C088889" "!fsint!" fsint
%$floatMul% "!fxx!" "!fsint!" fsint
%$floatSub% "0x3E2AAAAB" "!fsint!" fsint
%$floatMul% "!fxx!" "!fsint!" fsint
%$floatSub% "0x3F800000" "!fsint!" fsint
%$floatMul% "!fx!" "!fsint!" fsin
set fsint=
set fx=
set fxx=
if !r! lss 0 set /A "fsin=(1<<31)^fsin"
%$float2str% "!fsin!" sin
set "sinx=!sin!"
set fsin=
set sin=
rem ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%$str2float% "!sinx!" fx
%$floatMul% "!fx!" "!fe!" x1
%$float2str% "!x1!" x1
>%tmp%\Plasma_sin[%%x].$$$.tmp echo !x1!
)
set/p"=."<nul
)
echo(
)
for /L %%y in (-%sizey%,1,%sizey%) do (
<%tmp%\Plasma_sin[%%y].$$$.tmp set/p "y1="
:: get integer part
set app=!y1:*e-=!
if not "!y1!"=="!app!" (set app=0) else (
set app=!y1:*.=!
for %%a in (!app!) do set app=!y1:.%%a=!
)
if "!app!"=="." set app=0
set /a iy=e+!app!
set app=
for /L %%x in (-%sizex%,1,%sizex%) do (
<%tmp%\Plasma_sin[%%x].$$$.tmp set/p "x1="
:: get integer part
set app=!x1:*e-=!
if not "!x1!"=="!app!" (set app=0) else (
set app=!x1:*.=!
for %%a in (!app!) do set app=!x1:.%%a=!
)
if "!app!"=="." set app=0
set /a ix=e+!app!
set app=
set /a "c=(ix+iy)/2"
call :plot !c!
)
echo(
)
Goto :EndMain
:plot %1
(
call :color !p[%1]:~0,2! !p[%1]:~-1!
goto :eof )
::manual palette, best transient color, rif.http://en.wikipedia.org/wiki/Web_colors
rem
rem 1 -> 2 3 4 5 6 9
rem 2 -> 1 3 4 5 6 A
rem 3 -> 1 2 4 5 6 9 A B
rem 4 -> 1 2 3 5 6 C
rem 5 -> 1 2 3 4 6 9 D
rem 6 -> 1 2 3 4 5 A C E
rem 9 -> 1 3 5
rem A -> 2 3 6
rem B -> 3
rem C -> 4 5 6
rem D -> 5
rem E -> 6
:create_palette %1
set /a "p=0, n=%1 %% 6"
echo Get gradient number !n!
if !n! equ 0 set Grad=04 4C cE EA A2 21 15 50
if !n! equ 1 set Grad=04 4C c5 53 39 91 15 50
if !n! equ 2 set Grad=E6 61 13 3A A2 21 13 3B
if !n! equ 3 set Grad=E6 61 14 4C C4 41 13 3B
if !n! equ 4 set Grad=12 23 34 45 56 6A A3 3B
if !n! equ 5 set Grad=19 93 3A A6 6C C5 5D D5
For %%p in (%Grad%) do (
set "p[!p!]=%%p°" & set /a p+=1
set "p[!p!]=%%p±" & set /a p+=1
set "p[!p!]=%%p²" & set /a p+=1
set "p[!p!]=%%pÛ" & set /a p+=1
)
set /a p-=1
set Lenp=!p!
goto :eof
Goto :EndMain
:: ( Begin Color Function
:color
(echo %~2\..\'
) > $$$.color.txt && findstr /a:%~1 /f:$$$.color.txt "."
Shift
Shift
If ""=="%~1" Goto :Eof
goto :color
:: ) End color Fuction
:Init_system
for /F "delims==" %%f in ('set') do if /i not "%%f"=="Path" if /i not "%%f"=="TMP" set "%%f="
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a")
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"
Goto :Main
:EndMain
:: Clearing all garbage
del '
del $$$.color.txt
Goto :Eof
This is very fast now. The older versions can be found on the
ieee thread.
EDIT: For working is necessary the LoadFloat.bat
You can create the loadfloat.bat with notepad, copying and paste from the
first post of ieee 754. (thanks to foxidrive)
EDIT2-3: Adding check on null parameter and mode setting (thanks to foxidrive) , add 2 new gradients (0..5 now)
EDIT4:fixed a bug (thanks to foxidrive)
einstein1969