I like your interactive version!
I have found the initial article that had inpired me for porting the behavior . This is the link.
The initial project is not based on porting but generating something similar, but in the end it seems copied
I have seen that you begin using html5 canvas. I don't know but perhaps you can use with HTA
For HTA demo you can try 1kjs. I have ported some js in hta in the past. Should I look for in my backup ...
But back to the dos batch.
For modify the code I need remember the initial work. (but i don't remeber).
Then I resume my work here.
The initial work is on CUBE (a rotating cube). This work use the FILLRECT (javascript is the language
that i used for porting varius graphic application and fillrect is very fast graphics canvas instruction)
The sphere use the PLOT function. The dos batch version is faster than FILLRECT.
This is the code for cube. In this code there are some comments on various operations and the variables
are more easy to understand.
For rotate on Z,X,Y change the ZA,XA,YA angle.
Code: Select all
@echo off & set /a cols=55, lines=50 & goto :Init_system
________________
/| /|
/ / |
/ | / |
/_______________/ |
| | | |
| | |
| | | |
| | |
| | | |
| -----------|---|
| / | /
| | /
|/ | /
|_______________|/
Reference:
http://en.wikipedia.org/wiki/Rotation_(mathematics)
http://www.bit-101.com/tutorials/perspective.html
http://en.wikipedia.org/wiki/3D_projection
:Main
set t0=!time!
(setlocal & rem for /F "delims==" %%v in ('set') do set "%%v="
set AF=1 %anti flikering. Keep redraw near timer coalescing for windows 7 and up%
set /a t=100000, rn=0, n=t
set /a "pf[1].x=-35+5, pf[1].y=35, pf[1].z=35"
set /a "pf[2].x=35+5, pf[2].y=35, pf[2].z=35"
set /a "pf[3].x=35+5, pf[3].y=-35, pf[3].z=35"
set /a "pf[4].x=-35+5, pf[4].y=-35, pf[4].z=35"
set /a "pf[5].x=35+5, pf[5].y=35, pf[5].z=-35"
set /a "pf[6].x=-35+5, pf[6].y=35, pf[6].z=-35"
set /a "pf[7].x=35+5, pf[7].y=-35, pf[7].z=-35"
set /a "pf[8].x=-35+5, pf[8].y=-35, pf[8].z=-35"
set /a "pf[9].x=5, pf[y].y=0, pf[8].z=0"
set /a np=9
rem for generate more point change in if 1=1 ...
if 1==2 (
set /a np=3
for /L %%n in (1,1,!np!) do set /a "pf[%%n].x=(%%n-2)*35+5, pf[%%n].y=0, pf[%%n].z=0"
set /a np+=3
for /L %%n in (4,1,!np!) do set /a "pf[%%n].x=(%%n-5)*35+5, pf[%%n].y=35, pf[%%n].z=0"
set /a np+=3
for /L %%n in (7,1,!np!) do set /a "pf[%%n].x=(%%n-8)*35+5, pf[%%n].y=-35, pf[%%n].z=0"
set /a np+=3
for /L %%n in (10,1,!np!) do set /a "pf[%%n].x=(%%n-11)*35+5, pf[%%n].y=0, pf[%%n].z=35"
set /a np+=3
for /L %%n in (13,1,!np!) do set /a "pf[%%n].x=(%%n-14)*35+5, pf[%%n].y=35, pf[%%n].z=35"
set /a np+=3
for /L %%n in (16,1,!np!) do set /a "pf[%%n].x=(%%n-17)*35+5, pf[%%n].y=-35, pf[%%n].z=35"
set /a np+=3
for /L %%n in (19,1,!np!) do set /a "pf[%%n].x=(%%n-20)*35+5, pf[%%n].y=0, pf[%%n].z=-35"
set /a np+=3
for /L %%n in (22,1,!np!) do set /a "pf[%%n].x=(%%n-23)*35+5, pf[%%n].y=35, pf[%%n].z=-35"
set /a np+=3
for /L %%n in (25,1,!np!) do set /a "pf[%%n].x=(%%n-26)*35+5, pf[%%n].y=-35, pf[%%n].z=-35"
)
for /L %%N in (100000,1,110000) do (
for /L %%n in (1,1,!np!) do set /a "p[%%n].x=pf[%%n].x, p[%%n].y=pf[%%n].y, p[%%n].z=pf[%%n].z"
::rotazione asse Y, X o Z in radians!
set /a yA = 10000*4/100*%%N, ZA = 10000*6/100*%%N, XA = 10000*2/100*%%N
:: calcolo il seno
set /a "a0=yA, a=a0 %% 62832, b0s=(a>>31|1)*a"
if !b0s! gtr 47124 (set /a "a=a-(a>>31|1)*62832, s=%SIN%"
) else (if !b0s! gtr 15708 (set /a "a=(a>>31|1)*31416-a, s=%SIN%"
) else set /a "s=%SIN%"
)
:: calcolo il coseno. Cos(x)=Sin(PI/2-x)
set /a "a0=yA, a=(15708-a0) %% 62832, b0c=(a>>31|1)*a
if !b0c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, c=%SIN%"
) else (if !b0c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, c=%SIN%"
) else set /a "c=%SIN%"
)
:: calcolo il seno
set /a "a0=ZA, a=a0 %% 62832, b0s=(a>>31|1)*a"
if !b0s! gtr 47124 (set /a "a=a-(a>>31|1)*62832, s1=%SIN%"
) else (if !b0s! gtr 15708 (set /a "a=(a>>31|1)*31416-a, s1=%SIN%"
) else set /a "s1=%SIN%"
)
:: calcolo il coseno. Cos(x)=Sin(PI/2-x)
set /a "a0=ZA, a=(15708-a0) %% 62832, b0c=(a>>31|1)*a
if !b0c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, c1=%SIN%"
) else (if !b0c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, c1=%SIN%"
) else set /a "c1=%SIN%"
)
:: calcolo il seno
set /a "a0=XA, a=a0 %% 62832, b0s=(a>>31|1)*a"
if !b0s! gtr 47124 (set /a "a=a-(a>>31|1)*62832, s2=%SIN%"
) else (if !b0s! gtr 15708 (set /a "a=(a>>31|1)*31416-a, s2=%SIN%"
) else set /a "s2=%SIN%"
)
:: calcolo il coseno. Cos(x)=Sin(PI/2-x)
set /a "a0=XA, a=(15708-a0) %% 62832, b0c=(a>>31|1)*a
if !b0c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, c2=%SIN%"
) else (if !b0c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, c2=%SIN%"
) else set /a "c2=%SIN%"
)
:: rotazione
for /L %%n in (1,1,!np!) do set /a "rotx = (p[%%n].x * c - p[%%n].y * s)/10000, roty = (p[%%n].x * s + p[%%n].y * c)/10000, p[%%n].x=rotx, p[%%n].y=roty, rotx = (p[%%n].x * c1 - p[%%n].z * s1)/10000, rotz = (p[%%n].x * s1 + p[%%n].z * c1)/10000, p[%%n].x=rotx, p[%%n].z=rotz, roty = (p[%%n].y * c2 - p[%%n].z * s2)/10000, rotz = (p[%%n].y * s2 + p[%%n].z * c2)/10000, p[%%n].y=roty, p[%%n].z=rotz"
:: proiezione 3d to 2d
for /L %%n in (1,1,!np!) do set /a "px[%%n] = (p[%%n].x * 150) / (p[%%n].z + 350) + %cols%/2, pY[%%n] = (p[%%n].y * 150) / (p[%%n].z + 350) + %lines%/2"
:: Riempio buffer
for /L %%n in (1,1,!np!) do (
:: Fillrect macro - call :fillrect_1 px[%%n] py[%%n] px[%%n]+1 py[%%n] 4
if !px[%%n]! gtr 0 if !py[%%n]! gtr 0 if !px[%%n]! lss !cols! if !py[%%n]! lss !lines! Set /a x1=px[%%n], y1=py[%%n], W=1, H=1, c=4, %FILLRECT%
)
rem if not "!OT!"=="!time:~10,1!" (
rem set | more
:: call :Flush_BufferScreen
cls & For /L %%l in (1,1,%lines%) do echo( !_%%l!
rem ping -n 2 127.0.0.1 >nul
call :clr_screenBuffer
set /a rn+=1
set OT=!time:~10,1!
rem )
if %%N gtr !t! (
for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
if defined AF (set /a "FPS=rn*100/a, t+=(FPS+100)") else set /a "FPS=(%%N-100000)*100*10/a, t+=(FPS+800)"
title FPS=!FPS!
set a=&set FPS=
)
)
endlocal)
goto :eof
:prepare_fillrect_1
set L[0]=%empty%
For /L %%l in (1,1,%cols%) do set "L[1]=!L[1]!°"
For /L %%l in (1,1,%cols%) do set "L[2]=!L[2]!±"
For /L %%l in (1,1,%cols%) do set "L[3]=!L[3]!²"
For /L %%l in (1,1,%cols%) do set "L[4]=!L[4]!Û"
goto :eof
:Flush_BufferScreen
cls
For /L %%l in (1,1,%lines%) do echo( !_%%l!
goto :eof
:clr_screenBuffer
For /L %%l in (1,1,%lines%) do set _%%l=%empty%
goto :eof
:init_screenbuffer
set Empty=
For /L %%l in (1,1,%cols%) do set "empty=!empty! "
goto :eof
:Init_system
set /a cc=cols+2, ll=lines+3
mode %cc%,%ll%
cls
setlocal DisableDelayedExpansion
set "FILLRECT=y2=y1+H-1, X2=x1+W & For /F "tokens=1-4" %%u in ("!x1! !c! !W! !X2!") do"
set "FILLRECT=%FILLRECT% For /L %%y in (!y1!,1,!y2!) do set _%%y="
set "FILLRECT=%FILLRECT%!_%%y:~0,%%u!!L[%%v]:~0,%%w!!_%%y:~%%x!"
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)"
setlocal EnableDelayedExpansion
call :init_screenbuffer
Call :clr_screenbuffer
Call :prepare_fillrect_1
Goto :Main
but this cube stuff don't like me and then i moved into sphere.
TO be continued...
einstein1969