Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
misol101
Posts: 357
Joined: 02 May 2016 18:20

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

#91 Post by misol101 » 29 Mar 2018 14:12

Moved from elsewhere:

Coincidentally, I had just made a bouncing ball script using the "opposite" of "pure batch" - javascript for logic and cmdgfx for rendering. Here is a screenshot with 50 balls, with a shadow for each ball, running at 76 FPS:

Image

Archive is here: http://www.mediafire.com/file/ihbnkm2wy ... bounce.zip

By the way, this is an interesting way to test the speed of your machine (CPU). Press Cursor left to remove 10 balls, and cursor right to add 10 balls. Then observe the top left text within paranthesis. As long as it is 76 or more, you are still running at full frame rate.

On my Win7 machine, I can do 340 balls before FPS starts going down. At 500 balls (maximum) it's down to 46 FPS.

And code:

Code: Select all

@if (true == false) @end /*
@echo off
if defined __ goto :START
set __=.
cmdgfx_input.exe knW13x | call %0 %* | cmdgfx_gdi "" Sf0:0,0,320,220,240,100G16,16
set __=
cmdwiz showcursor 1 & goto :eof

:START
cmdwiz setfont 6 & cls & mode 120,50 & cmdwiz showcursor 0
cscript //nologo //e:javascript "%~dpnx0" %*
::cmdwiz getch & rem Enable this line to see jscript parse errors
mode 80,50
echo "cmdgfx: quit"
title input:Q
exit /b 0 */

var maxBalls=500, nofShownBalls=50, w=240, h=100
var ballsX=[], ballsY=[], ballsSX=[], ballsI=[], ballsYC=[], ballsYH=[], ballsSXcale=[], ballsCol=[]
var bI = ["ball4-t.gxy"], bIw = [13,11,9], bIh = [10,8,6]

var multiCol=1, shadow=1, extraFlag=""
var showHelp=1, helpMsg="text 7 0 0 SPACE\\-ENTER\\-\\g11\\g10\\-p\\-h 1,98", skip=["rem "," "]

for (i = 0; i < maxBalls; i++) {
	ballsX.push(Math.floor(Math.random() * w))
	ballsY.push(Math.floor(Math.random() * h))
	ballsSX.push(Math.random() * 1.8 + 0.1)
	ballsYC.push(Math.random() * Math.PI + Math.PI);
	ballsYH.push(Math.floor(Math.random() * 50) + 45);
	ballsI.push(Math.floor(Math.random() * bI.length))
	ballsSXcale.push(Math.floor(Math.random() * bIw.length))
	ballsCol.push(Math.floor(Math.random() * 6))
}

WScript.Echo("\"cmdgfx: fbox 1 0 X & image ball4-t.gxy 0 0 0 -1 260,0 & image ball4-t.gxy 0 0 0 -1 282,2 0 0 11,8 & image ball4-t.gxy 0 0 0 -1 303,4 0 0 9,6" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,10 -1 0 0 c4??=91??,?4??=?1??,c???=9???,?c??=?9??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,20 -1 0 0 c4??=a2??,?4??=?2??,c???=a???,?c??=?a??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,30 -1 0 0 c4??=d5??,?4??=?5??,c???=d???,?c??=?d??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,40 -1 0 0 c4??=e6??,?4??=?6??,c???=e???,?c??=?e??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,50 -1 0 0 c4??=78??,?4??=?8??,c???=7???,?c??=?7??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,60 -1 0 0 c4??=b3??,?4??=?3??,c???=b???,?c??=?b??" + "\" ")

while(true) {
	outString="fbox 1 0 b1 0,0," + w + "," + h + " & fbox 1 0 b0 0," + (h-8) + "," + w + ",8"
	for (i = 0; i < nofShownBalls; i++) {
		ballsX[i] = (ballsX[i] + ballsSX[i]);
		if (ballsX[i] > w || ballsX[i] < 0) ballsSX[i] = -ballsSX[i];
		ballsY[i] = Math.floor(Math.sin(ballsYC[i]) * ballsYH[i]) + 95;
		ballsYC[i] += 0.025; if (ballsYC[i] > Math.PI*2) { ballsYC[i] = Math.PI; } // ballsYH[i]*=0.7;
		outString += "& block 0 " + (260 + ballsSXcale[i]*20) + "," + (ballsCol[i] * 10 * multiCol) + ",13,10 " + Math.floor(ballsX[i]-bIw[ballsI[i]]/2) + "," + Math.floor(ballsY[i]-bIh[ballsI[i]]/2) + " 58"
	}
	if (shadow==1) outString += " & block 0 0,0," + w + "," + h + " 0," + h + " -1 0 0 10b1=1058" + " & block 0 0,0," + w + "," + h + " 8,-2 -1 0 0 10b?=10b1,????=10b0" + " & block 0 0," + h + "," + w + "," + h + " 0,0 58" ;
	WScript.Echo("\"cmdgfx:" + outString + " & " + skip[showHelp] + helpMsg + " & text a 0 0 " + nofShownBalls + ":_[FRAMECOUNT] 1,1" + "\" " + extraFlag)
	extraFlag=""

	var input = WScript.StdIn.ReadLine()
	var ti = input.split(" ")
	if (ti[3] == "1")
	{
		var key=ti[5]
		if (key == "27") break
		if (key == "32") multiCol = 1 - multiCol
		if (key == "13") shadow = 1 - shadow
		if (key == "104") showHelp = 1 - showHelp
		if (key == "331") { nofShownBalls-=10; if (nofShownBalls <= 0) nofShownBalls = 1; extraFlag="C" }
		if (key == "333") { nofShownBalls+=10; if (nofShownBalls > maxBalls) nofShownBalls = maxBalls; extraFlag="C" }
		if (key == "112") WScript.Echo("\"cmdgfx: \" K")
	}
}
If speed is the aim, I'd strongly recommend a Javascript / batch hybrid. We are talking magntitudes of 10-100 times faster than Batch. Still not as fast as compiled C of course, but still...

