Draw a sphere: Difference between revisions
Content added Content deleted
Simple9371 (talk | contribs) m (→{{header|BASIC256}}: About output) |
Simple9371 (talk | contribs) (Add VBScript) |
||
Line 4,292: | Line 4,292: | ||
\end{tikzpicture} |
\end{tikzpicture} |
||
\end{document}</lang> |
\end{document}</lang> |
||
=={{header|VBScript}}== |
|||
{{trans|C}} |
|||
<lang vb>shades = Array(".", ":", "!", "*", "o", "e", "&", "#", "%", "@") |
|||
light = Array(30, 30, -50) |
|||
Sub Normalize(v) |
|||
length = Sqr(v(0)*v(0) + v(1)*v(1) + v(2)*v(2)) |
|||
v(0) = v(0)/length : v(1) = v(1)/length : v(2) = v(2)/length |
|||
End Sub |
|||
Function Dot(x, y) |
|||
d = x(0)*y(0) + x(1)*y(1) + x(2)*y(2) |
|||
If d < 0 Then Dot = -d Else Dot = 0 End If |
|||
End Function |
|||
'floor function is the Int function |
|||
'ceil function implementation |
|||
Function Ceil(x) |
|||
Ceil = Int(x) |
|||
If Ceil <> x Then Ceil = Ceil + 1 End if |
|||
End Function |
|||
Sub DrawSphere(R, k, ambient) |
|||
Dim i, j, intensity, inten, b, x, y |
|||
Dim vec(3) |
|||
For i = Int(-R) to Ceil(R) |
|||
x = i + 0.5 |
|||
line = "" |
|||
For j = Int(-2*R) to Ceil(2*R) |
|||
y = j / 2 + 0.5 |
|||
If x * x + y * y <= R*R Then |
|||
vec(0) = x |
|||
vec(1) = y |
|||
vec(2) = Sqr(R * R - x * x - y * y) |
|||
Normalize vec |
|||
b = dot(light, vec)^k + ambient |
|||
intensity = Int((1 - b) * UBound(shades)) |
|||
If intensity < 0 Then intensity = 0 End If |
|||
If intensity >= UBound(shades) Then |
|||
intensity = UBound(shades) |
|||
End If |
|||
line = line & shades(intensity) |
|||
Else |
|||
line = line & " " |
|||
End If |
|||
Next |
|||
WScript.StdOut.WriteLine line |
|||
Next |
|||
End Sub |
|||
Normalize light |
|||
DrawSphere 20, 4, 0.1 |
|||
DrawSphere 10,2,0.4</lang> |
|||
{{Out}} |
|||
<pre> &&&&&&&&&&####### |
|||
&eeeeeeeeeeeeeeee&&&&&&#######% |
|||
&eoooo*******oooooooeeeee&&&&&########% |
|||
eoo****!!!!!!!!******oooooeeee&&&&&########%% |
|||
eoo**!!!!::::::::!!!!!*****ooooeeee&&&&&########%%% |
|||
eo**!!::::::...:::::::!!!!!***ooooeeee&&&&&########%%%% |
|||
eo*!!:::.............:::::!!!!***ooooeeee&&&&&########%%%%% |
|||
eo*!!:::.................::::!!!!***ooooeeee&&&&#########%%%%%% |
|||
eo*!!::....................::::!!!****oooeeee&&&&&#########%%%%%% |
|||
&o**!::......................::::!!!****oooeeee&&&&&##########%%%%%%% |
|||
&o**!::.......................::::!!!****oooeeee&&&&&##########%%%%%%%% |
|||
&oo*!!::.......................:::!!!!***ooooeeee&&&&&##########%%%%%%%%% |
|||
&eo*!!::.......................::::!!!****ooooeeee&&&&&##########%%%%%%%%%% |
|||
eo**!!::......................::::!!!!***ooooeeeee&&&&&##########%%%%%%%%%% |
|||
&eo**!!:::...................:::::!!!!****ooooeeee&&&&&###########%%%%%%%%%%% |
|||
eeo**!!::::................:::::!!!!!****ooooeeee&&&&&&###########%%%%%%%%%%% |
|||
&eeo***!!:::::...........::::::!!!!!****oooooeeee&&&&&&###########%%%%%%%%%%%%% |
|||
&eeoo**!!!!::::::::::::::::::!!!!!*****ooooeeeee&&&&&&############%%%%%%%%%%%%% |
|||
&eeooo***!!!!::::::::::::!!!!!!!*****oooooeeeee&&&&&&############%%%%%%%%%%%%%% |
|||
&&eeooo***!!!!!!!!!!!!!!!!!!!******oooooeeeeee&&&&&&############%%%%%%%%%%%%%%% |
|||
&&eeeooo******!!!!!!!!!!********ooooooeeeeee&&&&&&&############%%%%%%%%%%%%%%%% |
|||
#&&eeeooooo******************oooooooeeeeee&&&&&&&#############%%%%%%%%%%%%%%%%% |
|||
#&&&eeeeoooooooo******oooooooooooeeeeeee&&&&&&&&#############%%%%%%%%%%%%%%%%%% |
|||
##&&&&eeeeeooooooooooooooooooeeeeeeee&&&&&&&&&##############%%%%%%%%%%%%%%%%%%% |
|||
##&&&&&eeeeeeeeeeeeeeeeeeeeeeeeee&&&&&&&&&################%%%%%%%%%%%%%%%%%%% |
|||
####&&&&&&eeeeeeeeeeeeeeeeeee&&&&&&&&&&&################%%%%%%%%%%%%%%%%%%%%% |
|||
#####&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&#################%%%%%%%%%%%%%%%%%%%%%% |
|||
%#######&&&&&&&&&&&&&&&&&&&&&&&&###################%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%###########&&&&&&&&&&&&&#######################%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%############################################%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%#######################################%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%#################################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%#########################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%#############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
%%%%%%%%%%%%%%%%% |
|||
::...:::!!!*o |
|||
..............::!!*oo |
|||
..................::!!**ooe |
|||
.....................::!!**ooee |
|||
.......................::!!**ooee |
|||
........................::!!**oooee |
|||
.........................::!!**oooeee |
|||
:........................::!!!**oooeeee |
|||
........................::!!!**ooooeeee |
|||
:......................::!!!***oooeeeee |
|||
:....................:::!!!***oooeeeeee |
|||
!:.................:::!!!****oooeeeeeee |
|||
*!:::...........::::!!!!***ooooeeeeeeee |
|||
*!!!:::::::::::!!!!!****oooooeeeeeeee |
|||
o**!!!!!!!!!!!!!*****oooooeeeeeeeee |
|||
oo**************ooooooeeeeeeeeeee |
|||
eoooooooooooooooooeeeeeeeeeeeee |
|||
eeeooooooooeeeeeeeeeeeeeeee |
|||
eeeeeeeeeeeeeeeeeeeee |
|||
eeeeeeeeeeeee</pre> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |