Draw a sphere: Difference between revisions

Content added Content deleted
(Added Algol W)
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. <br/><br/>
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.
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> from C code corresponds to <code>ambient=1</code> here. <br/><br/>
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 ==%
call :drawSphere 20 1
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.
call :drawSphere 20 4 1
exit /b 0
exit /b 0


rem -------------- the function to draw the sphere
rem -------------- the function to draw the sphere
rem arguments: R k ambient
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*10000" %== R^2 is mult. by 100^2 ==%
set /a "sqrdR=R*R*100*100" %== R*R is mult. by 100*100 ==%
set "k=%2"
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+50" %== x is mult. by 100 ==%
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=50*%%j+50" %== y is mult. by 100 ==%
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&&&&&##
&&eeeeeeeeeeeeee&&&&&&#######%%
eoooo*****ooooooooeeeee&&&&###%
&eeooooooooooooooooeeeee&&&&&########%%
oo******!!!!!********oooooeeee&&&&###%%
eeoo****!!!!!*******ooooooeeee&&&&########%%%
o**!!!!!!!!!!!!!!!!!!*****oooooeeee&&&&###%%%
eoo**!!!!!!:::!:!!!!!!****ooooeeeee&&&&########%%%%
o**!!!!:::::::::::!!!!!!!!!****oooooeee&&&&&###%%%%
eoo*!!!::::::::::::::!!!!!***oooooeeee&&&&########%%%%%
o*!!!:::::::::::::::::::!!!!!!*****ooooeeee&&&&####%%%%
eo**!!::::........:::::::!!!!****oooeeeee&&&&########%%%%%%
o*!!!:::::........:::::::::!!!!!!*****oooeeee&&&&&####%%%%@
eoo*!::::.............::::::!!!!***ooooeeee&&&&&########%%%%%%%
o*!!!::::.............::::::::!!!!!!****ooooeeee&&&&####%%%%%@@
eo*!!:::.................:::::!!!****ooooeeee&&&&########%%%%%%%%
**!!::::.................::::::!!!!!!*****ooooeeee&&&&####%%%%%%@
&eo*!!:::..................::::!!!!!***ooooeeee&&&&#########%%%%%%%%%
e*!!!::::..................:::::::!!!!!!****ooooeeee&&&&#####%%%%%@@@
&oo*!:::....................::::!!!!****ooooeeee&&&&#########%%%%%%%%%%
o*!!!:::....................::::::!!!!!!!****ooooeeee&&&&&####%%%%%%@@@
&eo*!!:::....................::::!!!!***oooooeeee&&&&#########%%%%%%%%%%%
e**!!::::....................::::::!!!!!!*****ooooeeee&&&&#####%%%%%%@@@@
&eo**!!:::..................::::::!!!****ooooeeee&&&&&#########%%%%%%%%%%%%
e**!!!::::..................::::::::!!!!!!****ooooeeeee&&&&#####%%%%%%%@@@@
eoo*!!::::..................::::!!!!!***ooooeeeee&&&&##########%%%%%%%%%%%%
o**!!:::::..................:::::::!!!!!!*****ooooeeeee&&&&#####%%%%%%%@@@@
&eoo*!!!::::...............:::::!!!!!****oooeeeee&&&&&##########%%%%%%%%%%%%%
eo*!!!::::::...............::::::::!!!!!!*****ooooeeeee&&&&&#####%%%%%%%@@@@@
&eoo**!!::::::.........::::::::!!!!!***oooooeeeee&&&&##########%%%%%%%%%%%%%%
o**!!!!:::::::.........::::::::::!!!!!!!*****oooooeeee&&&&&&####%%%%%%%%@@@@@
&eeoo**!!!::::::::::::::::::::!!!!!****ooooeeeee&&&&&&##########%%%%%%%%%%%%%%%
eo**!!!!!:::::::::::::::::::::::!!!!!!!!*****oooooeeeee&&&&&#####%%%%%%%%@@@@@@
&eeoo***!!!!::::::::::::::!!!!!!!*****ooooeeeeee&&&&&##########%%%%%%%%%%%%%%%%
eoo**!!!!!::::::::::::::::::::!!!!!!!!******oooooeeeee&&&&&######%%%%%%%@@@@@@@
&&eeoo***!!!!!!!::!:!!!!!!!!!!!*****oooooeeeee&&&&&&###########%%%%%%%%%%%%%%%%
eoo***!!!!!:::::::::::::::::!!!!!!!!*******ooooeeeeee&&&&&######%%%%%%%%@@@@@@@
&&eeoooo***!!!!!!!!!!!!!!!!******ooooooeeeeee&&&&&&###########%%%%%%%%%%%%%%%%%
eoo****!!!!!!!!!!:::!:!!!!!!!!!!!!*******oooooeeeeee&&&&&######%%%%%%%%@@@@@@@@
#&&eeoooo********!!!*!********oooooooeeeeee&&&&&&############%%%%%%%%%%%%%%%%%%
eeoo****!!!!!!!!!!!!!!!!!!!!!!!!********oooooeeeeee&&&&&&#####%%%%%%%%%@@@@@@@@
#&&eeeoooooo**************ooooooooeeeeeee&&&&&&&############%%%%%%%%%%%%%%%%%%%
&eeoo******!!!!!!!!!!!!!!!!!*********ooooooeeeeee&&&&&&######%%%%%%%%%@@@@@@@@@
&eeeooo********!*!!!!!************oooooooeeeeeee&&&&&&######%%%%%%%%%@@@@@@@@@@
##&&&eeeeoooooooooooooooooooooooeeeeeee&&&&&&&#############%%%%%%%%%%%%%%%%%%%%
###&&&eeeeeeeoooooooooooooeeeeeeeeee&&&&&&&&#############%%%%%%%%%%%%%%%%%%%%%%
#&eeeooooo********************ooooooooeeeeeeee&&&&&&#######%%%%%%%%%@@@@@@@@@@@
###&&&&eeeeeeeeeeeeeeeeeeeeeeee&&&&&&&&&&##############%%%%%%%%%%%%%%%%%%%%%%
&&eeeeoooooooo*********oooooooooooeeeeeeee&&&&&&&&######%%%%%%%%%%@@@@@@@@@@@
#####&&&&&&eeeeeeeeeeeeeeee&&&&&&&&&&&###############%%%%%%%%%%%%%%%%%%%%%%%%
#&&&eeeeeooooooooooooooooooooooeeeeeeeee&&&&&&&&#######%%%%%%%%%%@@@@@@@@@@@@
######&&&&&&&&&&&&&&&&&&&&&&&&&&&&################%%%%%%%%%%%%%%%%%%%%%%%%%
#&&&&eeeeeeeeoooooooooeeeeeeeeeeeeee&&&&&&&&########%%%%%%%%%%@@@@@@@@@@@@@
%#########&&&&&&&&&&&&&&&&&&####################%%%%%%%%%%%%%%%%%%%%%%%%%%%
%##&&&&&eeeeeeeeeeeeeeeeeeeeeeee&&&&&&&&&&########%%%%%%%%%%%@@@@@@@@@@@@@@
%############################################%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%###&&&&&&&&eeeeeeeeeeeee&&&&&&&&&&&&&########%%%%%%%%%%%%@@@@@@@@@@@@@@@
%%#######################################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%####&&&&&&&&&&&&&&&&&&&&&&&&&&###########%%%%%%%%%%%%%@@@@@@@@@@@@@@@
%%%#################################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%#######&&&&&&&&&&&&&&&&#############%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@
%%%%%#########################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%##############################%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@
%%%%%%%%%#############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%####################%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@@@@@%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%</pre>
@@@@@@@@@@@@@@@@@</pre>


=={{header|Befunge}}==
=={{header|Befunge}}==