Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#61 Post by misol101 » 16 Sep 2016 21:44

Alright, I tried some jscript too. Result was fast (~80 fps), even though a new window opens for every frame, when calling shell.Run(!). This obviously ruins the effect...

Is there some way I can run an external from js without opening a new window? Tried Exec, but then no output from WriteConsoleOutput is shown :( And "start /B" for Run didn't work either.

Script:

Code: Select all

@if (true == false) @end /*
@echo off
setlocal ENABLEDELAYEDEXPANSION
cmdwiz setfont 6 & cls & mode 140,50
cmdwiz gettime&set STARTT=!errorlevel!
cscript //nologo //e:javascript "%~dpnx0" %*
mode 80,50 & cls
cmdwiz gettime&set /a FPS=(!errorlevel!-%STARTT%)/1000&set /a FPS=400/!FPS!&echo !FPS!
endlocal
exit /b 0 */

nofStars = 200
var starsX=[], starsY=[], starsS=[], starsC=[]

var shell = new ActiveXObject("WScript.Shell");

for (i = 0; i < nofStars; i++) {
  starsX.push(Math.floor(Math.random() * 140))
  starsY.push(Math.floor(Math.random() * 50))
  starsS.push(Math.random() * 1.2 + 0.1)
  if (starsS[i] < 0.5) {
     starsC.push(8)
   } else if (starsS[i] < 1.1) {
     starsC.push(7)
   } else {
     starsC.push(15)
   }
}

for (j = 0; j < 400; j++) {
  outString=""
  for (i = 0; i < nofStars; i++) {
    starsX[i] += starsS[i]
    if (starsX[i] > 140) {
        starsX[i] = 0
    }
    outString = outString + "& pixel " + starsC[i] + " 0 . " + Math.floor(starsX[i]) + "," + starsY[i]
  }
 
//  var wsx = shell.Exec("cmd /c cmdgfx \"" + outString + "\" k"); // can read/print stdout/stderr output this way, but no WriteConsoleOutput is shown :(
////  WScript.Echo(wsx.StdOut.ReadAll())

  shell.Run("cmdgfx \"" + outString + "\" k",10); // Always opens a new window  :(
}

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#62 Post by misol101 » 27 Sep 2016 18:50

Image

Archive / repo updated.

Not a lot of new features or scripts, mostly stability/bugfixes. But hey, there's the Matrix effect :)

1. Polygons no longer get horribly messed up when very close in 3d. This problem was "hidden" before, but try changing the near culling in 3dworld.bat from 800 to 1 using the old cmdgfx.exe and things will quickly get ugly.
Unfortunately, when using texture mapping, getting very close to polygons one can more clearly see the artefacts of non-perspective-correct texture mapping (things getting all wobbly etc). But that's another issue.

2. More sanity checks and better parsing of plg/ply/obj 3d object files. Still far from perfect.

3. No more "ipoly" polygons with "holes". To see an example of holes, use the old cmdgfx version, run glenz.bat and then zoom in with Shift-D.

4. Goraud shading rounding/edge bug fixed. Probably not noticed by many, but could be seen in all goraud shading examples, like gfxtest4.bat.

5. Able to set projection depth for 3d. This is used to change how "narrow" the z dimension in the world appears. The default value is 500. Use the new flag Zn to set this. The new script 3dworld3_pxlfont_1280.bat shows the same old 3d world, but now in 1280x680 resolution. At this high resolution, the projection narrowness was increased to 800 to avoid a too stretched out feeling.

6. Transparency supported for the block operation. This allows e.g. layers of transforms to be put on top of each other, as shown in the new matrix.bat script. SPACE to change colors.
Last edited by misol101 on 16 Apr 2017 13:12, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#63 Post by foxidrive » 27 Sep 2016 20:08

misol101 wrote:But hey, there's the Matrix effect :)


That's cool.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#64 Post by misol101 » 28 Sep 2016 10:57

foxidrive wrote:That's cool.

Thanks. I added another script (matrix-src.bat), so archive was updated again. This one is sort of meta, because it shows the code to the script while its code runs... This was a tricky one to get working...

Image

Edit: also try giving a file as input, like: matrix-src img\myface.txt
Last edited by misol101 on 16 Apr 2017 13:13, edited 1 time in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#65 Post by misol101 » 07 Oct 2016 17:50

My latest batch adventures! :mrgreen: Archive/repo were updated.

This time there were two major changes:

1. Math expressions for the block operation (both for color and position), in addition to previous transform.
2. Support for bezier curves (max 6 control points plus the first two)

To enable math expressions, I used source from tinyexpr, which can be cloned from here: https://github.com/codeplea/tinyexpr. It's quite cool and easy to extend!

Some scaled-down results from test scripts:

Image

Image 1: rotate-expr.bat, using expressions to rotate the screen while adding more content at the same time.
Image 2: plasma.bat, using expressions to change colors, creating a kind of moving "plasma" effect
Image 3: bezier-expr.bat (and bezier.bat for single color), draw a bunch of bezier curves in an animation, use expressions for symmetry and overlay plasma
Image 4: life.bat, implements Game of Life using expressions. Also possible to draw to screen with mouse, then evaluate.

There is a lot that could be said about the expressions, it's powerful but can be tricky, especially when combining color expressions, move expressions and transformations in several steps. From the get-go, tinyexpr supports math functions like sin/cos/abs/tan/floor etc, and I have added several: random,neg/and/or/xor/shl/shr,eq,neq,gtr,lss,col,char,fgcol,bgcol,store. I may explain it all more later. Anyway, as an example, here's an expression to implement GameOfLife :mrgreen: (the result of summing up the cell neighbours is stored in s0 by "store")

Code: Select all

((1-(lss(s0,2)+gtr(s0,3)))*gtr(col(x,y),0)+eq(col(x,y)*10+s0,3)+store(gtr(col(x-1,y-1),0)+gtr(col(x,y-1),0)+gtr(col(x+1,y-1),0)+gtr(col(x-1,y),0)+gtr(col(x+1,y),0)+gtr(col(x-1,y+1),0)+gtr(col(x,y+1),0)+gtr(col(x+1,y+1),0),0))*!COL!
Last edited by misol101 on 16 Apr 2017 13:14, edited 1 time in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#66 Post by misol101 » 08 Oct 2016 06:02

Another archive update. I realized it was a shame to draw 50 bezier lines per frame and not actually make it look like they move. So I made a new version, (bezier2.bat), where I have less lines but each lines moves individually after each other. This creates a totally different feeling and can be quite dizzying at times :)

