Draw a sphere: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added notes about show output when executing on an ASCII machine.)
m ({{out}})
Line 1: Line 1:
{{task}}{{requires|Graphics}}
{{task}}{{requires|Graphics}}


The task is to draw a sphere. The sphere can be represented graphically, or in ascii art, depending on the language capabilities. Either static or rotational projection is acceptable for this task.
The task is to draw a sphere. The sphere can be represented graphically, or in ascii art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.


=={{header|Ada}}==
=={{header|Ada}}==
Line 268: Line 269:
END
END
</lang>
</lang>
{{out}}
Output:
[[File:Sphere_BBC.jpeg]]
[[File:Sphere_BBC.jpeg]]


Line 335: Line 336:


return 0;
return 0;
}</lang>
}</lang>Output:<lang> #############%%%%
{{out}}
<pre> #############%%%%
##&&eeeeeeeeee&&&&&&&####%%%%%%%%
##&&eeeeeeeeee&&&&&&&####%%%%%%%%
&&eeooooooooooooooeeeee&&&&######%%%%%%%%
&&eeooooooooooooooeeeee&&&&######%%%%%%%%
Line 395: Line 398:
eeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeee </lang>
eeeeeeeeeeeee </pre>


===Fun with 3D noise texture===
===Fun with 3D noise texture===
Line 767: Line 770:
</lang>
</lang>


{{out}}
Output:
<pre>
<pre>
&&&&&&&&&&#######
&&&&&&&&&&#######
Line 890: Line 893:
drawSphere(19, 4, 0.1);
drawSphere(19, 4, 0.1);
</lang>
</lang>

=={{header|Go}}==
=={{header|Go}}==
[[file:GoSphere.png|right|thumb|Output png]]
[[file:GoSphere.png|right|thumb|Output png]]
Line 1,103: Line 1,107:
}
}
}</lang>
}</lang>
{{out}}
Output:
<pre> &&&&&&&&&&#######
<pre> &&&&&&&&&&#######
&eeeeeeeeeeeeeeee&&&&&&#######%
&eeeeeeeeeeeeeeee&&&&&&#######%
Line 1,316: Line 1,320:
draw_sphere (20, 4, 0.1)
draw_sphere (20, 4, 0.1)
draw_sphere (10, 2, 0.4)</lang>
draw_sphere (10, 2, 0.4)</lang>
{{out}}
Output:
<pre> &&&&&&&&&&&&#####
<pre> &&&&&&&&&&&&#####
&eeeoooooooooeeeeee&&&&&#######
&eeeoooooooooeeeeee&&&&&#######
Line 1,430: Line 1,434:
drawSphere 20, 4.0, 0.1
drawSphere 20, 4.0, 0.1
drawSphere 10, 2.0, 0.4</lang>
drawSphere 10, 2.0, 0.4</lang>
{{out}}
Output:
<pre> &&&&&&&&&&#######
<pre> &&&&&&&&&&#######
&eeeeeeeeeeeeeeee&&&&&&#######%
&eeeeeeeeeeeeeeee&&&&&&#######%
Line 1,698: Line 1,702:
(drawSphere 20.0 4 0.1)
(drawSphere 20.0 4 0.1)
(drawSphere 10.0 2 0.4)</lang>
(drawSphere 10.0 2 0.4)</lang>
{{out}}
Output:
<pre> ##############%%%
<pre> ##############%%%
#&&eeeeeeeeeee&&&&&&######%%%%%
#&&eeeeeeeeeee&&&&&&######%%%%%
Line 2,122: Line 2,126:
draw_sphere(20,4,0.1, light)
draw_sphere(20,4,0.1, light)
draw_sphere(10,2,0.4, light)</lang>
draw_sphere(10,2,0.4, light)</lang>
{{out}}
Output:
<pre> &&&&&&&&&&######
<pre> &&&&&&&&&&######
&&eeeeeeeeeeeeeeee&&&&&&######%%
&&eeeeeeeeeeeeeeee&&&&&&######%%
Line 2,187: Line 2,191:


===Python: Using Pygame===
===Python: Using Pygame===
Renders a sphere with random Perlin noise. This code contains unnecessary functions which are part of a 3D graphics library I wrote. Uses Pygame and Python 3.2.2
Renders a sphere with random Perlin noise.
This code contains unnecessary functions which are part of a 3D graphics library I wrote.
Uses Pygame and Python 3.2.2
[[File:PythonSphere.png]]
[[File:PythonSphere.png]]
<lang python>
<lang python>
Line 3,025: Line 3,031:
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end
numeric digits d; return g/1</lang>
numeric digits d; return g/1</lang>
'''output''' &nbsp; when executed on an ASCII machine:
{{out}} when executed on an ASCII machine:
<pre style="height:105ex">
<pre style="height:105ex">
eeeeeeeeee@@@@@@@
eeeeeeeeee@@@@@@@