"Get Pixel" loop misses pixels it should have found. (In Small Basic)

394 views Asked by At

Here's the code in Small Basic:

GraphicsWindow.CanResize = 0
GraphicsWindow.Width = 201
GraphicsWindow.Height = 300
X = 0
circumstance = 0

'Initialization
GraphicsWindow.SetPixel(100,0,"Black")
code = "01111111"


'Start
For i=1 To GraphicsWindow.Height
For X=0 To GraphicsWindow.Width
Program.Delay(1)

If X>0 Then
  If GraphicsWindow.GetPixel(X-1,i-1) = "Black" Then
    circumstance = circumstance + 1
  EndIf
EndIf  

If GraphicsWindow.GetPixel(X,i-1) = "Black" Then
  circumstance = circumstance + 10
EndIf

If X<GraphicsWindow.Width Then
  If GraphicsWindow.GetPixel(X+1,i-1) = "Black" Then
    circumstance = circumstance + 100
  EndIf
EndIf  

TextWindow.WriteLine(circumstance)
  EndFor
EndFor

What it does is it looks through the Graphics Window pixel by pixel. The variable "circumstance" is what it found. If there is a black pixel to the top left of the target pixel, the first digit will be 1. If there is a black pixel to the top of the target pixel, the second digit will be 1. If there is a black pixel to the top right of the target pixel, the third digit will be 1. But no matter what I try circumstance always outputs 000.

2

There are 2 answers

0
Nonki Takahashi On
  1. GetPixel returns "#rrggbb" not color name.
  2. GraphicsWindow is filled with "#000000" at the beginning. But the color is transparent so you can see the background color.
0
Vitexikora On

GetPixel always worked for me. What sB version are you using? BTW the graphics window needs to painted by some color, although its white by default, it won't return white, because there is like no color.