Space to create new pattern.

EDIT: Added yet another script, bezier-aacini-sin.bat, named as such simply because I stole Aacini's sin macro to get rid of the lookup table. Lovely, now I can easily use negative sinus values!

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#67 Post by misol101 » 09 Oct 2016 18:30

Updated archive again. Block operation got xflip and yflip options, and some bugs in ellipse and fellipse were fixed.

The latest script added (bezier-col-hires.bat) looks like this:

Image

but, actually, also like this: :mrgreen:

Image

and this:

Image

Some keys while running:
'o' switch drawing operation
'b' bit operator when in poly mode
'c' switch between default colors and set colors
Space: new pattern
D/d: increase decrease delay
's' turn on/off gradual slow change of pattern (default is on)
'a' print out data for the current pattern, to be copy/pasted
Last edited by misol101 on 16 Apr 2017 13:20, edited 1 time in total.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#68 Post by einstein1969 » 12 Oct 2016 10:34

Hi misol101,

very good job!

I see that you are using the sin(x) macros developed by me and Aacini and other Dostip users.
You can find the last version, faster than the previous in this thread.

The extracted code:

Code: Select all

set "SIN=(a - a*a/1920*a/312500 + a*a/1920*a/15625*a/15625*a/2560000 - a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"
set "SIN(x)=(a=(x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %SIN%)"
set SIN=


einstein1969 aka Francesco Poscetti

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#69 Post by neorobin » 13 Oct 2016 02:21

Hi einstein1969

I made another implementation, origin from 3D Sphere viewtopic.php?f=3&t=5594

map rule: [0,2pi) to [-pi/2, pi/2]

Code: Select all

angle t in [0,2pi)