IcarusLives
Posts: 97
Joined: 17 Jan 2016 23:55

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

#92 Post by IcarusLives » 29 Mar 2018 14:22

I am absolutely in love with your graphics and animations! Excellent work, my friend!

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

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

#93 Post by misol101 » 06 Jun 2018 20:43

Repo and archive was updated. Most importantly, this version brings added speed to the GDI version, especially for when running fullscreen or with large windows.

For example, on my Win10 machine, the fullscreen example script servH-zoom-maximized-custom-palette.bat can now run at 80 FPS (previously 33) on my 1920x1080 desktop.

( On a technical note, I found that CreateDIBSection and manipulating the bitmap directly was much faster than calling CreateBitmap every frame)

Full list of changes:

1. Cmdgfx_gdi.exe output speed improved
2. Performance for textures with transparency ('3d/tpoly' operations) was improved (see e.g. servH-sphere-texture.bat)
3. 'fbox' operation now accepts three params only to clear entire buffer
4. 'Image' and 'text' operation: possible to precede text color with '\' to mean that '\' codes should not be treated specially at all (=plaintext)
5. Forcing foreground or background color now supported for 'text' operation also (by preceding color with a '-' character)
6. 'G' flag minimum now 16,16 (plus bug fix)
7. Bug fix: starting cmdgfx with 'fc' font no longer captures a screenshot
8. When reading gxy files, tab(9) is now written as space if encountered plain (not if written as \g09)
9. The 'image', 'tpoly', and '3d' operations now has a workaround to support spaces in filenames. All spaces must be replaced with a '~' character when provided to these operations

As for the scripts, all remaining dependencies on BG.exe was finally removed completely. The window manager BWin (viewtopic.php?f=3&t=8484) was added to the archive, as well as the scripts 'server-objsplit.bat' (image below), and 'server-bounce-js.bat' (image above)

Image

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

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

#94 Post by misol101 » 21 Aug 2018 18:37

Repo and archive was updated.

This is a minor release, but it still has a fairly large number of changes:

1. cmdgfx_input: Added 'R' flag to report on the dimensions of the current window, since in Win10 any cmd window can be resized with the mouse. When 'R' is enabled, event data sent by cmdgfx_input has the following extra data added: RESIZE_EVENT 0 W 220 H 75. If RESIZE_EVENT was 1, then the window was just resized and we can respond to this from within our script. The window manager BWin (included in the archive) now uses this functionality, as well as new example script 'server-checkerbox-resizeable.bat'. Another more lazy way of dealing with resizing of console windows is to disable this functionality for the current window: use cmdwiz setwindowstyle clear standard 0x00040000L

2. Added a window title for all server script examples and games (not sure why I didn't earlier). Also, for pixel font examples, I added a list of available keys in the title

3. New flag 'U' for cmdgfx_gdi to draw not into console window but anywhere on desktop! This can be used for example to force fullscreen even on Windows 7. Beware though, it really draws on top of everything else. (Note that "cmdwiz fullscreen" operation is now using official 100% fullscreen API, but it does not work on Windows 7)
4. New flag 'I' to to enable using title bar for cmdgfx (same as cmdgfx_input can do), to avoid file writes to 'servercmd.dat'. Title must be set as output: "operations" flags. Use output: "" flags to only set flags. (Former 'I' flag is now 'J')
5. New flag 'Ln,n' to affect light calculations for 3d operation in mode 1, draw option 0 (used in 'server-lsystem-js-3d.bat')
6. New flag 'd' for error messages, to write out the actual full erroneous operation in case of an error

7. Bug fix: If a material was set in an obj file and a face with two points was encountered, nothing was drawn. Now draws a line like it should (ignoring the bitmap)
8. Bug fix: Draw single vertex face in mode 1(z-sourced light) as bitmap if material set (as in mode 0,5,6). Still not drawn for mode 2-4 (not possible in mode 2, not logical in mode 3-4)

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

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

#95 Post by misol101 » 15 Nov 2018 01:58

Archive and repo update

Actually, the cmdgfx executable(s) hardly changed at all. The only changes were: 1. A few bug fixes regarding cmdblock 2. Added resource info to the executables 3. Cmdwiz (the companion program) had 'getfullscreen' operation added.

Fullscreen / resizable effects
Every single script (except 4, where it was too cumbersome) was changed to support the 'R' flag. This means that all those scripts can now be freely window resized, and switched to fullscreen (using either Alt-Enter on Win10, or Ctrl-Enter on Win7). Naturally, running fullscreen requires more CPU power, and especially some of the heavier scripts are very likely to stutter on slower machines.

Screensavers
11 of the scripts were duplicated to become 'screensaver' scripts (with script name starting with 'ScreenSaver'). This just means that these scripts start fullscreen,and that they are shut down if any key or mouse key is pressed. In order to actually use these scripts as Window screensavers, download "Screen Launcher" from http://www.softpedia.com/get/Desktop-En ... cher.shtml, and then choose ScreenLauncher from Windows screensaver settings and point it to any of the ScreenSaver scripts.

Post Reply