Draw a sphere: Difference between revisions
Content added Content deleted
(Added Algol W) |
Simple9371 (talk | contribs) m (→{{header|Batch File}}: make the code slightly clearer) |
||
Line 1,142: | Line 1,142: | ||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
{{trans|C}}<br/> |
{{trans|C}}<br/> |
||
Since Batch Files do not support floating point, the input parameters for drawing the sphere are limited to integers only. < |
Since Batch Files do not support floating point, the input parameters for drawing the sphere are limited to integers only. The ''k'' parameter has been hardcoded to 2. The <code>ambient</code> variable for this code is scaled up 10 times of its value in C implementation. For example, <code>ambient = 0.1</code> in C code corresponds to <code>ambient = 1</code> here. |
||
Lastly, the variables used in calculations are scaled up 100 times of the actual values in C implementation, and then scaled down 100 times back for determination of shades. |
|||
Also, the variables used in calculations are scaled up 100 times of the actual values in C implementation, and then scaled down 100 times back for determination of shades. |
|||
<lang dos>:: Draw a Sphere Task from Rosetta Code |
<lang dos>:: Draw a Sphere Task from Rosetta Code |
||
:: Batch File Implementation |
:: Batch File Implementation |
||
@echo off |
@echo off |
||
rem -------------- define arithmetic "functions" |
rem -------------- define arithmetic "functions" |
||
Line 1,197: | Line 1,196: | ||
set "shades[9]=@" |
set "shades[9]=@" |
||
set "num_shades=9" %== start at 0 ==% |
set "num_shades=9" %== start at 0 ==% |
||
set "light[0]=30" & set "light[1]=30" & set "light[2]=-50" |
set "light[0]=30" & set "light[1]=30" & set "light[2]=-50" |
||
Line 1,203: | Line 1,202: | ||
setlocal enabledelayedexpansion |
setlocal enabledelayedexpansion |
||
%normalize% light %== normalize macro applied ==% |
%normalize% light %== normalize macro applied ==% |
||
⚫ | |||
rem note: due to scale up 100x of variables for calculations, |
|||
rem k=4 is the maximum value for k that does not cause overflow. |
|||
⚫ | |||
exit /b 0 |
exit /b 0 |
||
rem -------------- the function to draw the sphere |
rem -------------- the function to draw the sphere |
||
rem arguments: R |
rem arguments: R ambient |
||
:drawSphere |
:drawSphere |
||
rem initialize variables from arguments |
rem initialize variables from arguments |
||
set /a "R=%1", "negR=-R", "twiceR=R*2", "twiceNegR=negR*2" |
set /a "R=%1", "negR=-R", "twiceR=R*2", "twiceNegR=negR*2" |
||
set /a "sqrdR=R*R* |
set /a "sqrdR=R*R*100*100" %== R*R is mult. by 100*100 ==% |
||
set "k= |
set "k=2" %== k is hardcoded to 2 ==% |
||
set "ambient=%3" |
set "ambient=%3" |
||
rem start draw line-by-line |
rem start draw line-by-line |
||
for /l %%i in (%negR%, 1, %R%) do ( |
for /l %%i in (%negR%, 1, %R%) do ( |
||
set /a "x=100*%%i+ |
set /a "x=100*%%i+(100/2)" %== x is mult. by 100 ==% |
||
set "line=" |
set "line=" |
||
for /l %%j in (%twiceNegR%, 1, %twiceR%) do ( |
for /l %%j in (%twiceNegR%, 1, %twiceR%) do ( |
||
set /a "y= |
set /a "y=(100/2)*%%j+(100/2)" %== y is mult. by 100 ==% |
||
set /a "pythag = x*x + y*y" |
set /a "pythag = x*x + y*y" |
||
if !pythag! lss !sqrdR! ( |
if !pythag! lss !sqrdR! ( |
||
Line 1,251: | Line 1,248: | ||
goto :EOF</lang> |
goto :EOF</lang> |
||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> eeeeeeeeee&&&&&## |
||
&& |
eoooo*****ooooooooeeeee&&&&###% |
||
& |
oo******!!!!!********oooooeeee&&&&###%% |
||
o**!!!!!!!!!!!!!!!!!!*****oooooeeee&&&&###%%% |
|||
o**!!!!:::::::::::!!!!!!!!!****oooooeee&&&&&###%%%% |
|||
o*!!!:::::::::::::::::::!!!!!!*****ooooeeee&&&&####%%%% |
|||
o*!!!:::::........:::::::::!!!!!!*****oooeeee&&&&&####%%%%@ |
|||
o*!!!::::.............::::::::!!!!!!****ooooeeee&&&&####%%%%%@@ |
|||
**!!::::.................::::::!!!!!!*****ooooeeee&&&&####%%%%%%@ |
|||
e*!!!::::..................:::::::!!!!!!****ooooeeee&&&&#####%%%%%@@@ |
|||
o*!!!:::....................::::::!!!!!!!****ooooeeee&&&&&####%%%%%%@@@ |
|||
e**!!::::....................::::::!!!!!!*****ooooeeee&&&&#####%%%%%%@@@@ |
|||
e**!!!::::..................::::::::!!!!!!****ooooeeeee&&&&#####%%%%%%%@@@@ |
|||
o**!!:::::..................:::::::!!!!!!*****ooooeeeee&&&&#####%%%%%%%@@@@ |
|||
eo*!!!::::::...............::::::::!!!!!!*****ooooeeeee&&&&&#####%%%%%%%@@@@@ |
|||
o**!!!!:::::::.........::::::::::!!!!!!!*****oooooeeee&&&&&&####%%%%%%%%@@@@@ |
|||
eo**!!!!!:::::::::::::::::::::::!!!!!!!!*****oooooeeeee&&&&&#####%%%%%%%%@@@@@@ |
|||
eoo**!!!!!::::::::::::::::::::!!!!!!!!******oooooeeeee&&&&&######%%%%%%%@@@@@@@ |
|||
eoo***!!!!!:::::::::::::::::!!!!!!!!*******ooooeeeeee&&&&&######%%%%%%%%@@@@@@@ |
|||
eoo****!!!!!!!!!!:::!:!!!!!!!!!!!!*******oooooeeeeee&&&&&######%%%%%%%%@@@@@@@@ |
|||
eeoo****!!!!!!!!!!!!!!!!!!!!!!!!********oooooeeeeee&&&&&&#####%%%%%%%%%@@@@@@@@ |
|||
&eeoo******!!!!!!!!!!!!!!!!!*********ooooooeeeeee&&&&&&######%%%%%%%%%@@@@@@@@@ |
|||
&eeeooo********!*!!!!!************oooooooeeeeeee&&&&&&######%%%%%%%%%@@@@@@@@@@ |
|||
##&&&eeeeoooooooooooooooooooooooeeeeeee&&&&&&&#############%%%%%%%%%%%%%%%%%%%% |
|||
#&eeeooooo********************ooooooooeeeeeeee&&&&&&#######%%%%%%%%%@@@@@@@@@@@ |
|||
&&eeeeoooooooo*********oooooooooooeeeeeeee&&&&&&&&######%%%%%%%%%%@@@@@@@@@@@ |
|||
#&&&eeeeeooooooooooooooooooooooeeeeeeeee&&&&&&&&#######%%%%%%%%%%@@@@@@@@@@@@ |
|||
#&&&&eeeeeeeeoooooooooeeeeeeeeeeeeee&&&&&&&&########%%%%%%%%%%@@@@@@@@@@@@@ |
|||
% |
%##&&&&&eeeeeeeeeeeeeeeeeeeeeeee&&&&&&&&&&########%%%%%%%%%%%@@@@@@@@@@@@@@ |
||
%########### |
%###&&&&&&&&eeeeeeeeeeeee&&&&&&&&&&&&&########%%%%%%%%%%%%@@@@@@@@@@@@@@@ |
||
%%############### |
%%####&&&&&&&&&&&&&&&&&&&&&&&&&&###########%%%%%%%%%%%%%@@@@@@@@@@@@@@@ |
||
%%%#################### |
%%%#######&&&&&&&&&&&&&&&&#############%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@ |
||
%%%##############################%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@ |
|||
%%%%%%%####################%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@ |
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@ |
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@ |
||
%%%%%%%%%%%%%%%%%%%%%%%%% |
@@%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@ |
||
%%%%%%%%%%% |
@@@@@@%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
|||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
|||
@@@@@@@@@@@@@@@@@</pre> |
|||
=={{header|Befunge}}== |
=={{header|Befunge}}== |