0 <= t < pi/2       t -> t          in [-pi/2, 0)
not need map


pi/2 <= t < 3pi/2   t -> pi-t       in (-pi/2, pi/2]

sin(t) = sin(pi-t),    cos(t) = -cos(pi-t)


3pi/2 <= t < 2pi    t -> -2pi+t     in [-pi/2, 0)

sin(t) = sin(-2pi+t),  cos(t) = cos(-2pi+t)



my test code

Code: Select all

@echo off
mode 100
set "SIN=(t-t*t/1875*t/320000+t*t/1875*t/15625*t/16000*t/2560000-t*t/1875*t/15360*t/15625*t/15625*t/16000*t/44800000)"
set "COS=(10000-t*t/20000+t*t/1875*t/15625*t/819200-t*t/1875*t/15360*t/15625*t/15625*t/10240000+t*t/1875*t/15360*t/15625*t/15625*t/16000*t/15625*t/229376000)"

REM 15 test angles in [0, 2Pi) step by Pi/8
set "List=0,3927,7854,11781,15708,19635,23562,27489,31416,35343,39270,43197,47124,51051,54978,58905"
set /a "p=31416, p2=62832, pn2=-62832, p#2=15708, p3#2=47124, p3#2_=p3#2-1"
set R_Sin=
set R_Cos=

for %%a in (%List%) do (
        set /a "t=%%a"
        set /a "t%%=p2,s1=(t-p#2^t-p3#2)>>31, s3=p3#2_-t>>31, t=(-t&s1)+(t&~s1)+(p&s1)+(pn2&s3), r1=%SIN%"
        set /a "t=%COS%, r2=(-t&s1)+(t&~s1)"
        setlocal EnableDelayedExpansion
        set R_Sin=!R_Sin!!r1!,
        set R_Cos=!R_Cos!!r2!,
)
set R_
pause


test result

Code: Select all

R_Cos=10000,9238,7071,3826,0,-3826,-7071,-9238,-10000,-9238,-7071,-3826,0,3826,7071,9238,
R_Sin=0,3827,7071,9239,9999,9239,7071,3827,0,-3827,-7071,-9239,-9999,-9239,-7071,-3827,



Two usage examples: tested on WIN7 64bit and XP 32bit

Please edit the code, replace the ★ to a real TAB character (ASCII 0x9).

spiral

Image


Code: Select all

@echo off & setlocal enabledelayedexpansion

set "TAB=★" & for /F %%a in ('"prompt $h&for %%b in (1) do rem"')do Set "BS=%%a"

set /a "ZM=10000, p=31416, p2=62832, pn2=-62832, p#2=15708, p3#2=47124, p3#2_=p3#2-1, DEG=31416/180"
set "SIN=(t-t*t/1875*t/320000+t*t/1875*t/15625*t/16000*t/2560000-t*t/1875*t/15360*t/15625*t/15625*t/16000*t/44800000)"
set "COS=(10000-t*t/20000+t*t/1875*t/15625*t/819200-t*t/1875*t/15360*t/15625*t/15625*t/10240000+t*t/1875*t/15360*t/15625*t/15625*t/16000*t/15625*t/229376000)"

set /a "wid=75, hei=75, iMax=wid*hei, wid_div_2 = wid / 2 - 3"
color 0c & mode !wid!,!hei!

(for /l %%i in (1 1 !iMax!) do set "scr= !scr!") & set "emp=!scr!"

set /a "buffwid = wid, linesWantBackAbove = hei - 1, cntBS = 2 + (buffwid + 7) / 8 * linesWantBackAbove"

set "BSs=" & for /L %%a in (1 1 !cntBS!) do set "BSs=!BSs!%BS%"
set "aLineBS=" & for /L %%a in (1 1 !wid!) do set "aLineBS=!aLineBS!%BS%"

set /a "XC = wid/2, YC = hei/2, DEG_unit = 3, ddu=1, th0=!random! %% 360 * DEG"

