Search code examples
smallbasic

creating quick images on smallbasic


im trying to create a noise image on small basic, however, i cant get the image to load fast enough to look realistic. i tried using ldarray but it still isnt fast enough.

here is the current code im using:

GraphicsWindow.Left = 0 'positions graph
GraphicsWindow.Top = 0
GraphicsWindow.Height = 240
GraphicsWindow.Width = 320
numpix = 320 * 240 'creates number of indices for ldarray
pixels = LDArray.Create(numpix) 'creates 1D array where color values will be       stored
While 1=1
setcolor()
importcolor()
EndWhile

Sub setcolor
For h = 1 To numpix
randomcolor = Math.GetRandomNumber(2)
If randomcolor = 1 Then
  ldarray.SetValue(pixels,h,"black") 'sets the pixel color to black or white
Else
  ldarray.SetValue(pixels,h,"white")
EndIf
EndFor
EndSub


sub importcolor
'prints out the image
For h = 1 To 320
For w = 1 To 240
  i = i + 1
  color = LDArray.GetValue(pixels,i)
  GraphicsWindow.SetPixel(h,w,color)
EndFor
EndFor

EndSub

you can format to program later, by selecting all the text, then clicking "format program"

also, if you can help me write a fps counter, that would be extremely helpful because i have no idea where to start with that.


Solution

  • Well, this seems to be a bit faster, but not perfect. This is one of the harder tasks you can be doing, because it needs to make every single one of the 76,800 pixels randomized at the same time. Very hard.

    GraphicsWindow.Left = 0 'positions graph
    GraphicsWindow.Top = 0
    GraphicsWindow.Height = 240
    GraphicsWindow.Width = 320
    
    
    Randcol[1] = "Black"
    Randcol[2] = "White"
    
    'Load a random image of the right size into the imagelist
    img = ImageList.LoadImage("http://www.hdiphonewallpapers.us/phone-wallpapers/freewallpaper/12954B94004N0-1Da.jpg")
    LDImage.OpenWorkingImage(img)
    
    While 1=1
       For x = 1 To 320
        For y = 1 to 240
          LDImage.SetWorkingImagePixel(img,x,y,Randcol[Math.GetRandomNumber(2)])
        EndFor
       EndFor
      LDImage.CloseWorkingImage(img)
      GraphicsWindow.DrawImage(img,0,0)
      LDImage.OpenWorkingImage(img)
    EndWhile