在smallbasic上创建快速图像



我试图在小基础上创建一个噪声图像,但是,我不能让图像加载得足够快,看起来很逼真。我试过使用larray,但它仍然不够快。

下面是我使用的当前代码:

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

您可以稍后格式化程序,通过选择所有文本,然后点击"格式化程序"

还有,如果你能帮我写一个FPS计数器,那将非常有帮助,因为我不知道从哪里开始。

嗯,这似乎快了一点,但并不完美。这是一项比较困难的任务,因为它需要同时随机化76,800像素中的每一个像素。很努力。

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

相关内容

  • 没有找到相关文章

最新更新