for /L %%i in (5000 -1 0) do (

    set /a "th=th0+p2+DEG*%%i, DEG_unit+=ddu, DEG_unit= DEG_unit %% 360"
   
    for /l %%a in (0 1 !wid_div_2!) do (
        set /a "th+=p2+DEG * DEG_unit, th %%= p2, th += th>>31&p2, t=th, s1=(t-p#2^t-p3#2)>>31, s3=p3#2_-t>>31, t=(-t&s1)+(t&~s1)+(p&s1)+(pn2&s3), SINt=%SIN%, t=%COS%, COSt=(-t&s1)+(t&~s1)"

        set /a "r=%%a, x=(XC*10000 + r * COSt)/10000, y=(YC*10000 + r * SINt)/10000, inScr=(x-0^x-wid)&(y-0^y-hei)"

        REM if !inScr! lss 0 (
            set /a "ind=x+y*wid+1, lenL=ind-1"
            for /f "tokens=1,2" %%a in ("!lenL! !ind!") do (set scr=!scr:~0,%%a!*!scr:~%%b!)
        REM )
    )

    <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
    <nul set /p "=%BS%!scr:~0,-1!" & set "scr=!emp!" & title %%i / 5000
)
>nul pause
exit



3D Torus Vortex
Image
Please edit the code, replace the ★ to a real TAB character (ASCII 0x9).

Code: Select all

@echo off & setlocal enabledelayedexpansion & chcp 437 & title 3D Torus Vortex

set "Path=%SystemRoot%\system32" & for /f "delims==" %%a in ('set') do if /i "%%a" neq "Path" set "%%a="
set "SIN=(t-t*t/1875*t/320000+t*t/1875*t/15625*t/16000*t/2560000-t*t/1875*t/15360*t/15625*t/15625*t/16000*t/44800000)"
set "COS=(10000-t*t/20000+t*t/1875*t/15625*t/819200-t*t/1875*t/15360*t/15625*t/15625*t/10240000+t*t/1875*t/15360*t/15625*t/15625*t/16000*t/15625*t/229376000)"
set /a "ZM=10000, p=31416, p2=62832, pn2=-62832, p#2=15708, p3#2=47124, p3#2_=p3#2-1, DEG=31416/180"

set /a "Cols=wid=330, lines=hei=130, lines_plus_1=lines+1"
mode !Cols!,!lines_plus_1!

set "TAB=★" & for /F %%a in ('"prompt $h&for %%b in (1) do rem"')do Set "BS=%%a"
set /a "buffwid = wid, linesWantBackAbove = hei - 1 + 1, cntBS = 2 + (buffwid + 7) / 8 * linesWantBackAbove"
set "BSs=" & for /L %%a in (1 1 !cntBS!) do set "BSs=!BSs!%BS%"
set "aLineBS=" & for /L %%a in (1 1 !wid!) do set "aLineBS=!aLineBS!%BS%"

set "LN0=" & for /L %%C in (1 1 !Cols!) do set "LN0= !LN0!"
for /L %%L in (1 1 !lines!) do set "LN%%L=!LN0!"

set /a "pixel_h=6, pixel_w=4" & rem Fontsize 4X6
rem zscr: screen Z coor, zeye: eye point Z coor
set /a "XC = Cols/2, YC = lines/2, zscr = 128, zeye = 400, zs2e=zscr-zeye"

set /a "R1 = 68, r2 = 60, TH1 = 0, th2 = 0, cntRings=120, cntRings_1=cntRings-1, cntDotPerRing=20, cntDotPerRing_1=cntDotPerRing-1"
set /a "sumDots=cntDotPerRing*cntRings"
set /a "dth2base=(P2+P2/cntRings)/cntDotPerRing, offsClose=p2-(dth2base*cntDotPerRing-p2)*cntRings"
set "offsClose=!offsClose!/!sumDots!"
set /a "dTH1base=p2/cntRings, offsCloseBigCircle=p2-dTH1base*cntRings"
set "offsCloseBigCircle=!offsCloseBigCircle!/!cntRings!"
set /a "Z_cut_ZM=999*ZM" & rem The cutting plane parallel to plane xoy, Cut the front. When this value is large enough, there is no cutting effect

