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:
=={{header|Batch File}}==
{{trans|C}}<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 <brcode>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<br/code> here.
TheLastly, <code>ambient</code>the variablevariables forused thisin codecalculations isare scaled up 10100 times of itsthe valueactual values in C implementation., Forand example,then <code>ambient=0.1</code>scaled fromdown C100 codetimes correspondsback tofor <code>ambient=1</code>determination here.of <br/><br/>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
:: Batch File Implementation
 
@echo off
rem -------------- define arithmetic "functions"
Line 1,197 ⟶ 1,196:
set "shades[9]=@"
set "num_shades=9" %== start at 0 ==%
 
set "light[0]=30" & set "light[1]=30" & set "light[2]=-50"
 
Line 1,203 ⟶ 1,202:
setlocal enabledelayedexpansion
%normalize% light %== normalize macro applied ==%
call :drawSphere 20 4 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
 
rem -------------- the function to draw the sphere
rem arguments: R k ambient
:drawSphere
rem initialize variables from arguments
set /a "R=%1", "negR=-R", "twiceR=R*2", "twiceNegR=negR*2"
set /a "sqrdR=R*R*10000100*100" %== R^2*R is mult. by 100^2*100 ==%
set "k=%2" %== k is hardcoded to 2 ==%
set "ambient=%3"
rem start draw line-by-line
for /l %%i in (%negR%, 1, %R%) do (
set /a "x=100*%%i+50(100/2)" %== x is mult. by 100 ==%
set "line="
for /l %%j in (%twiceNegR%, 1, %twiceR%) do (
set /a "y=50(100/2)*%%j+50(100/2)" %== y is mult. by 100 ==%
set /a "pythag = x*x + y*y"
if !pythag! lss !sqrdR! (
Line 1,251 ⟶ 1,248:
goto :EOF</lang>
{{Out}}
<pre> #eeeeeeeeee&&&&&&&&########
eoooo*****ooooooooeeeee&&eeeeeeeeeeeeee&&&&&&#######%%
oo******!!!!!********oooooeeee&eeooooooooooooooooeeeee&&&&&########%%
eeoo**o**!!!!!!!!!!!!!!!!!!*******ooooooeeeeoooooeeee&&&&########%%%
eooo**!!!!!!:::!::::::::!!!!!!!!!****ooooeeeeeoooooeee&&&&&########%%%%
eooo*!!!:::::::::::::::::::!!!!!!***oooooeeee**ooooeeee&&&&########%%%%%
eo*o*!!!:::::........:::::::::!!!!!!****oooeeeee*oooeeee&&&&&########%%%%%%@
eooo*!!!::::.............::::::::!!!!!!****ooooeeee&&&&&########%%%%%%%@@
eo**!!::::.................::::::!!!!!!*****ooooeeee&&&&########%%%%%%%%@
&eoe*!!!::::..................:::::::!!!!!!****ooooeeee&&&&#########%%%%%%%%%@@@
&ooo*!!!:::....................::::::!!!!!!!****ooooeeee&&&&&#########%%%%%%%%%%@@@
&eoe**!!::::....................::::::!!!!!!***oooooeeee**ooooeeee&&&&#########%%%%%%%%%%%@@@@
&eoe**!!!::::..................::::::::!!!!!!****ooooeeee&ooooeeeee&&&&#########%%%%%%%%%%%%@@@@
eooo**!!:::::..................:::::::!!!!!!*****ooooeeeee&&&&##########%%%%%%%%%%%%@@@@
&eooeo*!!!::::::...............::::::::!!!!!!****oooeeeee*ooooeeeee&&&&&##########%%%%%%%%%%%%%@@@@@
&eooo**!!!!:::::::.........::::::::::!!!!!!!***oooooeeeee**oooooeeee&&&&&&##########%%%%%%%%%%%%%%@@@@@
&eeooeo**!!!!!:::::::::::::::::::::::!!!!!!!!****ooooeeeee&*oooooeeeee&&&&&##########%%%%%%%%%%%%%%%@@@@@@
&eeoo*eoo**!!!!!::::::::::::::::::::!!!!!!!!*****ooooeeeeee*oooooeeeee&&&&&##########%%%%%%%%%%%%%%%%@@@@@@@
&&eeooeoo***!!!!!!!::!:::::::::::::::!!!!!!!!!!!*****oooooeeeee&**ooooeeeeee&&&&&###########%%%%%%%%%%%%%%%%@@@@@@@
&&eeooooeoo****!!!!!!!!!!:::!:!!!!!!!!!!!!******ooooooeeeeee&*oooooeeeeee&&&&&###########%%%%%%%%%%%%%%%%%@@@@@@@@
#&&eeoooo****eeoo****!!!*!!!!!!!!!!!!!!!!!!!!!********oooooooeeeeeeoooooeeeeee&&&&&&############%%%%%%%%%%%%%%%%%%@@@@@@@@
#&&eeeooooooeeoo******!!!!!!!!!!!!!!!!!********ooooooooeeeeeee&*ooooooeeeeee&&&&&&############%%%%%%%%%%%%%%%%%%%@@@@@@@@@
&eeeooo********!*!!!!!************oooooooeeeeeee&&&&&&######%%%%%%%%%@@@@@@@@@@
##&&&eeeeoooooooooooooooooooooooeeeeeee&&&&&&&#############%%%%%%%%%%%%%%%%%%%%
###&&&eeeeeeeoooooooooooooeeeeeeeeee&&eeeooooo********************ooooooooeeeeeeee&&&&&&#############%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@
###&&&&eeeeeeeeeeeeeeeeeeeeeeee&&eeeeoooooooo*********oooooooooooeeeeeeee&&&&&&&&##############%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@
#####&&&&&&eeeeeeeeeeeeeeee&&&eeeeeooooooooooooooooooooooeeeeeeeee&&&&&&&&###############%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@
######&&&&&&&&&&&&&&&&&&&&eeeeeeeeoooooooooeeeeeeeeeeeeee&&&&&&&&################%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@
%#########&&&&&&&&eeeeeeeeeeeeeeeeeeeeeeee&&&&&&&&&&####################%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@
%###&&&&&&&&eeeeeeeeeeeee&&&&&&&&&&&&&#########################################%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@
%%####&&&&&&&&&&&&&&&&&&&&&&&&&&###################################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@
%%%#######&&&&&&&&&&&&&&&&##########################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@
%%%%%##############################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@
%%%%%%%%%####################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@
@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@
@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%%%%%%%%%@@@@@@@@@@@@@@@@@</pre>
 
=={{header|Befunge}}==