Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=HRD467' /> </object>
'Fractal.sb modified to debug and trap some of the spurious pixels seen.
GraphicsWindow
.
BackgroundColor
=
"Black"
x
=
100
y
=
100
oldx
=
150
oldy
=
1000
'For i = 1 To 100000
For
i
=
1
To
100000
r
=
Math
.
GetRandomNumber
(
3
)
' r determines whether the top, bottom left or bottom right sub-triangle
' of the overall triangle is selected. I have used the value of r to change
' the pixel colour to determine this fact.
' You will probably need to stretch the window to see the red and blue pixels.
'line goes from 30,1000 to 150,30
'gradient = (30 - 1000) / (150 - 30) = - 970 / 120 = -97 / 12
'origin = 30,1000
'y = -97/12 * x + 1242.5 from y=mx+c knowing two co-ordinates
'x = 30, y = 1000 and x = 150, y = 30
ux
=
150
uy
=
30
If
(
r
=
1
)
then
ux
=
30
uy
=
1000
EndIf
If
(
r
=
2
)
Then
ux
=
1000
uy
=
1000
EndIf
x
=
(
x
+
ux
)
/
2
y
=
(
y
+
uy
)
/
2
If
x
<
oldx
Then
oldx
=
x
' TextWindow.WriteLine("oldx = " + oldx)
EndIf
If
y
<
oldy
Then
oldy
=
y
' TextWindow.WriteLine("oldy = " + oldy)
EndIf
If
r
=
1
Then
GraphicsWindow
.
SetPixel
(
x
,
y
,
"red"
)
' TextWindow.WriteLine("red pixel")
EndIf
If
r
=
2
Then
GraphicsWindow
.
SetPixel
(
x
,
y
,
"Blue"
)
EndIf
If
r
=
3
Then
testy
=
(
x
*
-
97
/
12
)
+
1242.5
If
testy
>
y
Then
' Trap a pixel to the left of the large green triangle
' Does not trap any other stray pixels.
TextWindow
.
Write
(
"x = "
+
x
)
TextWindow
.
Write
(
" y = "
+
y
)
TextWindow
.
WriteLine
(
" testy = "
+
testy
)
EndIf
GraphicsWindow
.
SetPixel
(
x
,
y
,
"LightGreen"
)
EndIf
EndFor
Copyright (c) Microsoft Corporation. All rights reserved.