for /l %%i in (0 1 !cntRings_1!) do (

    for /l %%j in (0 1 !cntDotPerRing_1!) do (

        set /a "TH1=%%i*dTH1base+ %%i * %offsCloseBigCircle%, TH1 %%= p2, TH1 += TH1>>31&p2, t=TH1, s1=(t-p#2^t-p3#2)>>31, s3=p3#2_-t>>31, t=(-t&s1)+(t&~s1)+(p&s1)+(pn2&s3), SIN_TH1=%SIN%, t=%COS%, COS_TH1=(-t&s1)+(t&~s1)"

        set /a "t=%%i*cntDotPerRing+%%j,th2=t*dth2base+t*%offsClose%, th2 %%= p2, th2 += th2>>31&p2, t=th2, s1=(t-p#2^t-p3#2)>>31, s3=p3#2_-t>>31, t=(-t&s1)+(t&~s1)+(p&s1)+(pn2&s3), SIN_th2=%SIN%, t=%COS%, COS_th2=(-t&s1)+(t&~s1)"

        title 3D Torus Vortex  %%i/!cntRings_1! %%j/!cntDotPerRing_1!  TH1: !TH1! th2: !th2!

        set /a "z_ZM=(R1*ZM + r2*COS_th2)/ZM * SIN_TH1, z_t2eye_ZM=z_ZM -zeye*ZM, x=XC + (R1*ZM + r2*COS_th2)/ZM * COS_TH1 *zs2e* pixel_h /(z_t2eye_ZM * pixel_w), y=YC + r2 * SIN_th2 *zs2e/z_t2eye_ZM, inScr=(x-0^x-wid)&(y-0^y-hei)"

        set /a "inner=(th2-p#2^th2-p3#2)" & rem distance to the y-axis < big circle radius

        if !z_ZM! LSS !Z_cut_ZM! (

            set /a "ind=x+1, lenL=ind-1"
            for /f "tokens=1-3" %%a in ("!lenL! !ind! !y!") do (
                if !TH1! LSS !p! (
                    if !inner! LSS 0 (  set "LN%%c=!LN%%c:~0,%%a!#!LN%%c:~%%b!"
                    ) else (            set "LN%%c=!LN%%c:~0,%%a!o!LN%%c:~%%b!"
                    )
                ) else (
                    if !inner! LSS 0 (  rem set "LN%%c=!LN%%c:~0,%%a!*!LN%%c:~%%b!" & Blank the behind half of the inner hole
                    ) else (            set "LN%%c=!LN%%c:~0,%%a!.!LN%%c:~%%b!"
                    )
                )
            )
        )

        <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
        for /L %%d in (1 1 !lines!) do <nul set /p "=%BS%!LN%%d!"
    )
)
>nul pause
exit

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#70 Post by misol101 » 13 Oct 2016 10:49

einstein: Thanks! I mentioned using your sin macro in neorobin's thread http://www.dostips.com/forum/viewtopic.php?f=3&t=7447

neorobin: Cool, so.. is that even faster then or how does it differ?


I suppose you already know this, but for some real scripting speed something like Python is hard for Batch to beat... here is my hires bezier lines in Python (in a bat file), it runs a lot smoother for sure... (even though rendering probably takes the majority of time, so the difference is not as big as it can be)

Code: Select all

0<0# : ^
'''
@echo off
setlocal ENABLEDELAYEDEXPANSION
cmdwiz setfont 0 & cls & mode 180,80
cmdwiz showcursor 0
cmdwiz gettime&set STARTT=!errorlevel!
python %~f0 %*
rem pause
mode 80,50 & cls
rem cmdwiz gettime&set /a FPS=(!errorlevel!-%STARTT%)/1000&set /a FPS=400/!FPS!&echo !FPS!
cmdwiz setfont 6
cmdwiz showcursor 1
endlocal
exit /b 0
'''

from subprocess import Popen
from random import randint, uniform
from math import sin
from subprocess import call

