Page 1 of 1

Plasma color gradient example

Posted: 05 Jun 2014 13:10
by einstein1969
Hi to all,

Image

You can get the code or view other result on this thread

If have problem please use this thread for resolution.

EDIT:
Since the code is not well tested and is a working in progress and need make a merge, user with low skill may have problems. I suggest to wait for complete code.
For user with sufficient skill it is easy get complete code.
For those who have no skill and still want to try to do the merge can ask for help here.

einstein1969

Re: Plasma color gradient example

Posted: 22 Aug 2014 10:50
by einstein1969
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

Re: Plasma color gradient example

Posted: 23 Aug 2014 00:49
by foxidrive

'loadfloat.bat' is not recognized as an internal or external command,
operable program or batch file.

Re: Plasma color gradient example

Posted: 23 Aug 2014 01:05
by einstein1969
Can you rename 'loadfloat.cmd' to ''loadfloat.bat' and try again?

Code: Select all

ren loadfloat.cmd loadfloat.bat


In the last version i have used the same extension proposted in the initial thread of ieee 754.

einstein1969

Re: Plasma color gradient example

Posted: 23 Aug 2014 01:07
by foxidrive
loadfloat.bat is not on my computer. You didn't mention that it is needed.

Re: Plasma color gradient example

Posted: 23 Aug 2014 01:12
by einstein1969
foxidrive wrote:loadfloat.bat is not on my computer. You didn't mention that it is needed.


I'm sorry, you can create the loadfloat.bat with notepad, copying and paste from the first post of ieee 754.

einstein1969

Re: Plasma color gradient example

Posted: 23 Aug 2014 02:11
by foxidrive
Ta. It is colourful but I get double line spacing as the right margin seems bigger than my window,
so it would be good to use the mode command to set the required window size.

$$$.color.txt is left behind when it terminates.

At the start at the top line I also get a Missing operand. error before the dots appear across the screen.

Re: Plasma color gradient example

Posted: 23 Aug 2014 07:22
by einstein1969
foxidrive wrote:Ta. It is colourful but I get double line spacing as the right margin seems bigger than my window,
so it would be good to use the mode command to set the required window size.

$$$.color.txt is left behind when it terminates.

At the start at the top line I also get a Missing operand. error before the dots appear across the screen.


Ta :) (I did not know this slang!) . I have update the previous post with the new version.

einstein1969

Re: Plasma color gradient example

Posted: 23 Aug 2014 07:43
by foxidrive
When I launch the batch file with a parameter 1 or 2 I get this:


'grad' is not recognized as an internal or external command,
operable program or batch file.
Missing operand.
Get gradient number
Wait, precalc sin...

Re: Plasma color gradient example

Posted: 23 Aug 2014 07:52
by einstein1969
foxidrive wrote:When I launch the batch file with a parameter 1 or 2 I get this:


'grad' is not recognized as an internal or external command,
operable program or batch file.
Missing operand.
Get gradient number
Wait, precalc sin...


:oops: I have missed a SET... Correct above.

einstein1969

Re: Plasma color gradient example

Posted: 23 Aug 2014 08:06
by foxidrive
It looks good - random gradients works and I passed a number which works too.

Re: Plasma color gradient example

Posted: 23 Aug 2014 08:29
by einstein1969
foxidrive wrote:It looks good - random gradients works and I passed a number which works too.


For complete this is a nice black and white gradient: 78 80 08 87 7F F7 78 80

change to this code:

Code: Select all

  set /a "p=0, n=%1 %% 7"

  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
  if !n! equ 6 set Grad=78 80 08 87 7F F7 78 80


einstein1969

Re: Plasma color gradient example

Posted: 25 Aug 2014 16:25
by penpen
Great work!

The only bug i've found is that your color function does not look nice when using WinXP.

There you see something like this (in different colors):

Code: Select all

.\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..
\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':.
 .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. ..
.. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .
. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. ..
 .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. ..
..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\.
.\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':
. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. ..
 .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. ..
.. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .
. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. .. ..\..\':. .. .. .. .. ..

Fast Bugfix: Dave's color function works on Win XP with no such characters:
http://www.dostips.com/forum/viewtopic.php?p=34851#p34851

penpen