This is my old project for draw a sphere on console using the trick of font Lucida Console size 5 and the "shadow" chars
and the findstr colour mode.
I use an external MATH until a dos batch MATH is not avaible. The SQRT is ready. Lack the EXP/POW at the moments. But my goal is do in "native/pure" mode.
I need discovery a mechanism for create RIGHT colors on console and on image file ( I have open a separated thread )
Antialiasing and dithering ,small fonts usage and unicode use are other goals.
I hope that you can contribute to this work. TIA
Yuo can port in HTA for best view. See Aacini works!
results:
- Use Lucida console font 5
- Disable ClearType
- Enable "Smooth Edges of Screen Fonts"
code:
Code: Select all
@echo off & setlocal EnableDelayedExpansion
rem Use Lucida Console font size 5
rem Version 2.0.9.2 dec-2015
rem by einstein1969
rem http://rosettacode.org/wiki/Draw_a_sphere
mode 90,70
color 0f
pushd "%TMP%"
if not exist FPU-Module.js echo WScript.Stdout.WriteLine(eval(WScript.Stdin.ReadLine().replace(/\x22/g,"")));> FPU-Module.js
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%" > "'"
set "color1=778707880880880000000034"
set "color2=FFFFFFF7F7F7777F88788043"
set "char=Û²²±²°±Û±²°²±°±°Û²°±° "
set numshadesH=23
set "light[0]=30"
set "light[1]=30"
set "light[2]=-50"
call :normalize2 light
<nul set/p "=%DEL% °"
call :draw_sphereH2 8 3.5 0.20
call :draw_sphereH2 8 1.5 0.10
call :draw_sphereH2 8 3.5 0.10
call :draw_sphereH2 8 32.0 0.05
del $$$.color.txt
del '
popd
pause
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::
:draw_sphereH2 raggio k ambiente
set R=%1
set k=%2
set ambiente=%3
call :calculate2 "Math.floor(-!R!)" floorI
call :calculate2 "Math.ceil(!R!)" CeilI
For /L %%i in (!floorI!,1,!CeilI!) do (
call :calculate2 "%%i+0.5" x
call :calculate2 "Math.floor(-2*!R!)" floorJ
call :calculate2 "Math.ceil(2*!R!)" CeilJ
For /L %%j in (!floorJ!,1,!ceilJ!) do (
rem for aspect ratio "(%%j/2+0.5)" = y
call :calculate2 "!x!*!x! + (%%j/2+0.5)*(%%j/2+0.5) - !R!*!R!" inS
if "!inS:~0,1!"=="-" (
call :calculate2 "Math.round( (1 - (Math.pow(Math.max(0,-(!light[0]!*(!x!/Math.sqrt(!x!*!x!+(%%j/2+0.5)*(%%j/2+0.5)+(!R! * !R! -(!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5)))))+(!light[1]!)*((%%j/2+0.5)/Math.sqrt(!x!*!x!+(%%j/2+0.5)*(%%j/2+0.5)+(!R! * !R! - (!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5)))))+(!light[2]!)*(Math.sqrt(!R! * !R! - (!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5)))/Math.sqrt(!x!*!x!+(%%j/2+0.5)*(%%j/2+0.5)+(!R! * !R! - (!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5))))))),!k!)+!ambiente!)) * (!numshadesH! - 1) )" intensity
if "!intensity:~0,1!"=="-" set intensity=0
if !intensity! geq !numshadesH! set /a intensity=!numshadesH!-1
title !intensity!
for %%s in (!intensity!) do call :shadow %%s
) else (<nul set/p "=.%DEL%°")
)
echo(°
<nul set/p "=%DEL% °"
)
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::
:calculate2 expr retvar
echo "%~1" >%TMP%\in.txt
Cscript //nologo FPU-Module.js <%TMP%\in.txt >%TMP%\out.txt
set /p "%2=" <%TMP%\out.txt
set "%2=!%2:,=.!"
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::
:normalize2
set _0=!%1[0]!
set _1=!%1[1]!
set _2=!%1[2]!
call :calculate2 "!_0!/Math.sqrt(!_0!*!_0!+!_1!*!_1!+!_2!*!_2!)" %1[0]
call :calculate2 "!_1!/Math.sqrt(!_0!*!_0!+!_1!*!_1!+!_2!*!_2!)" %1[1]
call :calculate2 "!_2!/Math.sqrt(!_0!*!_0!+!_1!*!_1!+!_2!*!_2!)" %1[2]
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::
:shadow
(echo !char:~%1,1!\..\'
) > $$$.color.txt && findstr /a:!color1:~%1,1!!color2:~%1,1! /f:$$$.color.txt "."
goto :eof
einstein1969