W, H, DIV = 180*4, 80*6, 2
XMID, YMID = W/2/DIV, H/2/DIV
XMUL, YMUL = W/2/DIV, H/2/DIV
SXMID, SYMID = W/2, H/2
DELAY, KEY = 0, 0
LINEGAP, NOFBEZ, SINDIV = 5, 22, 75
CHANGE, CHANGESTEPS = 1, 400
CHANGECOUNT = CHANGESTEPS
PALETTES=["000000,000000,000000,000000,000000,0020ff,0040ff,0060ff,0080ff,20a0ff,20b0ff,50c0ff,80e0ff,b0f0ff,f0ffff,ffffff", "","000000,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00,00ff00", "000000,000040,000050,000060,000070,000080,0050a0,0050a0,0050a0,0070c0,2090e0,50b0ff,80d0ff,b0f0ff,f0ffff,ffffff"]
DRAWOP, BITOP, PAL = 0, 3, 0
DRAWS=["line", "ipoly", "fellipse", "fbox", "fcircle", "ellipse"]
S=[0, 0, 0, 0, 0, 0, 0, 0]
P=[0, 3, 0, 0, -2, -3, -3, 3]
SB=[35962, 7098, -26481, -5009, 61416, -41598, -32963, 26096]
#P=[3, 2.99, -2, 2, 0, 0, -1, -1]
#SB=[41341.21999999964, 16061.609999999948, -25810.830000000027, -528.31000000008, 61528, -47065.68999999749, -37120, 33081.20999999951]
P=[2, 2, 2, 3.01, 0, -1, -2, 1]
SB=[34053, 9497, -25587.770000000517, -4603.32999999992, 61032, -42626.240000001475, -33496, 28050]
out, process = 0, 0
P=[-3, 1, -2.01, 0.0, 2.01, 2.01, 0.99, 1.0]
SB=[28712.570000000116, 19988.01000000009, -26999.879999996017, 5247.810000000997, 68958.06999999368, -37988.6600000038, -36060.44999999826, 35267.98999999772]

#for x in range(0, 400):
while (out != 27):
  outString=""
  for i in range(0, 8):
     S[i]=SB[i]

  COL, COLPLUS = 1, 14/NOFBEZ
  for j in range(0, NOFBEZ):
    outString=outString + "& " + DRAWS[DRAWOP] + " "+ str(int(COL)) +" 0 A "

    if (DRAWOP==1):
      outString += str(int(BITOP)) + " "

    COL+=COLPLUS
    for i in range(0, 4):
       if (i == 0) or (i == 2) or ((DRAWOP==1) and (i == 1)):
         outString = outString + str(int(XMID+sin(S[i*2]/SINDIV)*XMUL)) + "," + str(int(YMID+sin(S[i*2+1]/SINDIV)*YMUL)) + ","
       elif (i == 1) or (i == 3):
         outString = outString + str(int(XMID+sin(S[i*2]/SINDIV)*XMUL)) + "," + str(int(YMID+sin(S[i*2+1]/SINDIV)*YMUL)) + " "
    for i in range(0, 8):
      S[i]+=P[i]*LINEGAP

  for i in range(0, 8):
     SB[i]+=P[i]

  CHANGECOUNT-=1
  if (CHANGECOUNT < 0):
    P[randint(0,7)]+=(randint(0,1)*2-1)/100
    CHANGECOUNT=CHANGESTEPS

  if (DIV == 2):
    outString += " & block 0 0,0,"+str(int(SXMID))+","+str(int(SYMID))+" "+str(int(SXMID))+",0 -1 1 0"
    outString += " & block 0 0,0,"+str(int(SXMID))+","+str(int(SYMID))+" 0,"+str(int(SYMID))+" -1 0 1"
    outString += " & block 0 0,0,"+str(int(SXMID))+","+str(int(SYMID))+" "+str(int(SXMID))+","+str(int(SYMID))+" -1 1 1"

  if (out == 112): #p
    call(["cmdwiz.exe", "getch"])

  if (out == 32): #space
    for i in range(0, 8):
      P[i]=randint(0,6)-3

  if (out == 99): #c
    PAL+=1
    if (PAL>3):
      PAL=0

  if (out == 111): #o
    DRAWOP+=1
    BITOP=3
    if (DRAWOP>5):
      DRAWOP=0

  if (out == 68): #D
    DELAY+=15

  if (out == 100): #d
    DELAY-=15
    if (DELAY<0):
      DELAY=0

  if (out == 98): #b
    BITOP+=1
    if (BITOP>10):
      BITOP=1

  if (out == 13): #ENTER
    DIV+=1
    if (DIV > 2):
      DIV=1
    XMID, YMID, XMUL, YMUL = W/2/DIV, H/2/DIV, W/2/DIV, H/2/DIV

  if (out == 97): #a
    call(["cmd", "/C", "cls"])
    print("P=[" + str(P[0]) + ", " + str(P[1]) + ", " + str(P[2]) + ", " + str(P[3]) + ", " + str(P[4]) + ", " + str(P[5]) + ", " + str(P[6]) + ", " + str(P[7]) + "]")
    print("SB=[" + str(SB[0]) + ", " + str(SB[1]) + ", " + str(SB[2]) + ", " + str(SB[3]) + ", " + str(SB[4]) + ", " + str(SB[5]) + ", " + str(SB[6]) + ", " + str(SB[7]) + "]")
    call(["cmdwiz.exe", "getch"])

  if process != 0:
     out = process.wait()
  process = Popen(["cmdgfx_gdi.exe", outString, "w"+str(DELAY)+"kfa:0,0,"+str(W)+","+str(H), PALETTES[PAL]])


Edit: oops, I accidentally included a 2ms wait per frame in this code. Try it again, it will run much more smooth :)
Last edited by misol101 on 26 Oct 2016 18:51, edited 2 times in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#71 Post by misol101 » 13 Oct 2016 17:18

New archive/repo update.

This time I added perspective correct texture mapping.

Here are two before/after screens from the new script 3dmaze.bat.

Affine:
Image

Perspective corrected:
Image

I saw a maze creator script by neorobin which was nice, so I decided to turn one of the mazes into 3d. Good luck finding your way to the end :) (cursor keys to move, or w/s/a/d and mouse)

While running, press 'RETURN' to switch between affine and perspective correct texture mapping. The latter is noticeably slower, especially since the new perspective tmapper is not optimized at all. It looks good though. Some wobblyness still exist if getting very close to walls.

All the other 3dworld batch scripts also use the new texturemapper now, press RETURN to change.
Last edited by misol101 on 16 Apr 2017 13:17, edited 1 time in total.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#72 Post by batchcc » 13 Oct 2016 17:29

I can't wait to try this maze out!

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#73 Post by misol101 » 14 Oct 2016 04:42

batchcc: Great to see some enthusiasm in this level-headed environment :D

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#74 Post by einstein1969 » 14 Oct 2016 08:19

@neorobin
very nice SIN alternative. I think your version is faster than precedence. I will post this version in the original thread of fastest sin x.

Francesco Poscettti aka einstein1969

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

#75 Post by misol101 » 09 Nov 2016 13:42

New version, archive and repo update.

1. Possible to use parts (blocks) of the current buffer as texturemaps for 3d objects. (plasma-cube.bat). This is an non-default extension to the obj 3d file format.

2. The image operation got optional width/height parameters to scale the image (gfxtest9.bat)

3. If a face in a 3d obj file only has 1 vertex AND a texture is set, the texture is drawn as an image instead of plotting a pixel (3d-bob.bat)

4. Mysterious "mode 6" was added as drawmode for 3d. I discovered this as a bug in my code but thought it was actually pretty neat in some cases. What it does is texturemap characters using affine texture mapping, but use perspective correction for the colors. This can create an interesting overlay effect (checkerbox.bat)

5. Second rotation for 3d possible after moving the object. (An example is in games\cmdrunner\cmdrunner_hz.bat where the cubes rotate with the horizon when flying)

6. For image and text operations, it is now possibly to use ? for fgcolor and/OR bgcolor, making it possible to e.g preserve the current bgcolor but setting the fgcolor. (now used in various scripts for help texts, e.g. interference.bat, bit-test.bat)

7. Bugfixes in perspective correct texturemapper and obj 3d object file reader

8. Added some additional scripts that do not actually show any new functionality in cmdgfx (shadebobs.bat, matrix01.bat, matrix-face.bat)

Image
Last edited by misol101 on 16 Apr 2017 13:16, edited 1 time in total.

Post Reply